[antlr-interest] AST construction - adding extra children via semantic action
Terence Parr
parrt at cs.usfca.edu
Wed Aug 11 13:17:57 PDT 2010
Hi Bill.I think the way to do it is to have the arbitrary action add to the rule_list List built by ANTLR. try
> spec
> : ^(SPEC r+=rule+)
> { <add nodes to $r list> }
> -> ^(SPEC $r+)
> ;
It might just work :)
T
On Aug 11, 2010, at 12:17 PM, Bill Andersen wrote:
> Hi Folks
>
> Here's the relevant fraction of a tree grammar I'm working on...
>
> spec
> : ^(SPEC rule+)
> ;
>
> rule
> : ^(RULE_DECL ID alts)
> ;
>
> It's a grammar that recognizes a language, the output of which is another ANTLR grammar.
>
> I want the first rule to look like this:
>
> spec
> : ^(SPEC rule+)
> { < some action here > }
> -> ^(SPEC < augmented list of rules >)
> ;
>
> In other words, I want to add some extra RULE_DECL trees on to the end of whatever rule+ accumulates, based on semantic information gathered during the tree parse.
>
> Is there a straightforward way to do this?
>
> Thanks
>
> .bill
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list