[antlr-interest] How to best resolve ambiguity?
Terence Parr
parrt at cs.usfca.edu
Fri Dec 30 18:45:55 PST 2005
On Dec 30, 2005, at 6:40 PM, Martin Traverso wrote:
> Ok, I did some testing, and antlr seems to be doing the natural
> thing even without explicitly setting k=1. What threw me off was
> that when I compiled the grammar I got the following errors:
>
> test.g:6:7: Decision can match input such as "'+'" using multiple
> alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> test.g:7:7: Decision can match input such as "'*'" using multiple
> alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
>
> But looking at the generated code it doesn't seem like any alt was
> disabled.
Actually, alt 2 is the exit branch for a single alt (...)* loop so
it's essentially saying it won't ever exit upon '+'. :)
> 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. :)
hooray for ANTLR v3's analysis engine. :) ;)
Ter
More information about the antlr-interest
mailing list