[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Fwd: question about error handling]
From: |
Dave Dutcher |
Subject: |
RE: [Fwd: question about error handling] |
Date: |
Tue, 12 Jun 2001 15:02:21 -0500 |
Aren't there times when you need to use a union? I know when all the tokens
in the file I am parsing are strings, I define YYSTYPE to be std::string or
something, and that makes handling strings real easy and there are no memory
leak problems. Sometimes though I have a grammer that has multiple types,
like perhaps a '+' operator that can work on numbers and strings. Then I
thought I had to use a union? In your method, do you have a way that a rule
could work on different types and not use a union?
> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Behalf Of Hans Aberg
> Sent: Tuesday, June 12, 2001 2:28 PM
> To: David Durham
> Cc: Bison Help
> Subject: Re: [Fwd: question about error handling]
>
>
> At 13:16 -0500 2001/06/12, David Durham wrote:
> >I'm not following you, but I'll respond anyway ;)
> ...
> >in fact I do use the %union feature... All (most really) of the
> >elements in the union are pointers to derivations of that base class,
> >that because, of course, I need parse tree nodes to have a certain
> >semantic value.
>
> What I am saying is that if one does not use the %union
> feature, which the
> parser implements as a C/C++ union, then one can instead use
> a C++ class as
> the YYSTYPE, and it can take care of the memory management via its
> destructor.
>
> If one does use the %union feature, then it is clear that
> pointers must be
> cleaned up separately by some method if one wants to avoid
> memory leaks, as
> the C/C++ unions do not have any user defineable destructors and only
> accept data without user defined destructors.
>
> Hans Aberg
>
>
>
> _______________________________________________
> Help-bison mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/help-bison