[antlr-interest] disambiguating sempred in a closure?

J Chapman Flack jflack at math.purdue.edu
Fri Dec 21 07:52:17 PST 2007


Hi,

I have backed myself into a corner where I need semantic
information to decide whether to take an exit branch:

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

so that even if the lookahead is KERMIT or FOZZIE
I should take the exit branch if I'm not looking for
muppets. (Before you ask, no, I don't know this
statically; actions may alter these flags on any
iteration. Such is the language I'm trying to parse.)

antlr 2.7.7 treats these sempreds as validating because they
are not at the top of the production, so they throw exceptions
instead of exiting the closure. I haven't tried to port my
grammar to antlr 3 yet.

1.  Is there a way to refactor this production in antlr 2.7.7
     to get the behavior I want?

2.  Is it easier in antlr 3?  Is it enough easier that I should
     bite the bullet and port the 1100 line grammar rather than
     fussing with it in 2.7.7?

Thanks,
-Chap



More information about the antlr-interest mailing list