cpplib: expression parser patch 2

Neil Booth NeilB@earthling.net
Fri Mar 31 16:53:00 GMT 2000


Hi Zack,

Zack Weinberg wrote:-

> Does this handle
> 
> #if 2 * ( 3 + 4    /* missing right paren */
> #if 2 *   3 + 4 )  /* missing left paren */
> 
> I see error messages for both cases, but I don't see how we get to
> them.  I'm also confused by the presence of the case ')' in the second
> switch; when will there ever be a ) on the stack?

Yes, trying the above with #endifs present, I get the messages

/home/neil/bug.c:1:14: missing ')' in expression
/home/neil/bug.c:3:14: missing '(' in expression

which is correct.  The case ')' is what causes the 2nd error message.

With correct syntax, a ')' will not appear on the stack.  However, if
there is not a matching '(', the low left priority of ')' will cause
the stack to reduce all the way back to the beginning, at which point
we reduce no further and push the ')' onto the stack.  The next
operator will cause a reduction (owing to the high right priority of
the ')' on the stack), causing the error message.  In the case there
is the matching '(' on the stack, the case '(' code executes, jumping
to push_immediate, and the ')' never gets pushed.

I hope this is clear.

> The way you've structured some of the conditions is confusing.
> Instead of writing

Yes, that was purely to keep the correct syntax case streamlined.  If
I use your alternative, can I commit?  The bootstrap succeeded.

Thanks,

Neil.



More information about the Gcc-patches mailing list