[antlr-interest] RE: Thanks for Your Help and question

james_cataldo at agilent.com james_cataldo at agilent.com
Thu Jul 27 09:22:25 PDT 2006


On second thought, this is about how to walk trees using a tree parsrers.  Building trees is very simple.  It's in the doc's on 

http://www.antlr.org/doc/metalang.html#_bb4 

under the heading  "Production Element Operators".  To build a tree, 


1) add 

> buidAST = true; 

to the options section of your parser.

2) For any token/rule that should serve as a root of a subtree, add 
'^'.  Example:

> add :
>   NUM PLUS^ NUM
> ;

gives you the tree

#(PLUS NUM NUM), or equivalently 

    PLUS
   /    \
NUM      NUM

3) For any token/rule you want to ignore, add '!'.  Example:

> command :
>  ID^ LPARENTHESIS! (ID (COMMA! ID)*)? RPARENTHESIS!
>

gives you

#(ID ID ... ID)

where the root of this tree is the first ID.

I hope this helps.

Cheers,
Adam

-----Original Message-----
From: Naveed Riaz [mailto:nriaz at ist.tugraz.at] 
Sent: Thursday, July 27, 2006 5:43 AM
To: james_cataldo at agilent.com
Subject: Thanks for Your Help and question

Dear james Cataldo...
Thank You very much for your help on antlr-interest ...
I hope you dont mind contacting on your personal email address.
Actually my problem is that i dont think that there is complete reference on antlr website that how a text parser grammar like provided in the antlr website for verilog can be transformed in to the tree parsing grammar.  How do i have to annotate that grammar and what kind of rules i should have in mind before the conversions.
I shall be really thank ful if you can guide me in this aspect....
Best of Regards...



More information about the antlr-interest mailing list