[antlr-interest] Non-LL(*) decision, different behaviour in ANTLRWorks vs. ANTLR (command line)

Martin Probst mail at martin-probst.com
Thu May 28 05:52:52 PDT 2009


Hi all,

I have trouble with a grammar I'm developing. Everything worked fine,
now I'm integrating some additional language constructs, and ANTLR
doesn't like them. You can find the grammar here (sorry, it's pretty
huge):

http://code.google.com/p/xqpretty/source/browse/trunk/src/main/antlr3/com/martinprobst/xqpretty/XQuery.g

The problem is that with the grammar as it is, ANTLR 3.1.3 reports
"[fatal] rule stepExpr has non-LL(*) decision", and then some more of
the same. I've spent some time tracking this, and I found that
ANTLRWorks does not give these errors (even when generating code!) and
also interprets the grammar correctly. So, is there any difference in
how ANTLRWorks and ANTLR run the generator? Can I emulate that on the
command line?

I can get rid of the non-LL(*) warnings by modifying two lines, line
546 (ftWordsValue):

ftWordsValue
    : literal; // | (LCURLY expr RCURLY);

and line 540 (ftPrimaryWithOptions):

ftPrimaryWithOptions
    : ftPrimary; // ftMatchOptions?;

However looking through the grammar, I really cannot find any problem
with these rules. The embedded recursion to "expr" (top rule) should
be properly guarded through the curly braces in the first case, and
the match options (latter case) simply consist of some tokens. ANTLR
reports for the second issue:

XQuery.g:541:17: Decision can match input such as "CASE INSENSITIVE
RETURN IntegerLiteral..DoubleLiteral" using multiple alternatives: 1,
2
(and many more like that)

Where alternative 1 would be to continue with the repetition, and
alternative 2 would be to exit the loop (I guess). However nothing
within the rules referenced from the loop allows the "RETURN" token,
and no rule on the outside allows a CASE token followed by an
INSENSITIVE token.

I'm pretty puzzled, in particular by the different behaviour of
ANTLRWorks and ANTLR. My ANTLRWorks version uses ANTLR 3.1.2 according
to "About", but I've also tried that one on the command line with no
success.

Any pointers/opinions?

Thanks,
Martin


More information about the antlr-interest mailing list