[antlr-interest] label for many alternatives?

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Mon Feb 28 01:53:30 PST 2005


Unfortunately, not.  You can do something like

rule
{ AST ast }
     :
     (    g1:GT { ast = #g1; }
     |    g2:GE { ast = #g2; }
     |   ...
     ) expr { anAction(op.getText()); }
     ;

but you cannot label subrules or even use the same label on alternatives.

--Loring

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of jean.morissette666 at videotron.ca
> Sent: Sunday, February 27, 2005 9:31 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] label for many alternatives?
> 
> 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 : "<=" ;
> 
> 
> ...instead of...
> 
> 
> expr ( op:OP expr { anAction(op.getText()); } )*
> 
> MyLexer...
> 
> OP : '>' | ">=" | '<'  | "<=" ;
> 
> 
> Thank
> -Jean



More information about the antlr-interest mailing list