[antlr-interest] ANTLR tree construction - list

Bill Andersen bill.andersen at mac.com
Mon Jun 13 06:32:23 PDT 2011


Folks,

Ought to be a pretty simple question.  I have the following production in a combined grammar with tree output

collection returns [CommonTree name]
@init {
  List<CommonTree> rest = new LinkedList<CommonTree>();
}
  : OPEN { $name = pushName(newName()); } 
      ( term { rest.add($term.rest); })+ 
    CLOSE { popName(); }
    -> ^(COL { $name } term+) ????
  ;

This production is supposed to match a "collection" - An open paren followed by a non-zero-length sequence of <term> followed by a close paren.  Each <term> has two outputs - the default tree return, and the "rest" tree.  I want the output of this production to be the sequence of the COL tree prepended to all the "rest"s which are accumulated in the @init list.

I know, for example, that I can do stuff like this:

test
  :  foo bar baz
    -> foo baz
  ;

to have the list of 'foo' and 'baz' trees as output.  Thing is I don't know what to do with the 'rest' list above to have its elements appear in the output tree.

Can someone tell me what needs to go in place of ????

Thanks!

	.bill




More information about the antlr-interest mailing list