[antlr-interest] can i do it like this ?

antlr_bill antlr_bill at yeah.net
Tue Oct 13 07:51:45 PDT 2009


Hi All,
I am still thinking about how to write the grammer ,after some research ,i found the grammer is always too complicated cause it need to parse the complicated sources ,so surely we need to write the grammer all manually .
but how about the tree grammer ? can I simply copy all the grammer into the tree grammer file and include them by ^(   ),also add an imaginary node . like this :
//here is a  grammer which meet a class or an interface of Java source

classOrInterace:
       PUBLIC? (INTERFACE | CLASS ) IDENTIFIER '{'
       classOrInterfaceBody
       '}'
;
so here can I write a tree grammer for this rule as below ?
classOrInterace:
       PUBLIC? (INTERFACE | CLASS ) IDENTIFIER '{'
       classOrInterfaceBody
       '}'
-> ^( CLASS_OR_INTERFACE PUBLIC? (INTERFACE | CLASS ) IDENTIFIER classOrInterfaceBody)
;


the green are the grammer ,and the blue and red are the tree grammer !!!

repeat again ,no matter how the grammer looks like ,i just copy all of them ,and add the ^( ) also an imaginary node , can I do it ?

the reason why I wanna do like this ? cause sometime I dont care about the efficiency ,i just wanna find a general way which I can write a program to generate all the code for me , sure the best way is write the tree grammer manually too , but because now I am not so familiar with the tree grammer and this wonderful antlr project ,so I am learning it and also trying to find a way to write an demo of an translator .


can somebody here tell me whether i can do it as i just described ,and more important thing is what should it learn if i wanna write the tree grammer manually !! 

it there a conclusion of antlr which can as an dictionary ? as a newbie of antlr ,i am not sure i learned all of the features of antlr ,

Thanks 

BILL at 20009



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


More information about the antlr-interest mailing list