[antlr-interest] label for many alternatives?

Terence Parr parrt at cs.usfca.edu
Mon Feb 28 14:50:31 PST 2005


On Feb 27, 2005, at 9:31 PM, jean.morissette666 at videotron.ca wrote:

> Hi,
> I would prefer to have only one lexer rule by token, and I'm wondering 
> if it's
> possible to write something like
>
> rule :	
> expr ( op:( GT | GE | LT  | LE ) expr { anAction(op.getText()); } )*
>
> MyLexer...
>
> GT : '>' ;
> GE : ">=" ;
> LT : '<' ;
> LE : "<=" ;

Try:

rule
{
Token op = null;
}
	:	expr ( {op=LT(1);} ( GT | GE | LT  | LE ) expr { 
anAction(op.getText()); } )*	;

:)

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com





More information about the antlr-interest mailing list