[antlr-interest] error in tree grammar syntax...
antlr at mirality.co.nz
Mon Dec 29 13:41:26 PST 2008
At 10:27 30/12/2008, Pady Srinivasan wrote:
>When I try something like this in my tree grammar, I get an
> : assignment
> | ^('if' boolExpression assignment? statement* ^('else'
> (statement)? (statement)? )? )
>error(100): GwfWalker.g:32:85: syntax error: antlr:
>GwfWalker.g:32:85: expecting RPAREN, found '?'
>error(100): GwfWalker.g:32:87: syntax error: antlr:
>GwfWalker.g:32:87: expecting SEMI, found ')'
>error(106): GwfWalker.g:26:4: reference to undefined rule:
Did you try removing the parentheses around "statement"?
Also, you're going to have trouble with a construct like
that. Having two optional statements in series -- when only one
statement is present in the input tree, which is it? The first or
the second? You need to either put more structure in your AST or
change the nesting so that it's obvious which one is "more
optional" than the other, when only one of the two is present.
You'll have similar trouble with "assignment? statement*", since
an assignment is a statement. This is a redundancy, and those
almost always lead to ambiguity and weird behaviour.
More information about the antlr-interest