help-bison
[Top][All Lists]
Advanced

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

Re: Token types with constructor


From: Hans Aberg
Subject: Re: Token types with constructor
Date: Thu, 26 Aug 2004 19:43:39 +0200

At 20:08 +0200 2004/08/25, Laurence Finston wrote:
>> I am using bison for some time in a C++ Project and I need a Token Type
>> that may have a constructor.

>There seem to be two schools of thought on this subject:
>I like to use pointers to `void', while Hans Aberg has created a patch
>that makes it possible to use a C++ parser class.  The latter is not
>thread-safe, however.  (I hope I've stated the case accurately).

Yes, your approach essentially avoids using C++ constructors. One
shortcoming with this approach is that one cannot use C++ automatics to
deallocate free store objects. So if one uses such objects pointed at by
void*, one has to deallocate them by hand in the rule actions, plus using
the experimental %destructor option to deallocate them during error
recovery, that is, if it is essential for your program to avoid memory
leaks.

Even though my parser is not thread safe, it should be easy to make it so,
by merely moving the parser stack into the function. Also, perhaps change
std::vector to std::deque.

  Hans Aberg






reply via email to

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