[antlr-interest] How to change AST node order in Java ?
Curtis Clauson
NOSPAM at TheSnakePitDev.com
Mon Nov 12 19:33:09 PST 2007
Jaak Niit wrote:
> Is there solution to change AST node order in Java ?
>
> If current node have children A, B, C, D and I want to change order to
> A, D, B, C.
> BaseTree has methods deleteChild(int i) and addChild(Tree t),
> but addChild(int offset, Tree t) is missing.
>
> I want to write something like
> BaseTree D = t.getChild(3);
> t.deleteChild(3);
> t.addChild(1,D);
>
> So problem is how to add node in middle of list.
The default object used for an AntLr tree is CommonTree which
sub-classes BaseTree which implement the Tree interface. BaseTree
extends the Tree interface with, among others, the method
void setChild(int i, BaseTree t)
You can simply cast your tree object to BaseTree or CommonTree, or
specify the returned type in the grammar with the ASTLabelType option.
I hope that helps.
-- Curtis
More information about the antlr-interest
mailing list