[antlr-interest] How to place syntactic predicate between rules

=?gb2312?q?=CB=EF=BC=CD=B8=D5=20Jigang=20(Robert)=20Sun?= sunjigang1965 at yahoo.com.cn
Thu Mar 16 03:35:03 PST 2006


both rule varDeclList and statementList in the following method declaration could be none and
their FIRST set contain ID, so when they are next to each other, nondertermistic warning was
given:

methodDecl
	:  "public" typeDenotor ID LPAREN formalList RPAREN 
			LBRACE varDeclList  statementList
			 "return" expression SEMI RBRACE
	;	

varDeclList
	:
	(varDecl)* 
	;

varDecl
	:	
	typeDenotor ID SEMI //int v; ID ID; 
	;

typeDenotor
	:
	"int"
	| ID 
 	;

statementList
	:
	(statement)* 
	;

statement
    :
     "if" LPAREN  expression RPAREN statement "else" statement 
    | ID BECOMES expression SEMI //v=8;
    ; 
		
If both confilicted subrules could be placed in one rule, I could put a syntactic predicate to
distinguish them: 

imaginaryRule
   :
   (ID BECOMES)=>ID BECOMES expression SEMI //v=8;
  | ID ID SEMI //int v; ID ID;
  ;

Does anyone have a solution to this? Is a way to put syntactic predicate between rules? 

Cheers.

Jigang



	

	
		
___________________________________________________________ 
ÑÅ»¢1GÃâ·ÑÓÊÏä°Ù·Ö°Ù·ÀÀ¬»øÐÅ 
http://cn.mail.yahoo.com/


More information about the antlr-interest mailing list