Structure element access wasn't obeying precedence rules. It is now.

Fixed test case 50.

git-svn-id: http://picoc.googlecode.com/svn/trunk@545 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-16 04:46:04 +00:00
parent 2de3aaba52
commit bd601e45c3
3 changed files with 15 additions and 14 deletions

View file

@ -1085,20 +1085,21 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
else if (OperatorPrecedence[(int)Token].InfixPrecedence != 0)
{
/* scan and collapse the stack, then push */
Precedence = BracketPrecedence + OperatorPrecedence[(int)Token].InfixPrecedence;
/* for right to left order, only go down to the next higher precedence so we evaluate it in reverse order */
/* for left to right order, collapse down to this precedence so we evaluate it in forward order */
if (IS_LEFT_TO_RIGHT(OperatorPrecedence[(int)Token].InfixPrecedence))
ExpressionStackCollapse(Parser, &StackTop, Precedence, &IgnorePrecedence);
else
ExpressionStackCollapse(Parser, &StackTop, Precedence+1, &IgnorePrecedence);
if (Token == TokenDot || Token == TokenArrow)
{
ExpressionGetStructElement(Parser, &StackTop, Token); /* this operator is followed by a struct element so handle it as a special case */
}
else
{
/* a standard infix operator */
Precedence = BracketPrecedence + OperatorPrecedence[(int)Token].InfixPrecedence;
/* for right to left order, only go down to the next higher precedence so we evaluate it in reverse order */
/* for left to right order, collapse down to this precedence so we evaluate it in forward order */
if (IS_LEFT_TO_RIGHT(OperatorPrecedence[(int)Token].InfixPrecedence))
ExpressionStackCollapse(Parser, &StackTop, Precedence, &IgnorePrecedence);
else
ExpressionStackCollapse(Parser, &StackTop, Precedence+1, &IgnorePrecedence);
/* if it's a && or || operator we may not need to evaluate the right hand side of the expression */
if ( (Token == TokenLogicalOr || Token == TokenLogicalAnd) && IS_NUMERIC_COERCIBLE(StackTop->Val))
{

View file

@ -19,8 +19,8 @@ int main()
printf("%d\n", joe() && fred());
printf("%d\n", joe() || fred());
printf("%d\n", fred() && (1 + joe()));
printf("%d\n", fred() || (1 + joe()));
printf("%d\n", joe() && (1 + fred()));
printf("%d\n", fred() || (0 + joe()));
printf("%d\n", joe() && (0 + fred()));
printf("%d\n", joe() || (1 + fred()));
return 0;

View file

@ -15,6 +15,6 @@ joe
1
joe
fred
1
joe
0
joe
1