[antlr-interest] Re: Syntactic predicate in lexer rule

Xue Yong Zhi seclib at seclib.com
Mon Jan 2 09:20:44 PST 2006


The lexer will definitely "try" to match FLOAT, if the token starts with 
DIGITS. But it will not accept it, since the syntactic predication will 
fail. That's expected behavior.

Martin Traverso wrote:
> Hi all,
> 
> Happy new year!
> 
> I'm having some trouble with the following grammar. I would think the 
> syntactic predicate in FLOAT should be enough to distinguish between a 
> FLOAT and an INTEGER followed by two dots, but when parsing stuff like 
> "1..2" the lexer tries to match a FLOAT. Any ideas why?
> 
> 
> grammar T;
> 
> range:  number ('..' number)?;
> number: INTEGER | FLOAT;
> 
> FLOAT:  (DIGITS '.' DIGITS) => DIGITS '.' DIGITS;
> 
> INTEGER : DIGITS;
> 
> fragment
> DIGITS: ('0'..'9')+;
> 
> 
> Thanks!
> 
> Martin



More information about the antlr-interest mailing list