|Yacc parsers: Cleaning up the wreckage! firstname.lastname@example.org (1997-08-16)|
|Re: Yacc parsers: Cleaning up the wreckage! email@example.com (Dwight VandenBerghe) (1997-08-19)|
|Re: Yacc parsers: Cleaning up the wreckage! firstname.lastname@example.org (Markus Armbruster) (1997-08-20)|
|Re: Yacc parsers: Cleaning up the wreckage! email@example.com (1997-08-24)|
|From:||"Dwight VandenBerghe" <firstname.lastname@example.org>|
|Date:||19 Aug 1997 22:51:59 -0400|
Martin Harvey <email@example.com> wrote
> How on earth do I go about clearing up?? I suspect I need to comb
> through the parser stack finding all the parts of the syntax tree and
> deallocating them. However, this presents problems for me...
You thread all the objects that you create on the heap in a chain that
is rooted in some global variable, then at error time you run through
this chain and free everything that isn't a valid node. Please note
that this amazingly terrible kludge is *not* a problem with yacc.
It is a problem with C and C++, which make you manage your own storage.
My general solution to the problem is to write compilers in something
other than C/C++. [Popular wisdom to the contrary, they really aren't
good compiler-writing languages, and not just because of not having a
garbage collector.] Objective Caml, for example, comes with a complete
yacc implementation that offers some improvements over the original,
and there is never a need to worry about collecting your own garbage.
If you *must* stick with C/C++, you might want to take a look at one
of the gc packages that are available - Boehm's for free, Great Circle
for $$$. These will free up storage for you, as long as you play by
their not-too-restrictive rules.
Return to the
Search the comp.compilers archives again.