[antlr-interest] Example code with multiple AST passes?

Terence Parr parrt at cs.usfca.edu
Mon Jun 20 12:33:30 PDT 2005


On Jun 20, 2005, at 12:25 PM, Bryan Ewbank wrote:

> True, it's not elegant, but I can *always* define actions for each
> production (using the same name), and have them do the same thing.
>
> Thank you for the warning about disabling default tree construction;
> hadn't thought about that yet and it's always better to learn from the
> mistakes, er, experience of others.
>
> I too would like to see true inheritance - even restricted to just
> "redefine tail actions" to avoid lookahead set weirdness - so that I
> don't have to do the same thing over and over.

Hi.  The only thing that doesn't do inheritance as you expect is the  
lookahead computaiton; that has to be done statically--hence, the  
"include" like inheritance.  Actions inherit as you expect, but you  
have to put in the hooks yourself:

class T extends Parser;

{
public abstract void action();
}

a : blort {action();}

Then in a subclass of T, define action.

:)

I have also done this:

class T extends Parser;

{
MyBehavior behavior;
public void setBehavior(MyBehavior behavior) {
   this.behavior = behavior;
}
}

a : blort {behavior.action();}

This works great in some circumstances, but not others...

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