[antlr-interest] Error on Defining a syntactic predicate

txm3124 tracey_meng at yahoo.com
Thu Oct 3 11:34:00 PDT 2002


Can someone help me to fix the definition of Lexer rules of AND and 
OR?  Thanks.

I got an error as follows when I compiled the attached ruleParser.g 
file:
  
C:\Tools\antlr-2.7.1\examples\java\ruleParser>java antlr.Tool 
ruleParser.g
ANTLR Parser Generator   Version 2.7.1   1989-2000 jGuru.com
warning: lexical nondeterminism between rules VARIABLE and AND upon
ruleParser.g:0:         k==1:'A'..'Z','_','a'..'z'
warning: lexical nondeterminism between rules VARIABLE and OR upon
ruleParser.g:0:         k==1:'A'..'Z','_','a'..'z'
warning: lexical nondeterminism between rules AND and OR upon
ruleParser.g:0:         k==1:<end-of-token>,'A'..'Z','_','a'..'z'
warning: found optional path in nextToken()
warning: found optional path in nextToken()

---------------------------------------------------

class RuleParser extends Parser;
options {
	buildAST = true;
}

expr
	:	mexpr (OR^ mexpr)* SEMI!
	;

mexpr
	:	atom (AND^ atom)*
	;

atom:	INT | WORDS
	;

class RuleLexer extends Lexer;

WS	:	(' '
	|	'\t'
	|	'\n'
	|	'\r')
		{_ttType = Token.SKIP; }
	;

LPAREN:	'('
	;

RPAREN:	')'
	;

SEMI:	';'
	;

protected
DIGIT
	:	'0'..'9'
	;

INT	:	(DIGIT)+
	;
	
VARIABLE
	:	('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
	;

AND
	:	('A''N''D')	 => 	{$setType(AND);} 
	|	VARIABLE      	{$setType(VARIABLE);}
	;

OR
	: 	('O''R')	 => 	{$setType(OR);} 
	|	VARIABLE      	{$setType(VARIABLE);}
	;


 

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



More information about the antlr-interest mailing list