[antlr-interest] How to best resolve ambiguity?

Martin Traverso mtraverso at gmail.com
Fri Dec 30 19:30:20 PST 2005


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

> On a related note, any idea why antlr complains with "2:16: The
> > following alternatives are unreachable: 2" for the following
> > grammar? A bug, maybe?
> >
> > grammar T;
> > a    :  'x' ('+' a)? ;
>
> For one, ANTLR must complain that there is no rule obviously followed
> by EOF.  In this case, though, I think it's saying that there is no
> input that will predict bypassing the (...)?, which of course there
> isn't due to lack of start rule.  It should become ('+' a) in the
> output and probably never terminate. :)


Yup, that's exactly what's happening. If I add a parent rule that simply
calls rule a, it starts working. Cool! :)

Thanks!

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051230/c60bae1f/attachment.html


More information about the antlr-interest mailing list