thanks jim again,
i am rereading the 'the definitve antlr reference'
seems i misunderstanded at this .
aexpr
: mexpr ('+' ^ mexpr)*
;
the explanation on the book is here
All nonsuffixed tokens are subtree leaf nodes (operands), and the elements
suffixed with ^ are subtree root nodes (operators). The only rule
that uses a rewrite is atom. The parenthesized expression alternative is
much clearer when you say explicitly -> expr rather than putting ! on
the left parenthesis and right parenthesis tokens.
but i still not quite understand the meaning of the node suffixed with ^
thanks,
BILL
在2009-10-06,"Jim Idle" <[email protected]> 写道: -----原始邮件-----
发件人:"Jim Idle" <[email protected]>
发送时间:2009年10月6日 星期二
收件人:
抄送:"[email protected]" <[email protected]>
主题:Re: [antlr-interest] [SPAM] Re:Re: help on rewritting the tree
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:[email protected]]
Sent:Sunday, October 04, 2009 10:07 AM
To:Jim Idle
Cc:[email protected]
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" <[email protected]>写道:
-----原始邮件-----
发件人:"Jim Idle" <[email protected]>
发送时间:2009年10月5日 星期一
收件人:"[email protected]" <[email protected]>
主题:Re: [antlr-interest] help on rewritting the tree
a: b -> ^(V b) ;
b : part (DOT^ part )* ;
part: ID( ABC )? ;
Jim
From:[email protected][mailto:[email protected]]on
Behalf Ofantlr_bill
Sent:Sunday, October 04, 2009 8:56 AM
To:[email protected]
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 ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address