help-bison
[Top][All Lists]
Advanced

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

Re: Deallocations upon parse errors?


From: Hans Aberg
Subject: Re: Deallocations upon parse errors?
Date: Wed, 17 Jan 2007 10:22:39 +0100

Not going into the stuff you are doing (as I use a C++ semantic type, doing the cleanup via the language :-)), the %destructor is not output language related, but merely invokes some code when the parser stack unwinds during error recovery. So if you use a pointer type, I gather %destructor should be as usable both when using the C and C++ parsers. The C-parser does not support compiled under C (though in earlier version of Bison, it may have compiled that way), so better use the C++ parser when using C++.

  Hans Aberg


On 17 Jan 2007, at 05:10, David Fang wrote:

Pick down some later version of Bison (2.3+); then, if you use the C
parser, there is a %destructor command, that can be used to handle
clean-up during error recovery. Another way is to use a C++ parser,
and a semantic type that does cleanup via the C++ language, but one
cannot then use %union.

   Hans Aberg

Hi,
        One of these days I'll sit down an use the new %destructor feature
in bison, but FWIW, it IS *possible* to to clean-up of the parser stack in C++, using only the C skeleton, and while using a union of various pointer types. It involves deducing the union type based on the state numbers and transitions on the parser stack. I described the recipe for doing this in
an old thread.

http://lists.gnu.org/archive/html/help-bison/2006-04/msg00023.html

Yeah, it might be disgusting, but it was educational.  :)

I verified that no symbol objects were leaked in the event of parse errors by defining class-overloaded operator new/delete (for all pointee types in
the union) to use pool-allocators and asserting that the pools were
'clean' upon global static destruction.  This method works with
traditional yacc, byacc, and all released versions of bison from 1.35 to
2.3 (present).

Fang







reply via email to

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