[antlr-interest] ANTLR Problem

Thomas Brandon tbrandonau at gmail.com
Thu Jun 29 02:49:58 PDT 2006


Firstly I think that message is the ea10 message, upgrade to Antlr 3.0b1 as,
as well as other updates, it also gives more informative messages for some
of these sorts of errors.

There are three different warnings there:
The first warning is that Antlr was unable to analyse your rule due to
ambiguity so it had to switch off its fancy analysis and try to predict the
decision with just one character of lookahead. This indicates either left
recursion or other ambiguities (I haven't quite got a handle on these other
ambiguities).
The second warning is telling you that (with only one character of lookahead
now) Antlr cannot predict which alternative to follow, there are two
possible ways the next character could be 'i': either directly or somehow
through SingleConstExpression (if you look at the syntax diagram for the
rule in AntlrWorks you should be able to see the two possible paths to
'infinity'). As a result Antlr disabled alternative 2 ('infinity') for the
lookahead 'i'.
The third message is saying that now that alternative 2 is disabled there is
no possible input sequence that will lead to the second alternative.

So, you need to find the ambiguity. It may be an error in your grammar as
most languages are designed to be fairly unambiguous, or it could be a true
ambiguity. Maybe someone else can suggest a good method for resolving
ambiguities that break the analysis. From my (limited) experience: try
analysing the syntax diagram\DFA for SingleConstExpression and rules it
calls and look for possible ambiguities. Maybe try commenting out various
bits of those rules until you find the bit that's doing it.
Also you can replace the rule with:
<code>
UpperBound options { k=1; }
    :   ('infinity')=>'infinity'
    |   SingleConstExpression
    ;
</code>
The k=1 option overrides Antlr's analysis with the syntactic predicate
forcing 'infinity' to match. This may resolve the problem or it may produce
other errors which might lead you closer to the underlying issue.
Or, if it's all too much, if you post SingleConstExpression and the rules it
calls then maybe someone can spot the issue.

Tom.
On 6/29/06, Jörg Riedl <Jrydl at web.de> wrote:
>
> Hello.
>
> I have a problem with ANTLR.
> The Consol throws the following exception!
>
> Antlr.g:654:4: ANTLR could not analyze this decision in rule UpperBound
> probably due to a true ambiguity in the grammar or left-recursion problems.
> ANTLR re-analyzed the decision with a fixed lookahead of k=1.
>
> [12:36:01] Antlr.g:654:4: Decision can match input such as "'i'" using
> multiple alternatives:
>
> alt 1 via NFA path
> 2596,2584,860,7423,7421,876,7503,7492,878,7516,7504,880,7529,7517,882,7540,7535,7536,7537,884,7551,7541,886,7562,7552,888,7573,7563,890,7587,7574,892,7602,7588,894,7617,7603,896,7630,7625,7626,7627,898,7641,7631,900,7652,7642,902,7661,7656,7657,7658,904,7673,7662,908,7718,7694,496,4498,4475,498,4550,4504,128,1985,1980,1979,1975,6,1
> 008,1006,8,1011,1009,748,6404,6392,750,6410,6411,6407,756,6426,6425,6424
>
> alt 2 via NFA path 2596,2597,2586,2587
>
> As a result, alternative(s) 2 were disabled for that input
>
> [12:36:01] Antlr.g:654:4: The following alternatives are unreachable: 2
>
>
> code :
> UpperBound
> : SingleConstExpression | 'infinity'
> ;
>
>
> What can i do to solve that problem?
>
>
>
>
>
>
> Verschicken Sie romantische, coole und witzige Bilder per SMS!
> Jetzt bei WEB.DE FreeMail: *http://f.web.de/?mc=021193*<http://f.web.de/?mc=021193>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060629/627a1086/attachment-0001.html


More information about the antlr-interest mailing list