[antlr-interest] Tree parser tree building bug and workaround

Monty Zukowski monty at codetransform.com
Tue Nov 28 10:53:57 PST 2006


Hi all,

I just found a bug in 2.7.7 (and 2.7.4).  I have a tree parser rule
that builds a tree (just adding a new parent node), like this:

rule1:
#( T1 T2 T3
  { ##=#(#[NEWROOT],##); }
  )
  ;

>From inside the action, I see that the tree is built properly.  But
for some reason, upon exit of the rule the AST for rule1 is replaced
by the original.  (You can see it in the generated code).

I didn't track down the problem in ANTLR itself.  However, I found a workaround:

rule1:
  subruleT1 { ##=#(#[NEWROOT],##); }
  ;

subruleT1
  : #( T1 T2 T3 )
  ;

Monty


More information about the antlr-interest mailing list