[antlr-interest] non-LL(*) error in list rule

John B. Brodie jbb at acm.org
Tue Jul 1 19:16:40 PDT 2008


Chris Rebert wrote:
>I have a grammar and am getting an error about the rule 'exprlist'
>being non-LL(*), even after turning on backtracking as suggested by
>the error:
>
>exprlist options {backtrack=true;}: es+=expr? (',' es+=expr)*  -> es;
>list: '['! exprlist ']'!;
>
>And suffice it to say that the rule for 'expr' includes some rules
>like 'list' as alternatives.
>...snipped...
>How do I go about fixing this grammar?

It is hard to say without seeing the entire grammar.

exprList can recognize the empty string (because of the ? on the first expr
reference).

rules which can match the empty string are always, in my experience,
problematic.  I always try to hoist the emptyness choice up into parents.

I suspect that somewhere in your grammar there is an instance of exprList
that is followed by some other possibly empty element which causes an
ambiguity regarding which empty element is supposed to be matched.



Or Perhaps Something Else Is Wrong.



anyway, try to find a way to not have any rules that match the empty string.



sorry for not being really very helpful.  perhaps you can post a *MINIMAL*
yet *COMPLETE* grammar that exhibits this same issue for you.  and then we
can go from there?

   -jbb


More information about the antlr-interest mailing list