Re: yacc parse tree

Sukru Cinar <scinar@ug.bcc.bilkent.edu.tr>
21 Dec 1998 11:49:30 -0500

          From comp.compilers

Related articles
yacc parse tree josh_adams@bmc.com (Josh Adams) (1998-12-10)
Re: yacc parse tree simon.cozens@pembroke.oxford.ac.uk (Simon Cozens) (1998-12-13)
Re: yacc parse tree mikesw@whiterose.net (1998-12-13)
Re: yacc parse tree bob@werken.com (1998-12-18)
Re: yacc parse tree belinfan@cs.utwente.nl (1998-12-18)
Re: yacc parse tree josh_adams@bmc.com (Josh Adams) (1998-12-19)
Re: yacc parse tree joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-12-19)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1998-12-21)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1998-12-22)
Re: yacc parse tree AMartin@ma.ultranet.com (Alan H. Martin) (1999-01-02)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1999-01-02)
Re: yacc parse tree buzzard@world.std.com (1999-01-02)
| List of all articles for this month |
From: Sukru Cinar <scinar@ug.bcc.bilkent.edu.tr>
Newsgroups: comp.compilers
Date: 21 Dec 1998 11:49:30 -0500
Organization: Bilkent University
References: 98-12-018 98-12-022
Keywords: yacc, parse, comment

> > get to the top, you have a parse tree. The most annoying part is
> > allocating and deallocating the tree nodes, particularly if you want
> > to recover from parse errors.
>
> I imagine Knuth would have a clever data-structure based solution to this
> one - is anyone aware of any work done on the idea of the parser
> constructing a *tree of trees*?


Once I had done something similar, maybe it suits for you too. you can
get it at


http://www.ug.bcc.bilkent.edu.tr/~scinar/st.tgz


The trick is done in the file yaccp. tree specific functions are in
tnode.c


instead of using the $$ thing, I prefer constructing the tree myself
like this:


when ruleN is reduced,
make a tree whose root is the rule that has just reduced
and children are the children :)
save it to a global variable.


this is done easily by modifiying the output of yacc.


when yyparse() exits, global variable is the root of the whole tree.


****************************************************************************
Sukru Cinar scinar@ug.bcc.bilkent.edu.tr
YetNotGraduate Computer Science Student in Bilkent/Turkey
[Seems to me you're just building your own stack parallel to the one
that yacc already keeps for you. I don't see the advantage of storing
the tree pointer in a global, other than the final top-level tree since
yacc doesn't let you return it from yyparse(). -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.