[antlr-interest] error in tree grammar syntax...
Gavin Lambert
antlr at mirality.co.nz
Mon Dec 29 14:18:25 PST 2008
At 10:51 30/12/2008, pady wrote:
>I was under the assumption that the paranthesis is what makes
the
>parser choose different paths...so to differentiate input like
[...]
>About the "optional statements", this is where my understanding
on
>rewrite rules is poor...i dont understand how to differentiate
>the 2 optional statements using more structure in the ast...ie
>the syntax to use is what i am not clear on.
statement
: assignment
| ^('if' boolExpression statement*
^('else' (statement statement?)? )? )
;
This will permit zero, one, or two statements in the "else"
section; if only one statement is supplied then it will
unambiguously be recognised as the first of the two. I also
removed the redundant assignment from the "if" section.
I'm still not sure why you'd want to define the else block like
that, though; generally the if and else blocks should be symmetric
-- they should both either only accept one statement (which might
be a composite block) or any number of statements (depending on
how you choose to write the parser rule and how you want to
structure the AST). It's a little strange to make one side open
and the other restricted like that.
More information about the antlr-interest
mailing list