[antlr-interest] How to best resolve ambiguity?

Terence Parr parrt at cs.usfca.edu
Fri Dec 30 19:34:45 PST 2005


On Dec 30, 2005, at 7:30 PM, Martin Traverso wrote:
>> Actually, alt 2 is the exit branch for a single alt (...)* loop so
>> it's essentially saying it won't ever exit upon '+'. :)
>
> I'm not sure I understand that... If I comment out the 'D' a alt  
> from rule c,  ANTLR stops complaining, but the generated code for  
> rule a is the same as when I leave it in.

Yep.  It's doing the right thing; it's just warning you that it could  
actually match the Da by not jumping into the loop.

> Regardless, isn't this true of even the simplest (...)*, I mean,  
> the fact that it won't exit upon matching what's between the  
> parenthesis ( i.e., it has to keep looping)?

Yes, as we define all loops to be greedy.  You may want the warning  
though as it usually indicates you have weird thing in my language or  
grammar like, blech, allowing random trailing semicolons and commas  
like certain unmentioned languages. ;)

Ter


More information about the antlr-interest mailing list