help-bison
[Top][All Lists]
Advanced

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

Re: C++ / multiple instances / iostreams


From: Laurence Finston
Subject: Re: C++ / multiple instances / iostreams
Date: Mon, 19 Jul 2004 20:49:59 +0200 (MEST)

On Mon, 19 Jul 2004, Hans Aberg wrote:

>
> But you need only this skeleton file if you use a semantic type with
> non-POD data members; otherwise the compiling the C output as C++ will
> suffice. In particular, if you use the Bison %union feature, then you can
> compile C as C++.
>

What's a POD?

I hesitate to suggest anything without trying it out first, but generally
speaking, I would define `YYSTYPE' to be a pointer if I was using
a class type as my semantic value.  Even if using a type with non-trivial copy
constructors was possible, calling a copy constructor is potentially expensive,
whereas copying a pointer is not.  My union looks like this:

%union
{
  char string_value[64];
  double real_value;
  signed int int_value;
  void* pointer_value;
};

I may revise my parser so that I just use the `void*' and don't
bother with the other types.  I thought it would be more convenient this way,
but it's not, really.

Hans' method of deriving all possible rule values from a common base class (if
I've understood him correctly) will probably work well for a lot of
applications.  In my application it wouldn't, but I've found that casting the
objects to the appropriate types as needed isn't any trouble.

Laurence




reply via email to

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