[antlr-interest] AST rewrite
Trevor John Thompson
tijet at mac.com
Sat Jun 11 07:01:01 PDT 2011
The short answer is "yes", you can manipulate the tree (before walking, not during).
I am using tree adapter manipulations to reorganize the AST, and then handing the tree to the standard tree walker.
The only caution is that TreeIterator depends on parent pointers. I am contemplating a version that does not have this dependency, so i can base my trees on BaseTree, rather than CommonTree.
On 2011 Jun 11, at 00:53, srinivasan karthikeyan pitchai wrote:
> 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
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
Trevor John Thompson (425) 246-4023
net: tijet at me.com
Quidquid Latine dictum sit, altum videtur.
More information about the antlr-interest
mailing list