[antlr-interest] Swapping root node

Edward Povazan epovazan at telus.net
Fri Dec 5 21:13:13 PST 2003


Hello,

I am creating a heterogenous tree. Is there an easy way to swap a root. For
example:
lp:LPAREN^ (param_list)? rp:RPAREN!
// This is base AST node, need to put my own in
// { #lp.setType(METHOD_CALL); #lp.setText("method_call"); }
{
AST children = astFactory.dupList(#lp.getFirstChild());
## = #([METHOD_CALL, "method_call"], children);
}

Is there no 'cleaner' way? Is there a more detailed doc about AST
manipulation somewhere? I am doing a few transformations to make my back end
code gen simpler, and I am not sure if my 'scary' looking code is the normal
way to do it :) it works though.

Also, why does this fail:
## = #([METHOD_CALL, "method_call"],
astFactory.dupList(#lp.getFirstChild()));
The #lp.getFirstChild() compiles to lp.getFirstChild(), I expected
lp_AST.getFirstChild().

Thanks
-Ed




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list