[antlr-interest] Repeatedly parsing number literals

Rick Mann rmann at latencyzero.com
Sat Mar 28 19:44:53 PDT 2009


I have a couple of lexer rules like this:

DecimalLiteral
	: '0'..'9' '0'..'9'* { $value = };

FloatingPointLiteral
	:	('0'..'9')+ '.' ('0'..'9')* Exponent?
	|	('0'..'9')+ Exponent
	|	('0'..'9')+
	;

And a number of parser rules that refer to them. Do I need to write  
actions like this:

$value = Integer.parseInt($DecimalLiteral.text);

Everywhere a parser rule references DecimalLiteral, or can I just get  
the literal's value, and parse it once in the lexer rule:

DecimalLiteral returns [long value]
	: '0'..'9' '0'..'9'* { $value = ??? };


How do I parse it? That is, how do I get the text of that literal?

Thanks!

-- 
Rick



More information about the antlr-interest mailing list