[antlr-interest] [C target] Duplicating tree error
jimi at temporal-wave.com
Thu Jan 21 06:47:57 PST 2010
Well, you are rewriting the tree with ^(....)+ but the tree grammar only walks one declaration ^(...). Unless you are using the + higher up the rule chain.
... e+=entity_decl (COMMA e+=entity_decl)* ...
-> ^(X .... $e)+
Also, your rewrite rule loses the label.
It is generally a good idea to break components up in to separate rules when rewriting as then the token boundaries of nodes are correctly set. So here, you would move label? In to a higher rule for instance.
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Þðóøêèí Ìèõàèë
> Sent: Thursday, January 21, 2010 3:57 AM
> To: Gavin Lambert; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] [C target] Duplicating tree error
> Excuse me, what you mean behind "you need to use a label"? Could you
> And, currently, I haven't seen problems with duplicating of
> I have a fault with a coping of "declaration_type_spec" tree.
> Gavin Lambert <antlr at mirality.co.nz> писал(а) в своём письме Thu, 21
> 2010 14:42:01 +0300:
> > At 00:21 22/01/2010, =?koi8-r?B?4NLV28vJziDtycjBycw=?= wrote:
> > >type_declaration_stmt
> > > : label? declaration_type_spec ( (T_COMMA attr_spec )*
> > >T_COLON_COLON )?
> > > entity_decl (T_COMMA entity_decl)* end_of_stmt
> > > -> ^(T_TYPE_DECLARATION_STMT declaration_type_spec attr_spec*
> > >entity_decl)+
> > > ;
> > [...]
> > >BUT declaration_type_spec subtree isn't dublicated (only the root
> > >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
> > appears (during the + loop) the value is empty since it didn't occur
> > more times in the input. To duplicate nodes you need to use a label.
> > __________ Information from ESET Smart Security, version of virus
> > signature database 4792 (20100121) __________
> > The message was checked by ESET Smart Security.
> > http://www.esetnod32.ru
> Best regards,
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
More information about the antlr-interest