From 2de3aaba52e6f3d5f7470d965e70cd3e86f52521 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Wed, 16 Feb 2011 03:58:48 +0000 Subject: [PATCH] Fixed a bug in bracket evaluation - was collapsing the expression stack at the wrong precedence. Fixed a bug in evaluation of logical operators where the RHS is not evaluated - off-by-one error in precedence. git-svn-id: http://picoc.googlecode.com/svn/trunk@544 21eae674-98b7-11dd-bd71-f92a316d2d60 --- expression.c | 9 +++++---- tests/30_hanoi.c | 22 ++-------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/expression.c b/expression.c index 1e27e3b..e09eb7a 100644 --- a/expression.c +++ b/expression.c @@ -885,7 +885,7 @@ void ExpressionStackCollapse(struct ParseState *Parser, struct ExpressionStack * *StackTop = TopOperatorNode->Next->Next; /* do the infix operation */ - if (Parser->Mode == RunModeRun && FoundPrecedence < *IgnorePrecedence) + if (Parser->Mode == RunModeRun && FoundPrecedence <= *IgnorePrecedence) { /* run the operator */ ExpressionInfixOperator(Parser, StackTop, TopOperatorNode->Op, BottomValue, TopValue); @@ -1067,10 +1067,11 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) Done = TRUE; } else + { + /* collapse to the bracket precedence */ + ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence, &IgnorePrecedence); BracketPrecedence -= BRACKET_PRECEDENCE; - - /* collapse to the bracket precedence */ - ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence, &IgnorePrecedence); + } break; default: diff --git a/tests/30_hanoi.c b/tests/30_hanoi.c index c5846c6..5ca6667 100644 --- a/tests/30_hanoi.c +++ b/tests/30_hanoi.c @@ -71,27 +71,9 @@ PrintAll() int Move(int *source, int *dest) { int i,j; - int done = FALSE; - - for (i=0; i