[antlr-interest] Performing an action based on alternative result

Don Caton dcaton at shorelinesoftware.com
Thu Sep 15 05:54:16 PDT 2005


Olivier:

In addition to the other answers you received, I think that creating another
rule is often the simplest way to do this, especially when rules begin to
get complicated.

  foobar
     : t:foobar2
  { doSomethingWith( t ); };

  foobar2
     : "function" | "subroutine" | "program"
     ;

Don  

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Olivier Dragon
> Sent: Wednesday, September 14, 2005 6:45 PM
> To: ANTLR Interest
> Subject: [antlr-interest] Performing an action based on 
> alternative result
> 
> Hi,
> 
> I'd like to be able to define a single label for many 
> alternatives and then use the result in an action. Something 
> like this:
> 
> foobar :
> (
> 	t:"function" |
> 	t:"subroutine" |
> 	t:"program"
> )
> { doSomethingWith(t) ; }
> 
> But ANTLR gives me an error "Label 't' has already been 
> defined". Is there an easy way to do this so that I don't 
> have to specify different label for each alternative and the 
> same action for each as well?
> 
> Thanks,
> 
> -Olivier




More information about the antlr-interest mailing list