[antlr-interest] transforming AST's in place when generated

Mark Wright markwright at internode.on.net
Mon Feb 25 17:35:10 PST 2008


> Well it's probably a bit of a beginner question but I
> was wondering if you could in general reach into
> already created subtrees and reconstitute them as you
> pass them up the tree. Or perhaps return a forest i.e.
> do something like this-
> 
> RuleA: RuleB RuleC RuleD RuleE;
> 
> Rule1:
>        RuleA RuleF -> ^(DEF RuleB RuleC RuleD RuleE
> RuleF)
>      ;
> 
> i.e. somehow have RuleA pass back something where one
> could reach into it an extract RuleB RuleC RuleD RuleE
> and construct a new tree discarding information or
> just raw passing of RuleB RuleC RuleD RuleE without
> messing with the returns syntax.

Hello Carter,

Yes:

RuleA: RuleB RuleC RuleD RuleE;

Rule1:
      RuleA RuleF -> ^(DEF RuleA RuleF)
      ;

Which builds the tree, as output by CommonTree.toStringTree():

(DEF RuleB RuleC RuleD RuleE RuleF)

Where RuleB RuleC RuleD RuleE RuleF are also expanded
into whatever they are.
 
> I however think what your initial reply suggested is
> enough for me to complete the task I have in hand so
> thanks again.
> 
> Regards,
> 
> Carter.

Great, thanks.

Regards, Mark

-- 


More information about the antlr-interest mailing list