help-bison
[Top][All Lists]
Advanced

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

Re: Deallocations upon parse errors?


From: Roland Nilsson
Subject: Re: Deallocations upon parse errors?
Date: Tue, 16 Jan 2007 23:05:39 +0100

Ok, I'll try to find an more recent version. Thanks.

But in any case, does the yylval variable carry the value of the most
recent $$ variable? Or is this perhaps overwritten with each new token
scanned?

// Roland

2007/1/16, Hans Aberg <address@hidden>:
Pick down some later version of Bison (2.3+); then, if you use the C
parser, there is a %destructor command, that can be used to handle
clean-up during error recovery. Another way is to use a C++ parser,
and a semantic type that does cleanup via the C++ language, but one
cannot then use %union.

  Hans Aberg


On 15 Jan 2007, at 23:12, Roland Nilsson wrote:

> Hello,
>
> [apologies if this is a common question, I didn't find any FAQ for
> this list]
>
> I am using Bison (v1.24, a windows port I found on the web; I'm not on
> linux) for a simple command-line interpreter of my own experimental
> language. The parser actions are used to recursively build up a kind
> of syntax tree, so they allocate various objects along the way. This
> works fine, except when there are parse errors; in which case I need
> to intercept and deallocate whatever objects have been allocated so
> far, to avoid memory leaks.
>
> To do this cleanup I need to find the thing produced by the last
> reduction before the error. I first thought I could use yylval inside
> the yyerror() routine for this, but I constantly find that yylval is
> empty (null) when entering yyerror(). So how do I access the value of
> the last reduction (i.e. the last thing assigned to $$) ??
>
> By the way, yylval is null also after successful parsing. I thought
> this was strange too, from what I gathered from the Bison docs it
> should contain the $$ result at all the time? I got around that by
> inserting a "top level" rule that simply copies $$ to a different
> variable prior to accepting, but it seems like a weird work-around ...
> ?
>
> Thanks for any help!
>
> Best,
> Roland Nilsson
> Linköping, Sweden
>
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison






reply via email to

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