[antlr-interest] Resolving ambiguity
Gavin Lambert
antlr at mirality.co.nz
Fri May 4 15:36:01 PDT 2007
At 07:07 5/05/2007, Stefan wrote:
>OK, but how do I do it without changing the grammar? How do I
make
>ANTLR choose the 4th alternative instead of the 2nd, when
IDENTIFIER
>is a variable?
You need to use a semantic predicate. Something along these
lines:
statement
:
( function_definition
| {isFunction(LT(1))}? function_call
| variable_definition
| expression
) ';';
(The exact syntax used to call LT may be different depending on
your target language. But it'll be something along those
lines. There's probably more info on the wiki.)
More information about the antlr-interest
mailing list