[antlr-interest] Duplicating Tree Nodes (in rewrite grammar)
parrt at cs.usfca.edu
Fri May 30 15:11:33 PDT 2008
ANTLRWill automatically build duplicates as necessary. Is this what
d : type ID (',' ID)* -> ^(DECL type ID)+ ;
ANTLR should make n copies of DECL and n-1 copies of type's tree.
On May 30, 2008, at 3:08 PM, Robin Hamilton-Pennell wrote:
> Hi all,
> Been stumbling against a problem lately which I'd like to get some
> feedback on.
> I need to duplicate a tree node at a certain point in my AST rewrite
> grammar, including all of its children (recursively). If I knew the
> number of copies necessary in advance, I imagine I could do something
> like this:
> ^(BAR baz) -> ^(BAR baz) ^(BAR baz) ^(BAR baz)
> However, the number of copies necessary is not knowable until runtime.
> I tried simply using CommonTree.dupNode(), but it doesn't copy the
> children (after reading through the source I know this is correct
> So I guess my question is this: How can I make an arbitrary number of
> copies of a tree node and all sub-trees? I don't actually care about
> making changes to the tree yet, I just want a verbatim copy.
> Any advice would be appreciated.
> Thanks in advance,
More information about the antlr-interest