[antlr-interest] Parser question: producing an AST tree?
Sriram Durbha
cintyram at yahoo.com
Wed Oct 23 14:19:39 PDT 2002
in the internal implementation of toStringTree () to StringLKist is
calle d on the first child;
so both give almost similar output.. except the wrapping paranthesis..
2> what is the general rule for placing the caret? is it like the last
token which has the caret in a given alt, becomes the root?
3> i did a small test.. i have a expr grammar, and the ast created by
it, if i have a list of exprs, but if i want to see the tree generated
for all of them i have to make the semi colon the root of the tree ;
if i use toStringTree only the first expression is being shown in lisp
syntax
if i use toStringList, all are being displayed
if i use a dummy token do i have to create the tree manually? like
## =(DUMMY,#stmnt,##); it does not complain when i run the grammar thu
antlr if i use dummy token as rot like in (DUMMY^ stmnt SEMI)+ ;
but i get runtime exception
4> is there any corresponding viewer in c++ to see the ast generated
by parser [like in java using swing components ..]
thank you
cheers
ram
--- mzukowski at yci.com wrote:
> What does your tree walker look like? How do you know it is flat?
> Have you printed out a tree with toStringTree() or toStringList()?
> Note that in the rule below the second ID will be the root, not the
> first
> ID.
>
> Monty
>
> > -----Original Message-----
> > From: Vince Marco [mailto:vmarco at mac.com]
> > Sent: Wednesday, October 23, 2002 8:59 AM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] Parser question: producing an AST tree?
> >
> >
> > Here's a newbie parser question. I'm trying to produce a
> hierarchical
> > AST tree from a C++ source file. My lexer works over the
> > 400K codebase,
> > but when I walk the AST I get all the tokens as siblings...ie. a
> flat
> > tree. Here is my parser line for a method:
> > cppmethod
> > : (ID^ COLON COLON (TILDE)? ID^ LPAREN (param (COMMA
> > param)*)? RPAREN cppbody)
> > ;
> >
> > I thought that by putting in the carot "^" the remaining
> > tokens would be
> > added as children to the first ID. My objective was to get
> > the AST tree
> > nested as desired before generating a Walker. Is this a faulty
> > approach? All my tokens in the entire file are still
> > siblings (ie. no
> > children). Any suggestions for what I'm doing wrong?
> >
> > Vince
> >
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list