[antlr-interest] undeserved nondeterminism warning

e_p_olson e_p_olson at yahoo.com
Mon Apr 28 14:17:02 PDT 2003


I'm getting a "nondeterminism warning" that I don't beleve my grammar
should have. (I could be wrong, I'm good at being wrong -- but nobody
I've asked seems to be able to figure it out) I know how to change the
grammar to fix the warning, but I still want to know where it came
from.  Here is a small test case (full grammar is verilog 2001) 

class TestLexer extends Lexer;

WS_	:  (' ' | '\t' | '\n' | '\r')
		{ _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; } ;
LPAREN:	'(' ;
RPAREN:	')' ;
SEMI:	';' ;
IDENTIFIER
	:  ('A'..'Z'|'a'..'z'|'_')*
	;


class TestParser extends Parser;
  options {
    k=5;  // only really needs k==2
}

//////////////////////////////////////////

function_declaration 
     : "FUNCTION" IDENTIFIER
       ( function_port_list SEMI
       | SEMI ( function_port_declaration SEMI )+
       )
       function_statement "ENDFUNCTION"
     ;

function_port_list 
     : LPAREN 
       function_port_declaration ( COMMA function_port_declaration )* 
// 'macro' expanding the above rule fixed the warning:
//     "INPUT" IDENTIFIER ( COMMA IDENTIFIER )*
//     ( COMMA "INPUT" IDENTIFIER ( COMMA IDENTIFIER )*  )* 
       RPAREN
     ;

function_port_declaration  
     : "INPUT" IDENTIFIER ( COMMA IDENTIFIER )*   // line 42
     ;

function_statement
     : IDENTIFIER SEMI
     ;

/* ANTLR Parser Generator   Version 2.7.2   1989-2003 jGuru.com
   test.g:42: warning: nondeterminism upon
   test.g:42:      k==1:COMMA
   test.g:42:      k==2:IDENTIFIER
   test.g:42:      k==3:SEMI
   test.g:42:      k==4:SEMI
   test.g:42:      k==5:SEMI,IDENTIFIER
   test.g:42:      between alt 1 and exit branch of block

   k==2 should be: IDENTIFIER,"INPUT"
   There should be no nondeterminism bewteen alt 1 and exit:
      k==1 COMMA, k==2 IDENTIFIER  => take alt 1
      k==1 COMMA, k==2 "INPUT" => take exit 
   
*/  
Thanks


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list