help-bison
[Top][All Lists]
Advanced

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

Re: [Fwd: question about error handling]


From: ashish sehgal
Subject: Re: [Fwd: question about error handling]
Date: Mon, 11 Jun 2001 15:04:14 -0400

David Durham wrote:

> As far as cleaning up memory upon parse errors... Here's what I did..
> I'm using C++, but I'm sure something like this could be done with C if
> you try really really hard ;)
>
> Anyway, all my parse tree nodes are C++ classes and they are all derived
> from a base class.  This base class's constructor adds the this pointer
> to a static data-member list of parse tree node pointers.  And the
> virtual destructor of this base class removes itself from the list.
> Then if I have an error, then I just delete all the pointers in this
> list.
>
> Also, I once used to be really careful and in the destructor of every
> parse tree node I would be sure to also delete any child nodes.
> Otherwise I would have a mem leak... I've seens said 'screw that, I'll
> just maintain this list of pointers even after I've successfully parsed
> and use it to clean up'...

i really appreciate your responding, problem with linking all the objects in the
base class is that
some of the classes as you noted point to  instances of other classes which they
delete when they destruct. so if you have a parse error before the container
object is created you should deleted the objects individually on the other hand
if the container object has been constructed and then the parse error occurs
then you need only delete the container object and it would automatically delete
the instances of objects that it points to in this case you cant delete all the
objects that are linked up in the chain.

there may be other C++ ways of handling this, i was more hoping for something
from bison that let me examine the stack that its constructed and call
destructor on each of the values in the stack.

anyways thanks.






>
> So you see, I've just made a fail safe way of never forgetting to
> cleanup a single parse tree node.  Everytime a parse tree node is
> allocated, it adds itself to this list.  And, everytime I delete a parse
> tree node, it removes itself from this list...
>
> Does this help?
>
> --Davy
>
> On 07 Jun 2001 19:43:08 +0200, Hans Aberg wrote:
> ? At 11:13 -0400 2001/06/07, ashish sehgal wrote:
> ? ?When the bison generated parser encounters an error in the input
> ? ?expression and there is no error recovery grammar then the forrest of
> ? ?linked up structures that may have been created as part of parsing need
> ? ?to be cleaned up else every wrong input stream causes this memory to be
> ? ?allocated and not get deleted at all when the parser is working as part
> ? ?of another thread.
> ?
> ? Have you run out of punctuation marks at your company? -- They surely help
> ? the parsing. :-)
> ?
> ? But sure, if you can't take memory leaks, then garbage must somehow be
> ? collected.
> ?
> ? ?Is there some standard functionality available to do some cleanup
> ? ?associated with the values associated with bison's internal stack ?? for
> ? ?instance something that lets you iterate over all the
> ? ?values in the stack and delete them.
> ?
> ? I use C++ which does that cleanup automatically (if all used memory
> ? management is wrapped up in automatic objects). So I do not know.
> ?
> ? But I am not GNU, just a reader of this list. -- Perhaps somebody else can
> ? give a better answer.
> ?
> ?   Hans Aberg
> ?
> ?
> ?
> ? _______________________________________________
> ? Help-bison mailing list
> ? address@hidden
> ? http://mail.gnu.org/mailman/listinfo/help-bison




reply via email to

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