[antlr-interest] Is ANTLR Hallucinating?

Wincent Colaiuta win at wincent.com
Mon Jun 25 12:04:56 PDT 2007


El 25/6/2007, a las 20:33, Randall R Schulz escribió:

> Hi,
>
> I have this production in an ANTLR grammar:
>
> clifFile
>   : clText * EOF
>   ;
>
>
> It elicits this error from ANTLR:
>
> warning(200): CLIF.g:1371:4: Decision can match input such as  
> "{EOF, Open}" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(201): CLIF.g:1371:4: The following alternatives are  
> unreachable: 2
>
>
> Why is it talking about alternatives in a rule that has none?

Try looking at the syntax diagram in ANTLRWorks so that you can see  
the two alternative paths. In many cases these warnings are harmless  
because the second option (the one automatically disabled by ANTLR)  
is the one that you'd want to turn off to resolve the ambiguity  
anyway (ANTLR resolves these things by favoring the greedy match,  
which is often what you want), but it's good to check.

Being a C programmer I like warning-free builds and I like warning- 
free ANTLR generations too, so sometimes you can tweak your grammar a  
bit to avoid such warnings.

Without seeing your entire grammar I can't comment on what the  
problem is but ANTLR evidently thinks there is more than one way to  
match rule "clText" zero or more times followed by an EOF. That is,  
although there are no explicit alternatives in your "clifFile" rule,  
the ambiguity creeps in anyway in the other rule(s) referenced from  
that rule.

Cheers,
Wincent



More information about the antlr-interest mailing list