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

Randall R Schulz rschulz at sonic.net
Sat Jul 7 08:50:02 PDT 2007


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?


Randall Schulz


More information about the antlr-interest mailing list