[antlr-interest] How can I decide at runtime if a rule contains an optional token
Gavin Lambert
antlr at mirality.co.nz
Sat Apr 25 16:21:22 PDT 2009
At 06:23 26/04/2009, Gabriel Petrovay wrote:
>This is my problem. I only know at runtime of a rule is alowed
to
>contain a token based on o flag in the parser. Moreover, this
>token, if alowed, is optional.
>
>Example:
>rule : T1 ({ isT2Alowed }?=> T2?) T3 ...
I haven't tested this, but in theory it should work:
rule : T1 ({ isT2Allowed }? => T2)? T3 ...
(When you use a predicate, lookahead is still checked -- so the T2
will still be optional even when isT2Allowed.)
More information about the antlr-interest
mailing list