[antlr-interest] nondeterminism issue for dummies ?

Michiel Vermandel Michiel_Vermandel at axi.be
Mon Jul 10 00:58:33 PDT 2006


Hi, 

another nondeterminism issue... 

The issue is in deciding between a single-line comment rule or a directive 
rule. 

A single-line comment is "--" (two minus signs) followed by anything 
untill the end of the line. 

A directive is "--"(two minus signs) follwed by spaces or tabs, then 
followed by some reserved words such as "axi.locate" or "axi.reject" 

So: 

"-- hello world" CRLF 

is a comment 

"-- axi.locate blabla" CRLF 

is a directive. 

My rule works though gives a nondeterminism warning. 

Rule: 
-------------------------------- 

SL_COMMENT 
        :        "--"!  ( 
               ( 
                  (' '|        '\t')* 
                  ( 
                     ("axi.locate") => (  "axi.locate" { _ttype = 
AXI_DIRECTIVE; } ) 
                    |("axi.reject") => (  "axi.reject" { _ttype = 
AXI_DIRECTIVE; } ) 
                  ) 
                ) 
                | (~('a')) (~('\n'|'\r'))* 
            ) 
            CRLF 
        ; 

Warning: 
------------------------------ 
ANTLR Parser Generator   Version 2.7.5rc2 (2005-01-08)   1989-2005 
jGuru.com 
FormsLexerSnip.g:20:24: warning:lexical nondeterminism between alts 1 and 
2 of block upon 
FormsLexerSnip.g:20:24:     k==1:'\t',' ' 
FormsLexerSnip.g:20:24:     k==2:'\t',' ','a','x' 
FormsLexerSnip.g:20:24:     k==3:'\t',' ','a','i','x' 
FormsLexerSnip.g:20:24:     k==4:'\t',' ','.','a','i','x' 


Any ideas how to rewrite this rule so it parses without warning? 
Or just ignore the warning? 

Thanks a lot! 

Have a great weekend! 

Michiel 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060710/4458ab4f/attachment.html


More information about the antlr-interest mailing list