[antlr-interest] accessing parent node in order to replace
Jim Idle
jimi at temporal-wave.com
Thu May 31 15:57:24 PDT 2007
Make the return value of production)_b the tree. In production-a, test
this for null. If null then rewrite with the production_a else rewrite
with the tree returned by _b.
{retTre == null}? -> ...
->
However, you should be able to find a way to do this without all that.
Perhaps you have factored things into production_b too much.
Have you considered dividing the things that cause a rewrite in one
rule, and those that don't in another., then rewriteing in _a accoreding
to which branch is taken:
p_a: token (
prod_c
-> ^(prod_c)
| prod_d ->
^(token balh)
)
;
prod_b : prod_c | prod_d ; // Only if you need a rule for them all at
once
prod_c : blah ;
prod_d : blah ;
Jim
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Pam L Sampson
Sent: Thursday, May 31, 2007 1:16 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] accessing parent node in order to replace
I would like to build a tree where in some cases I want the parent node
removed and replaced with a different tree. My question is how do I
access the parent node of the tree I am currently building. For example:
production_a
: token production_b
//tree built here
;
production_b
: token
//now here I would like to replace the tree built in production_a
//with a new tree for production_b but only in some cases
//how do I replace the previous subtree with the new one?
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070531/2d1ba7c7/attachment.html
More information about the antlr-interest
mailing list