help-bison
[Top][All Lists]
Advanced

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

Re: Memory (de)allocation ...


From: Hans Aberg
Subject: Re: Memory (de)allocation ...
Date: Mon, 5 May 2003 19:00:11 +0200

At 17:01 +0100 2003/05/05, Ricardo Rafael wrote:
>       I am developing a script language compiler using Flex (C++
>classes generated) and Bison (%pure-parser directive used), that will be
>running as a multi-threaded server process (in Win32). What should I do
>in order to avoid memory leakage?
>
>    a) Manually write all deallocation code in every single action;
>
>    b) Use the following Bison syntax:
>          %destructor { delete $$; } program
>          %destructor { if ( $$.mem ) delete $$.mem; } items rule2
>          %destructor { complexCode( $1 ); delete $$; } xpto_rule
>          ...
>
>    Option b) should be the correct one, right!? In case of a syntax
>error, the right destructors are always called. Am I correct?! Or am I
>missing something.

Yes, that %destructor stuff is for C, a language which does not support
user written constructors/destructors. If you use C++, merely make sure to
use a parser that uses properly written C++ containers for stack (for
example the standard library sequence containers std::vector, std::deque,
std::list).

There is a C++ skeleton file for generating C++ called lalr1.cc in Bison
1.75. I could not make it work, so I made my own version; unfortunately my
version also requires some additional Bison tweaks, so it would not help
you. -- My intention is to eventually land on a closer Flex/Bison
lexer/parser C++ class integration, but unfortunately, I can't work on it
now. (I need to get hold of a better computer, etc, first. :-) )

  Hans Aberg






reply via email to

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