[antlr-interest] token construction priority

=?gb2312?q?=CB=EF=BC=CD=B8=D5=20Jigang=20(Robert)=20Sun?= sunjigang1965 at yahoo.com.cn
Sat Jun 3 10:33:05 PDT 2006


I want  -23.5E3 to be parsed as real value, 

paser rule is

realDenot: (sign)? INTEGER  DOT INTEGER (exponent)? ;
exponent : E (Sign)? INTEGER;
sign: PLUS | MINUS;

in lexer, I put 

options {
	  testLiterals=true; 
	}				
tokens
{	
    MINUS="-"; //I assume MINUS has the precedence of keywords 
}

ID3: Class1Char ( RestChar)* ;

protected Class1Char : ...| '-' |... ;
protected RestChar : LowerCaseChar | Class1Char | Digit| UpperCaseChar;
INTEGER:(Digit)+; //Digit: '0'..'9'

The result is that -23.5E3 is recongnised as ID3, I wish by setting "testLiterals=true; ", the
first char '-' should be considered as MINUS, but it is not the case.

Although setting nongreedy to ID3 works,

ID3: Class1Char (options {greedy=false;}: RestChar)* ;

I do not think this is the best solution.

Could anyone give me an idea?

Thanks.

Robert

__________________________________________________
¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
http://cn.mail.yahoo.com


More information about the antlr-interest mailing list