[antlr-interest] Re: Swapping root node

lgcraymer lgc at mail1.jpl.nasa.gov
Fri Dec 5 23:40:23 PST 2003


Ed--

Until we can get 2.8e (e for experimental) out (January is likely), 
you're stuck with this approach.  2.8e will provide a target-
language independent (excepting construction predicates) syntax for 
rewriting trees.

For your example, change #lp to #lp_in; that will get you the input 
AST for duplication.

--Loring


--- In antlr-interest at yahoogroups.com, "Edward Povazan" 
<epovazan at t...> wrote:
> 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