[antlr-interest] how to collect multiple AST under single root
Bryan Ewbank
ewbank at gmail.com
Tue Apr 12 14:03:53 PDT 2005
Yep, that's the same thing, written with a separate rule to give you a
handle. It still relies on the fact of default AST construction being
a forest (i.e., trees per element, linked as /siblings/) in the
subordinate /tmp_rule/.
On Apr 12, 2005 3:58 PM, Anton Arhipov <tonyfox24 at hot.ee> wrote:
> Thx!
>
> Actually this one worked for me:
>
> rule1: tmp:tmp_rule {#rule1 = #([RULE, "root"], #tmp); };
> tmp_rule : (rule2)*;
> rule2: ..... ;
>
> Bryan Ewbank wrote:
>
> > rule1: ( rule2 )* { #rule1 = #( [RULE, "root"], ## ); };
> >
> >Here, "##" means that tree already constructed. Note that you can
> >also write this in a more general way
> >
> > rule1: ( rule2 )* { ## = #( [RULE, "root"], ## ); };
> >
> >Hope this helps,
> >- B
> >
> >On Apr 11, 2005 6:09 PM, Anton Arhipov <tonyfox24 at hot.ee> wrote:
> >
> >
> >>hi! could anyone suggest please how could I collect multiple ASTs under
> >>a single root :
> >>
> >>rule1 :
> >> ( tmp:rule2 )*
> >> {
> >> #rule1 = #([RULE, "root"],tmp);
> >> }
> >> ;
> >>
> >>rule2 :
> >> ...............
> >> ;
> >>
> >>this creates only a root with a single child.
> >>
> >>thx.
> >>A.
> >>
> >>
> >>
> >
> >
> >
>
>
More information about the antlr-interest
mailing list