help-bison
[Top][All Lists]
Advanced

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

Re: Token types with constructor


From: Laurence Finston
Subject: Re: Token types with constructor
Date: Thu, 2 Sep 2004 16:51:13 +0200 (MEST)

On Thu, 2 Sep 2004, Martin Trautmann wrote:

> Hi,
>
> its funny that 4 persons have 4 oppinions how bison should cooperate
> with C++.


I don't claim that my way is how Bison "should" cooperate with C++.  It's
one way that it _can_.

One advantage of my way is that it doesn't require a patch, an
experimental version of Bison, or even the most recent stable release.

> 2) Construct a Token in the lexer and destruct it in every rule. There
> the experimental %destructor definition is needed to avoid memory leaks
> during error recoverage. Bison calls this when it discards tokens.

While it's possible to construct objects in the scanner, I only do so in
one place.  I usually construct objects in the parser actions.
My point was that if a program creates heap objects,
they will probably have to be destroyed.  While Bison's stack management
routine may take care of copying and destroying temporaries, it will not
automatically destroy the original objects created dynamically in the
parser actions or in `yylex()'.

There would be no point to destroying them
in every rule.  It is necessary to cast them to the proper type if you
want to use the value.
Otherwise, it can just be "passed on" as a "void*".  I doubt that it
will be necessary to use the `%destructor' feature, but I don't
know for sure yet.

Laurence




reply via email to

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