[antlr-interest] [C target] Duplicating tree error

Gavin Lambert antlr at mirality.co.nz
Thu Jan 21 03:42:01 PST 2010

At 00:21 22/01/2010, =?koi8-r?B?4NLV28vJziDtycjBycw=?= wrote:
 >   : label? declaration_type_spec ( (T_COMMA  attr_spec )*
 >     entity_decl (T_COMMA entity_decl)* end_of_stmt    	
 >     -> ^(T_TYPE_DECLARATION_STMT declaration_type_spec 
 >   ;
 >BUT declaration_type_spec subtree isn't dublicated (only the 
 >of subtree).
 >Where is mistake?

IIRC, when you use a rule name in a rewrite rule, it represents 
"the first unused instance of this rule in the input" (which is 
why entity_decl is doing what it is).  So the second and 
subsequent times it appears (during the + loop) the value is empty 
since it didn't occur any more times in the input.  To duplicate 
nodes you need to use a label.

More information about the antlr-interest mailing list