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

O.E. Dragon dragonoe at univmail.cis.mcmaster.ca
Thu Sep 15 15:22:27 PDT 2005


On Thu, 15 Sep 2005 08:54:16 -0400
 "Don Caton" <dcaton at shorelinesoftware.com> wrote:
>   foobar
>      : t:foobar2
>   { doSomethingWith( t ); };
> 
>   foobar2
>      : "function" | "subroutine" | "program"
>      ;

I really like your solution (not that I hated the others ;). It's
simple and elegant, and best of all it doesn't make use of LT() or
target language actions which I prefer to leave out of a grammar, as
much as possible.

In a somewhat related problem, I'm in need for a tree parser that
achieves something similar. The problem I'm having is that you can
neither specify alternate root nodes nor use a non-terminal (rule) as a
root node. Is there a way to cope with the code duplication ensuing
other that would be better than only putting the common children in a
sub-rule?

Thanks for your help (all who replied). I really appreciate it!

-Olivier


More information about the antlr-interest mailing list