[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax questions
- From: Edgar Toernig <froese@...>
- Date: Wed, 17 Sep 2008 15:07:00 +0200
Roberto Ierusalimschy wrote:
>
> > And, if I remember correctly, such a change even simplifies the
> > parser.
>
> I agree that it can be done, but I did not understand how it would
> simplify the parser. The current problem is that we use a single
> non-terminal 'functioncall' for both expressions and statements. To
> allow "x":foo() as an expression but not as a statement, we would
> have to duplicate that non-terminal.
Phew, that was a long time ago. I remember, that while changing that
in Sol, the resulting parser was slightly simpler and smaller. I think,
I moved the handling of the parentheses to the same layer where numbers,
strings, constructors, identifiers etc were handled (simpleexp?) and I
could drop one abstraction (prefixexp?) and could simplify some callers.
Your problem that only an identifier can start a statement is
handled at the top layer: instead of making 'expr' a fall-back
for all remaining tokens, it becomes a 'case TK_NAME: exprstat;'
and the 'default' case becomes a syntax error. That way it
doesn't matter that exprstat may accept more initial tokens -
from the top layer it will only be called _when_ it starts with
an identifier.
Ciao, ET.
PS: I'm afk for the next 10 days...