[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
%destructor is not compatible with YYSTYPE
From: |
Mike Ady |
Subject: |
%destructor is not compatible with YYSTYPE |
Date: |
Sun, 15 Feb 2004 14:03:41 -0700 |
Sirs,
I was suffering from memory leaks when parsing bad input. I added a
"%distructor" derective to my parser, but the resulting code would not
compile. (I am working in C, with the MSVC++ 6 compiler.) For example, I
added the following code:
%destructor { freetoken($$); } MYTOK_INTEGER ...
Then Bison generated the following destructor code for each token type I
specified:
freetoken(yyvaluep->(null));
That code is invalid and it caused my C compiler to issue an error message.
The problem appears to be that I was declaring the parser value data type
with YYSTYPE instead of with %union.
I first got my parser working by hacking the output .tab.c file, and
replacing the above code with
#define YYSTYPE struct mytok *
...
freetoken((YYSTYPE)*yyvaluep);
Then I discarded my YYSTYPE definition and switched to a %union directive.
That solved the problem (and no more memory leaks!).
I don't know if this is a bug or an undocumented feature/restriction. But
it looks like support for YYSTYPE was missed as an oversight.
Regards,
Mike Ady
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- %destructor is not compatible with YYSTYPE,
Mike Ady <=