Re: Yacc parsers: Cleaning up the wreckage!

"Dwight VandenBerghe" <>
19 Aug 1997 22:51:59 -0400

          From comp.compilers

Related articles
Yacc parsers: Cleaning up the wreckage! (1997-08-16)
Re: Yacc parsers: Cleaning up the wreckage! (Dwight VandenBerghe) (1997-08-19)
Re: Yacc parsers: Cleaning up the wreckage! (Markus Armbruster) (1997-08-20)
Re: Yacc parsers: Cleaning up the wreckage! (1997-08-24)
| List of all articles for this month |

From: "Dwight VandenBerghe" <>
Newsgroups: comp.compilers
Date: 19 Aug 1997 22:51:59 -0400
Organization: Pentasoft Corporation
References: 97-08-047
Keywords: yacc, errors

Martin Harvey <> 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.


Post a followup to this message

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