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: David Durham
Subject: Re: [Fwd: question about error handling]
Date: Tue, 12 Jun 2001 12:58:29 -0500

Hi, perhaps I'm misunderstanding your message, but here goes again...

I'm sugguesting not to let the parse tree nodes be responsible for
deallocating their children.  Just maintain the global list of pointers
to the base class even after you are finished parsing.  When you want to
deallocate the parse tree, just delete all the parse tree nodes in the
list.  The parse tree nodes should not delete *ANY* instances of parse
tree nodes that are derived from this base class, because when they are
created they automatically add themselves to the list of pointers to
later be deallocated.   This does not mean that the destructors of the
parse tree nodes won't do anything.. I for instance sometimes allocate
memory which needs to be freed in the destructor.

(A note about C++ and destructors: someone correct me if I'm wrong...
All your destructors in this implementation MUST be virtual (actually I
always make my destructors virtual). And, You'll need to put at least an
empty implementation for all your parse tree nodes even if that
particular parse tree node doesn't need to do anything in its
destructor.  If you don't put even an empty implementation in the
derived class then the base class's destructor may not get called.) 

And of course it doesn't necessarily have to be global if it just
absolutely can't be... You'd just have to pass around a pointer to the
list you're wanting to add to all the time... Or, what I do, the list is
global while parsing, then when I'm done I copy that list into a local
list and destroy the global list.  Then if later parses occur the lists
are separate.

I can give further explaination if needed, but as far as I can tell, you
can still implement this solution... 

And I'm assuming that "linking all the objects in the base class", you
are referring to letting all the parse tree nodes be derived from a base
class (that is what I'm doing)

On 11 Jun 2001 15:04:14 -0400, ashish sehgal wrote:
> 
> 
> 
> 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.
> 
> 
> 
> 
> 
> 







reply via email to

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