[antlr-interest] Changing the order of execution of tree pattern matching rules

Andrew Mains andrew.mains at oracle.com
Tue Jul 31 11:59:32 PDT 2012

Hi all,

I am currently working on preprocessing an AST in order to compute some 
properties about the code and make my code generation easier. To do 
this, I'm using a tree grammar with pattern matching (filter = true).

My question is this: I want to set a flag on each node of the tree in a 
bottomup manner, and then use the information from this flag in a 
topdown walk of the tree. Unfortunately for me, ANTLR does only one 
depth first walk of the tree, (sensibly) executing the topdown actions 
first, since they are performed in the preorder position. Since my 
topdown action is dependent on my bottomup action, this order doesn't 
work for me.

Is there any convenient method of telling ANTLR to perform multiple DF 
walks of the tree so I can perform my bottomup action in the first walk 
and my topdown action in the second?

If possible, I'd prefer to avoid splitting my grammar into two, as this 
is less convenient, but I'll do so if necessary. I am, of course, open 
to different ways of looking at the problem--this was just what made the 
most sense to me initially (and what I would do if I were walking the 
tree "by hand")

Let me know if anything is unclear--I'm happy to provide more 
details/actual code if it will help.

Thanks for the help!


More information about the antlr-interest mailing list