[antlr-interest] AST construction - adding extra children via semantic action

Bill Andersen bill.andersen at mac.com
Wed Aug 11 12:17:09 PDT 2010


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


More information about the antlr-interest mailing list