[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
%destructor questions
From: |
Bill Fenlason |
Subject: |
%destructor questions |
Date: |
Mon, 25 Oct 2004 11:48:36 -0400 |
I'm trying to understand how %destructor works. Can someone help?
I have the following union:
%union {
TokenNode terminal;
NonTerminalNode syntax; }
My scanner returns a TokenNode struct pointer rather than a simple character
string. Both my TokenNode struct and my NonTerminalNode struct need to be
processed if they are popped off the stack during error processing.
My terminals (several hundred) are defined like this:
%token <terminal> EQUAL "Equal Sign"
%token <terminal> PLUS "Plus Sign"
My non-terminals (several hundred) are defined like this:
%type <syntax> Ident
%type <syntax> IfStmt
I tried adding the following:
%destructor { ; /* T Destructor code */; } EQUAL PLUS
%destructor { ; /* NT Destructor code */; } Ident IfStmt
The following snip is some code generated for the yydestruct routine (using
the cygwin 1.875b version of BISON):
static void
yydestruct (yytype, yyvaluep)
int yytype;
YYSTYPE *yyvaluep;
#endif
{
/* Pacify ``unused variable'' warnings. */
(void) yyvaluep;
switch (yytype)
{
case 359: /* IfStmt */
{ ; /* NT Destructor code */; };
break;
case 540: /* Ident */
{ ; /* NT Destructor code */; };
break;
default:
break;
}
}
First, am I doing anything obviously wrong, or missing the point of
%destructor?
Next, it appears to me that terminal symbol structures are not being
processed. Is this intentional?
Or, was this fixed in a version later than 1.875b?
Finally (and most important), is there a way to specify a user version of
yydestruct? Or at least the default case of the switch statement?
The problem is that with the current syntax, %destructor statements with
well over a thousand names must be coded - not a small task in itself. But
worse, a huge, unnecessary switch statement will be generated, and over a
thousand copies of the same destructor code will be generated and compiled.
One simple solution might be to allow a %destructor statement without any
symbols, and use the provided code as the switch default.
Of course, I may not fully understand the situation - hopefully a developer
or knowledgeable user will explain this for me.
Thank you for your help.
Bill Fenlason
- %destructor questions,
Bill Fenlason <=