[antlr-interest] disambiguating sempred in a closure?

Gavin Lambert antlr at mirality.co.nz
Fri Dec 21 15:41:14 PST 2007


At 11:58 22/12/2007, J Chapman Flack wrote:
 >Ok, here is the simplified grammar that really does
 >demonstrate my dilemma. The predicates can't do what
 >I need because of the grouping parentheses added to
 >factor out the common something_else suffix.
[...]
 >prod : something
 >        ( options { greedy=true; }
 >        : ( { muppet }? ( KERMIT | FOZZIE )
 >          | { turtle }? ( LEONARDO | DONATELLO )
 >          )
 >	something_else
 >        )*
 >      ;

I haven't tried it, but I would think that you could accomplish 
what you want by manually hoisting the predicate:

prod : something
        ( options { greedy=true; }
        : { muppet || turtle }?
          ( { muppet }? ( KERMIT | FOZZIE )
          | { turtle }? ( LEONARDO | DONATELLO )
          ) something_else
        )*
      ;



More information about the antlr-interest mailing list