[antlr-interest] AST rewrite

srinivasan karthikeyan pitchai srinivasan.karthikeyan.pitchai at oracle.com
Sat Jun 11 00:53:34 PDT 2011


Hi Gurus,
I'm a novice using ANTLR for a development project.  I am at a stage 
where I need to rewrite AST so that the transformed AST renders itself 
more easy for me to walk and emit the translation that I need.  In this 
context I've a concept question.

In general,  can I use the *same*  tree adapter,  used by the 
InputNodeStream used by the walker,  in a java method that I code to 
restructure the tree without using the rewrite rule?  That is can I add, 
delete, replace nodes at will in the source tree?  I am looking at this 
option as I need to move up a subtree from deep down to a much higher 
level.   In particular would manipulating the source tree mess up the 
iterator used by the ANTLR AST walker  to parse the tree?


(eg)  Just want to know if I can effect this in JAVA.   I am sure we can 
make it happen using rewrite rule.  However I want to conceptually know 
if what I desire above is a feasibility or it it a totally wrong approach.

^(ROOT a  b ^(ROOT c d  ^(ROOT e f g)))

I need to restructure the tree like, say,

^(ROOT a  b ^(ROOT c d ) ^(ROOT e f g))

Based on your input I need to chalk the future course of my coding.

Thanks in advance.

Regards,
Vasan




More information about the antlr-interest mailing list