help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unabled to Free Discarded Tokens


From: Hans Aberg
Subject: Re: Unabled to Free Discarded Tokens
Date: Sat, 14 Feb 2004 19:39:15 +0100

At 08:27 -0700 2004/02/14, Mike Ady wrote:
>I have a lexer that uses malloc (more than once) to store the data
>associated with most tokens.  These malloc'ed tokens are then assembled into
>various structures by my parser before being executed and finally freed.
>Everything is fine until an error occurs.  I suffer memory leaks whenever
>Bison is forced to discard tokens.
>
>I've searched the documentation...  Is there any way to get Bison to call a
>routine (to free allocated memory) for each discarded token?
>
>Or am I just going about this the wrong way?  Creating a symbol table for
>this application would seem to be overkill.

You have got it right: With Bison generate parsers in C, you must either
keep track of the allocations separately and deallocate them when
appropriate, and free them by hand, or you might try an experimental
%destructor, which I think might be undocumented. The %destructor only
makes destructions when in error recovery mode; other deallocations must
still be done. See a recent post in the Bug-Bison list.

I use Bison generated parsers in C++, where the language can create code
that performs the correct deallocations.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]