[antlr-interest] Semantic predicates during AST construction

Gavin Lambert antlr at mirality.co.nz
Mon Oct 6 03:15:20 PDT 2008


At 20:30 6/10/2008, Oliver B. Fischer wrote:
 >I would like to express things like:
 >
 >-> ^(ROOT A ({condition}? B | C)
 >
 >Evaluates condition to true, I would like to get ^(ROOT A B).
 >Otherwise the result should be ^(ROOT A C).

If B and C are tokens that exist on the matching side (left of the 
arrow) then I think you can do this (haven't tried it, though, so 
I could be wrong):

A b=B c=C -> ^(ROOT A { (condition) ? $b : $c })

It's probably possible to do this sort of thing with imaginary 
tokens as well, although I'm not sure exactly what the syntax 
would be.



More information about the antlr-interest mailing list