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
This commit is contained in:
zik.saleeba 2011-02-16 03:58:48 +00:00
parent ee2ba8a53c
commit 2de3aaba52
2 changed files with 7 additions and 24 deletions

View file

@ -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:

View file

@ -71,27 +71,9 @@ PrintAll()
int Move(int *source, int *dest)
{
int i,j;
int done = FALSE;
for (i=0; i<N && !done; )
{
if (source[i] != 0)
done = TRUE;
else
i++;
}
done = FALSE;
for (j=0; j<N && !done; )
{
if (dest[j] != 0)
done = TRUE;
else
j++;
}
//while (source[i]==0 && i<N) i++;
//while(dest[j]==0 && j<N) j++;
while (i<N && (source[i])==0) i++;
while (j<N && (dest[j])==0) j++;
dest[j-1] = source[i];
source[i] = 0;