[antlr-interest] unexpected nondeterminism...
Terence Parr
parrt at cs.usfca.edu
Sat Mar 27 11:21:21 PST 2004
Hi. I think this is a limitation of the linear approximate lookahead
not your understanding. There is usually one place in a grammar where
the approximation bites you. ANTLR will do the right thing by
consuming the OP greedily, but it confuses itself and then gives you a
warning. My suggestion is to just leave it and add "options {
greedy=true; } :" to the subrule (OP)? so that you can inform ANTLR you
intended to do this. It will obediently shut up and do the right
thing. :)
Sorry for the hassle.
Ter
On Mar 26, 2004, at 4:21 PM, Mark wrote:
> Call me dense, but I'm not getting why this results in a
> nondeterminism:
>
> class TestParser extends Parser;
> options { k = 2; }
>
> term: ID ;
> expression: term ( OP term )* ;
> statement: expression ( assignment )? ;
> assignment: ( OP )? AOP expression ;
>
> The warning given is:
>
> ANTLR Parser Generator Version 2.7.3 (20040322-1) 1989-2004
> jGuru.com
> foo.g:7: warning:nondeterminism upon
> foo.g:7: k==1:OP
> foo.g:7: k==2:ID
> foo.g:7: between alt 1 and exit branch of block
>
> Surely, with k=2 look ahead, the sequence [ OP, ID ] can only be
> alternative one of the
> block. There doesn't seem to be a way in which OP can be followed by
> anything other than
> ID (in which case it is a continuation of the ()* block in
> expression), or AOP, in which case
> it is an assignment. Doesn't the k=2 ensure that in the code for
> expression, it can look
> ahead and say if k==1:OP, k==2:ID then continue the loop, otherwise
> exit?
>
> Any help to clear my thick-headed understanding would be appreciated!
>
> - Mark
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list