[antlr-interest] About tree duplication ?
Bryan Ewbank
ewbank at gmail.com
Thu Nov 17 12:35:45 PST 2005
> > Another way that is closer, perhaps, to what you are wanting,
> > is to write a production that duplicates a node (works only
> > with buildAST=true).
>
> mmmmh, would you mind to give me an example ? I have some
> difficulties to draw something wich approach your suggestion...
A production like this will generate an exactly duplicate of a
tree....
// duplicate tree rooted at current node
duptree: #( . ( duptree )* );
Or perhaps this, to reduce push/pop on the call stack by following
sibling chains in one function:
// duplicate tree rooted at current node
duptree: #( . duplist );
duplist: ( #( . duplist ) )*;
When I am building a transformation pass, I usually start here,
and then start extending it for exceptions (e.g., "copy it everywhere,
except when ...").
More information about the antlr-interest
mailing list