[antlr-interest] Lexer non-determinism

Terence Parr parrt at jguru.com
Sun Dec 22 12:56:43 PST 2002


On Sunday, December 22, 2002, at 08:19  AM, seaswar <sje at sigma-inc.com> 
wrote:

> I posted this on the jGuru forum but got no reply. Perhaps I'll have
> better luck here.
>
> I don't understand why the following is ambiguous for k=2 but notfor
> k=3. I checked the generated code (java, antlr 2.7.1) and it looks
> right. So I turned of the warning. But I would still like to
> understand why there is a warning in the first place. No warning is
> generated for k=3.
>
> class TestLexer extends Lexer;
>
> options { k = 2; }
>
> MULTI_LINE_COMMENT
>     :    "/*"
>          (    { LA(2) != '/' }? '*'
>          |    ( "\r\n" | '\n') { newline(); }
>          |   ~( '*' | '\r' | '\n')
>          )*
>          "*/" { $setType(Token.SKIP); }
>     ;
>
> ANTLR Parser Generator   Version 2.7.1   1989-2000 jGuru.com
> com/qsi/parser/test/test9.g:7: warning: lexical nondeterminism upon
> com/qsi/parser/test/test9.g:7:  k==1:'*'
> com/qsi/parser/test/test9.g:7:  k==2:'/'
> com/qsi/parser/test/test9.g:7:  between alt 1 and exit branch of block

The predicate should hush the warning I think; perhaps 2.7.2 does.  
Anyway, check the java grammar to see what it does.

Thanks,
Terence
--
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