[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Deallocations upon parse errors?
From: |
Roland Nilsson |
Subject: |
Deallocations upon parse errors? |
Date: |
Mon, 15 Jan 2007 23:12:34 +0100 |
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
- Deallocations upon parse errors?,
Roland Nilsson <=