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

Rodrigo B. de Oliveira rodrigobamboo at gmail.com
Mon Jun 20 10:04:36 PDT 2005


On 6/20/05, Bryan Ewbank <ewbank at gmail.com> wrote:
> Thank you, Don.  That's a very interesting solution to a problem that
> I've been encountering as I have more and more passes, especially when
> I need to add a new token to *every* pass.  *Groan*.
> 
> I think I see construction of an actions object that is passed to the
> grammar, but that starts to smell more and more like visitor pattern
> (turned inside out, perhaps).
> 
> Using an "action object" per pass, rather than a complete *.g, would
> allow that object to be passed to the constructor for the more generic
> tree parser.
> Hmm.  Sounds like quite a bit less duplicate code, as well as
> splitting "tree goo" from "action foo".
> 

Yes. That's what I've been using for the boo compiler. The compilation
process is described  by a CompilerPipeline object which is basically
a list of CompilerStep objects (the actions, mostly implemented as
visitors). The first step is generally the parser which constructs the
AST from the input files. The intermediate steps apply transformations
and annotations to the tree. The last step generally outputs
something.

It works great but it's based on a automatically generated hetero AST.

Rodrigo


More information about the antlr-interest mailing list