[antlr-interest] Weird problem with semantic predicates. Incorrect warning message

Jim Idle jimi at temporal-wave.com
Tue Apr 28 09:51:29 PDT 2009


Gabriel Petrovay wrote:
> Hi,
>
> Thanks a lot John for make it it clear. Although I see the problem and
> I think that generates everyting, there are at least a couple of
> problems with ANTLR:
>
> 1. The Warning is incorrect: Decision can match input such as "IF"
> using multiple alternatives: 1, 4.  As a result, alternative(s) 4 were
> disabled for that input.
>
> This is non-sense to me since decision 1 in p_ExprSingle does not
> match "IF". Only decision 4 can match it (p_StepExpr)
>   
No, the warning is perfectly correct. Use ANTLRWorks, do the Check 
Gramar, select the rule in red, select the syntax tab, turn on both 
paths, your problem will be obvious.
>
> 2. What do those two alternatives (1 and 4) have to do with the
> alternative 2 (p_ExitExpr) and a rule that is NOT used anywhere
> (p_ReplaceExpr) ???
>   
Because in the look ahead set, you calculate all possible tokens that 
the grammar says can come next, not just the rule that you have 
provided. Basically your grammar does not make a lot of sense and ANTLR 
is trying to tell you this. You might be better starting with the 
examples and building up from there; trying to run before you can walk 
gets you in to trouble with grammars ;-)

Jim


More information about the antlr-interest mailing list