help-bison
[Top][All Lists]
Advanced

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

Re: Re[2]: bison %union and C++


From: Hans Aberg
Subject: Re: Re[2]: bison %union and C++
Date: Mon, 30 Sep 2002 11:15:13 +0200

At 10:42 +0200 2002/09/30, Akim Demaille wrote:
>AD> Using pointers to string. Or make sure to have a single hierarchy,
>AD> which means that you must wrap std::string :(
>Oleg> yeah, but every time bison removed something from the stack I
>Oleg> get a memory leak. (which I have worked around by keeping track
>Oleg> of what bison allocs and frees, but it's quite nasty)
>
>If you are ready to use a beta (and it will certainly change in the
>future, so *this is a bad idea*), you can try this:
>
>%destructor { delete $$; } expr stmt etc...
>%destructor { free ($$); } C_STRING

This will leak when using C++ exceptions:

Under C++, one usually must allow the exception handling stack unwinding
see the objects whose resources should be destroyed.

It may happen can handle it by the use of a construct
  try {
    // Bison generated code.
  } catch (...) {
    // Bison destructor code
    throw; // re-throw the exception.
  }

Then any C++ exception out of the Bison parser will be able to execute
resource deallocating before passing the exception on to the program
calling the parser.

Some may use an "embedded C++" subset which does not admit C++ exceptions.
So Bison should support that, then that try-catch construct above must be
an option.

  Hans Aberg






reply via email to

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