Re: Question about token stack

Ervin Hegedüs <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Hi Akim

many thanks for your answer.

On Sun, Aug 30, 2020 at 03:43:54PM +0200, Akim Demaille wrote:
> Hi Ervin,
> 
> > Le 30 août 2020 à 11:44, Ervin Hegedüs <[email protected]> a écrit :
> > 
> > How can I avoid this situation? Is that any "best-practice"? How
> > can I access to pointers in stack to free them when error
> > occurred?
> 
> I have not read all in details, but I believe you need to read
> about %destructor.
> 
> https://www.gnu.org/software/bison/manual/html_node/Destructor-Decl.html

looks like that's what I need - but for some reason that didn't
triggered in any case of error.

I just put:

%destructor { printf("free() called\n"); free ($$); } <*>

but it never called, and valgrind still shows that the block is
still reachable.

Btw I reviewed the generated code, but I'm afriad this destructor
called only when the parser run into the error state.

Now I thought what happens if the scanner found an unrecognized
token after the previous was pushed into stack - that item is
sill at there. So I'm still curious, how can I clear the whole
stack.


Thanks again,


a.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.