On 16 Sep 2005, at 19:14, Frans Englich wrote:
I have a problem involving bison although a solution may not
directly mean
modifying the bison grammar. Nevertheless, someone might be able to
spot a
solution.
From my actions I call factory functions which returns instances I
assign to
the actions($$), in order to build an AST tree. I write in C++, and
recently
converted all code to return/take shared pointers to objects,
instead of raw
pointers.
When it came to converting the Bison grammar, I of course ran into
the problem
that the union can't house class objects(such as shared_ptr
instances), but
only primitive types.
There are two ways to solve this problem. One is to store a common
pointer a pointer of type void* in the union. You are then
essentially doing C-programming, and must do cleanup by hand in the
actions, and using %destructor.
The other way is to make of the C++ language features. One is then
making a C++ polymorphic (virtual) class hierarchy, which is stored
in the semantic type. One cannot then use %union, so wither one does
not use it, and uses dynamic_cast, or one hopes for Bison to be
augmented so that one still use the Bison static type system. I use
the first one using my own C++ skeleton file and a Bison tweak, and I
know, more or less, how to do the second one.
There is some C++ support in Bison, but I do not know how it works;
Akim Demaille is responsible for that.
Hans Aberg
_______________________________________________
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison