[antlr-interest] Nested Closures -> Nested AST Generation

Randall R Schulz rschulz at sonic.net
Sat Jul 7 11:08:27 PDT 2007


On Saturday 07 July 2007 10:55, Johannes Luber wrote:
> Randall R Schulz wrote:
> > Hi,
> >
> > Here is a fragment of a AST-generating grammar I have:
> >
> > atom
> >   : ( '('
> >         predicate = term
> >         '('
> >           RoleSet ( '(' role = name arg = term ')' ) *
> >         ')'
> >       ')'
> >     )
> >   ->  ^( RoleSet $predicate ^( RoleArg $role $arg ) * )
> >   ;
> >
> >
> > I've discovered (through the miracle of DOTTreeGenerator!) that no
> > matter how many repetitions of the ( role=name arg=term ) tuples
> > appear following the RoleSet token, only one RoleArg subtree is
> > present in the synthesized AST. That single RoleArg subtree's
> > values always correspond to the last repetition of the RoleSet
> > tuples that was present in the input.
> >
> > Am I doing this wrong, or is this a bug?
>
> Try "RoleSet ( '(' role+=name arg+=term ')' ) *".

Great, thanks, that works. I had a work-around, but it was not quite as 
clean as this (it took an auxiliary production).


> Best regards,
> Johannes Luber


Randall Schulz


More information about the antlr-interest mailing list