[antlr-interest] help me to understand nondeterminism warnings
please
David Penton
djplists at arrowsash.com
Wed Dec 18 06:55:45 PST 2002
Thanks Greg. I shall give that a try.
- Dave -
On Wed, 2002-12-18 at 01:21, Greg Lindholm wrote:
> I would suggest having your lexer throw away all the white space (S
> rule). In most languages the white space is not significant except
> to separate tokens.
> Use the { $setType(Token.SKIP); } command to have the lexer discard
> all the whitespace characters.
>
> S : (' ' | '\t' | '\n' | '\r')+ { $setType(Token.SKIP); };
>
> Then remove all the 'S's from your parser.
> This would greatly simplify your grammer as you wouldn't have (S)?
> between every token. And... the nondeterminism will likely go
> away or be clearer.
>
> (If you need to perserve the whitespace for generation later you
> can use the Hidden token stream mechanism.)
>
> I know this doesn't really answer your question but it's good
> advice and if you search this group for "nondeterminism" you will
> find hundreds of similar questions and occasionally a helpful
> answer :)
>
> Greg
>
>
> --- "davidjpenton2002 <nwestreb at arrowsash.com>"
> <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)*
> > (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'?
> >
> > The nondeterminism seems to exist regardless of k. I guess I don't
> > really know if I should expect to spot the problem by looking only at
> >
> > the rules at the line numbers reported by antlr, or if I must think
> > more globally, i.e. look at the rules that include or are included by
> >
> > the offending rules as reported by antlr?
> >
> > My attempt to sort this out entailed stripping my grammar down to the
> >
> > offending rules (the ones above), the rules that refer to them, and
> > the related lexer rules. This produced the odd (to me) effect of
> > causing the problem to go away, i.e. no more warnings.
> >
> > How should I approach getting an understanding of this?
> >
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> >
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list