Re: Reclaiming dynamic memory if parse fails?

Mark Holland <kenshin_40@htomail.com>
Mon, 16 Jul 2007 19:29:55 +0100

          From comp.compilers

Related articles
Reclaiming dynamic memory if parse fails? carsonbj@gmail.com (carsonbj@gmail.com) (2007-07-13)
Re: Reclaiming dynamic memory if parse fails? chris.dollin@hp.com (Chris Dollin) (2007-07-16)
Re: Reclaiming dynamic memory if parse fails? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-16)
Re: Reclaiming dynamic memory if parse fails? kenshin_40@htomail.com (Mark Holland) (2007-07-16)
Re: Reclaiming dynamic memory if parse fails? martin@gkc.org.uk (Martin Ward) (2007-07-16)
Re: Reclaiming dynamic memory if parse fails? blume@hanabi.local (Matthias Blume) (2007-07-18)
| List of all articles for this month |

From: Mark Holland <kenshin_40@htomail.com>
Newsgroups: comp.compilers
Date: Mon, 16 Jul 2007 19:29:55 +0100
Organization: freedom2surf
References: 07-07-051
Keywords: parse, errors

<carsonbj@gmail.com> wrote
> I'm using lex and yacc for parsing a configuration file that builds
> a dynamically allocated tree structure for runtime searching as user
> requests come in. When a parse fails, in the middle of the
> configuration file, and the tree is partially built, how can I
> reclaim all of the dynamic memory gracefully? The tree is built
> from the bottom up, the references to the pointers of the tree are
> passed between each of the grammar rules using the $$ = (some
> pointer) scheme, finally the root of the tree is set at the start
> symbol.


<snip globals idea>


The newer versions of Bison have this already. In your grammar
definition file you can specify %destructor definitions for each of
your grammar symbols. These will be called if there is a failure
during parsing for each symbol which has been created when the parser
is clearing up it's internal stack.


Here is a link to the relevant manual section:
http://www.gnu.org/software/bison/manual/html_mono/bison.html#Destructor-Decl


HTH
Mark


Post a followup to this message

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