[antlr-interest] help me to understand nondeterminism warnings please

Terence Parr parrt at jguru.com
Tue Dec 17 16:20:38 PST 2002


On Tuesday, December 17, 2002, at 12:22  PM, davidjpenton2002 
<nwestreb at arrowsash.com> wrote:

> I would very much appreciate tips on understanding nondeterminism
> warnings from antlr.  I suppose it is probably not appropriate to
> just dump a grammar into a post and ask y'all to debug it, so, I'll
> only include the relevant snippets (which may be insufficient to
> identify the problem, I guess).
>
> As I would like to gain a fairly complete grasp of antlr, I expect
> that replies to this post be to point me in the right direction in
> the FAQ, the reference manual, or other sources. Such advice would be
> much appreciated.
>
> Anyway, here is what I get:
>
> *** antlr output: ***
>
> ANTLR Parser Generator   Version 2.7.1   1989-2000 jGuru.com
> grammar.g:137: warning: nondeterminism upon
> grammar.g:137: 	k==1:S
> grammar.g:137: 	k==2:S
> grammar.g:137: 	between alt 1 and exit branch of block
> grammar.g:92: warning: nondeterminism upon
> grammar.g:92: 	k==1:S
> grammar.g:92: 	k==2:S
> grammar.g:92: 	between alt 1 and exit branch of block
>
>   ***
>
> Here is the rule at line 137:
>
> notationType
>     :  "NOTATION" S LEFTPAREN (S)? name
>        ((S)? VERTICALBAR (S)? name)*

The S might start this production or the next one...ANTLR doesn't know 
which to match with k=1.  k=2 might solve it.

>        (S)? RIGHTPAREN
>     ;
>
> And here is the production at line 92:
>
> enumeration
>     : LEFTPAREN (S)? nmtoken
>       ((S)? VERTICALBAR (S)? nmtoken)* (S)? RIGHTPAREN
>     ;
>
> and, if it helps, the lexer rule for S is:
>
> S : (' ' | '\t' | '\n' | '\r')+;
>
> I don't really understand what the ambiguity is, which is probably
> just another way of saying I do not yet understand antlr and LL(k)
> parsing yet. More specifically, I don't know how to read the warning
> message.  What are 'alt 1' and the 'exit branch'?

Exit branch of the loop or optional branch of an optional subrule.

Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list