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

David Holroyd dave at badgers-in-foil.co.uk
Mon Feb 25 08:36:07 PST 2008


On Mon, Feb 25, 2008 at 08:23:22AM -0800, Carter Cheng wrote:
> 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.

If you mean, can you have a result 'tree' without a root, then yes
(NB lower-case letters for parser rule names):

  ruleA: B C D E;
  rule1: ruleA F -> ^(DEF ruleA F)
         ;

will result in a result tree being produced from rule1 which has DEF as
its root, and B C D E F as its children.

Actually, ANTLR does this by producing a special ('null') tree node as
the result of ruleA which will be recognised and discarded when added to
the result tree of rule1, if that makes any sense..?


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list