[antlr-interest] [SPAM] Re:Re: help on rewritting the tree

Jim Idle jimi at temporal-wave.com
Mon Oct 5 10:32:02 PDT 2009


ANTLR trees can have many children. Your javaSource rule will be fine, but because all elements are optional you need:

 

J: ^(V etc)

  | V // Empty translation unit

;

 

It is easier to see how the tree is going if you break it down and do not try to create sub trees in a rewrite rule. When you create subtrees, the created node does not properly have the start and end tokens for the sub tree and so on because these happen at rulePostProcessing, not within a rewrite.

 

Don’t use imaginary nodes unless they are necessary to create an unambiguous tree, so the DOT token is just fine as a root node for each element of a compound and you probably only need the imaginary as a root for the whole reference.

 

Jim

 

From: antlr_bill [mailto:antlr_bill at yeah.net] 
Sent: Sunday, October 04, 2009 10:07 AM
To: Jim Idle
Cc: antlr-interest at antlr.org
Subject: [SPAM] Re:Re: [antlr-interest] help on rewritting the tree

 

Hi Jim, thanks for you quick reply !

do you mean i should break them into pieces ?
cause the tree structure only can have two children in maximum

if so ,so how about this one? break them too ? 

javaSource
    :   (packageDeclaration)? (importDeclaration)* (typeDeclaration)*
    ->^(V packageDeclaration? importDeclaration* typeDeclaration*)
    ;

here means the java source file can contain  package and import and type ,three kinds of element 
but i wrote that tree like that , is it right ?

any article about this ? i read the book of antlr many times on the tree grammer ,but still didnt get all of it 

thanks again!


BILL


在2009-10-05,"Jim Idle" <jimi at temporal-wave.com> 写道: 

-----原始邮件-----
发件人:"Jim Idle" <jimi at temporal-wave.com>
发送时间:2009年10月5日 星期一
收件人:"antlr-interest at antlr.org" <antlr-interest at antlr.org>
主题:Re: [antlr-interest] help on rewritting the tree

a: b -> ^(V b) ;

 

b : part (DOT^ part )* ;

 

part:  ID( ABC )? ;

 

Jim

 

From: antlr-interest-bounces at antlr.org[mailto:antlr-interest-bounces at antlr.org]On Behalf Ofantlr_bill
Sent:Sunday, October 04, 2009 8:56 AM
To:antlr-interest at antlr.org
Subject:[antlr-interest] help on rewritting the tree

 

can someone please help on this ?
i have an rule like this :

a:
 :   ID( ABC )? (DOT ID (ABC)? )*
;
how to rewrite it into a tree grammer ?

 

 

 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091005/e1b81723/attachment.html 


More information about the antlr-interest mailing list