Re: Yacc parsers: Cleaning up the wreckage!

"Dwight VandenBerghe" <dwight@pentasoft.com>
19 Aug 1997 22:51:59 -0400

          From comp.compilers

Related articles
Yacc parsers: Cleaning up the wreckage! mch24@harvey27.demon.co.uk (1997-08-16)
Re: Yacc parsers: Cleaning up the wreckage! dwight@pentasoft.com (Dwight VandenBerghe) (1997-08-19)
Re: Yacc parsers: Cleaning up the wreckage! armbru@pond.sub.org (Markus Armbruster) (1997-08-20)
Re: Yacc parsers: Cleaning up the wreckage! mch24@harvey27.demon.co.uk (1997-08-24)
| List of all articles for this month |

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

Martin Harvey <mch24@harvey27.demon.co.uk> 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.


Dwight
--


Post a followup to this message

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