[antlr-interest] unexpected nondeterminism...

Mark markl at glyphic.com
Fri Mar 26 16:21:27 PST 2004


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

<*> 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