> On 18 Aug 2016, at 01:20, Min Wang <mingew...@gmail.com> wrote:
> so if I have something like that ( pointer) in as token type: > > %type <PROG*> PROG > > %type <ListExp*> ListExp > > My thinking about using PROG* instead of PROG is because I do not want to > copy constructor a big PROG, is it correct? > > In this case of pointer, do I need to have a %destructor? > > %destructor { delete $$; } PROG > %destructor { delete $$; } ListExp Yes, if your pointers have explicit allocators in the actions, then if you want to avoid memory leaks during error recovery, the corresponding deallocator should be called as you indicate. > (2) when %destructor is called? > > Assuming I need those %destructor, it seems that %destructor was called > even for a every successful parse. I thought it should only called during > During error recovery. It is called only during error recovery. For a normal parse, without errors, the corresponding deallocator should be in the actions. So you need to keep track in the grammar of where an object becomes obsolete. So if your program is not doing much of error recovery, some memory leaks during that process might be acceptable. _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison