[antlr-interest] How can I decide at runtime if a rule contains an optional token

Gabriel Petrovay gabriel.petrovay at 28msec.com
Sat Apr 25 11:23:22 PDT 2009


Hi all,

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 ...

In the above scenario, if the flag is set to true, the rule is alowed
to contain an additional optional token T2.

The above solution does not work because I get a "failed predicate"
error when isT2Alowed is false. The same applies when I use normal
predicates as in: ({ isT2Alowed }? T2?)

Any solution to this besides branching the whole rule in two
alternatives, one that contains the T2 and one that doesn't? (that
will make my grammar ugly and is also not scalable if there are
multiple such tokens that depend on different flags)

Thanks!

Regards,
Gabriel

-- 
MSc Gabriel Petrovay
MCSA, MCDBA, MCAD
Mobile: +41(0)787978034


More information about the antlr-interest mailing list