1

I will try to be briefly.

Currently we are using the GNU Bison to construct an Interpreter tree, that later on will be saved was a proprietary format and loaded by our server. So we use a lot of dynamic allocation inside the Bison code. The problem is that recently I found out if Bison gets any syntax error, we get a lot of memory leaks, because during the parsing some parts of the tree were already allocated. Reading some books and I found a little about the "Error Recovering" and the %destructor. The first one seems to the right way to go, but the use of the %destructor wasn't so clear for me yet.

So, if for some reason the Bison isn't able to re-synchronize, does the it means that the %destructor will be called to delete the all token/symbols that was created?

1 Answers1

1

This question is a duplicate of :

When is %destructor invoked in BISON?

In fact to my point of view the %destructor directive is almost useless : If you redefine the YYSTYPE, you can specify an alternate C++ class/union with what exactly what you want

class AToken
{
   char     *text;
 public:
   AToken() : text(0) {}
   ~AToken() { delete [] text; }
   ...
};

#define YYSTYPE AToken
Community
  • 1
  • 1
VGE
  • 4,171
  • 18
  • 17