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:
parent
2de3aaba52
commit
bd601e45c3
11
expression.c
11
expression.c
|
@ -1085,11 +1085,6 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
else if (OperatorPrecedence[(int)Token].InfixPrecedence != 0)
|
else if (OperatorPrecedence[(int)Token].InfixPrecedence != 0)
|
||||||
{
|
{
|
||||||
/* scan and collapse the stack, then push */
|
/* scan and collapse the stack, then push */
|
||||||
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;
|
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 right to left order, only go down to the next higher precedence so we evaluate it in reverse order */
|
||||||
|
@ -1099,6 +1094,12 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
else
|
else
|
||||||
ExpressionStackCollapse(Parser, &StackTop, Precedence+1, &IgnorePrecedence);
|
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
|
||||||
|
{
|
||||||
/* if it's a && or || operator we may not need to evaluate the right hand side of the expression */
|
/* 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))
|
if ( (Token == TokenLogicalOr || Token == TokenLogicalAnd) && IS_NUMERIC_COERCIBLE(StackTop->Val))
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,8 +19,8 @@ int main()
|
||||||
printf("%d\n", joe() && fred());
|
printf("%d\n", joe() && fred());
|
||||||
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", fred() || (1 + joe()));
|
printf("%d\n", fred() || (0 + joe()));
|
||||||
printf("%d\n", joe() && (1 + fred()));
|
printf("%d\n", joe() && (0 + fred()));
|
||||||
printf("%d\n", joe() || (1 + fred()));
|
printf("%d\n", joe() || (1 + fred()));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -15,6 +15,6 @@ joe
|
||||||
1
|
1
|
||||||
joe
|
joe
|
||||||
fred
|
fred
|
||||||
1
|
|
||||||
joe
|
|
||||||
0
|
0
|
||||||
|
joe
|
||||||
|
1
|
||||||
|
|
Loading…
Reference in a new issue