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

Alexey Demakov demakov at ispras.ru
Wed Sep 14 23:37:52 PDT 2005


Hi,

Once again :)

foobar 
{ Token t = null; }
:
{ t = LT(1); }
(
 "function" |
 "subroutine" |
 "program"
)
{ doSomethingWith(t) ; }

LT(k) returns k-th next token.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com


----- Original Message ----- 
From: "Olivier Dragon" <dragonoe at mcmaster.ca>
To: "ANTLR Interest" <antlr-interest at antlr.org>
Sent: Thursday, September 15, 2005 2:44 AM
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