Hi all,

I'm writing a parser which builds an AST for consumption by a compiler
backend. Actions for most productions need to preserve certain tokens'
values as part of the AST, but some productions involve tokens without
associated types, whose values don't figure into the AST.

My question is: do the actions for these productions need to
explicitly deallocate memory associated with the unused tokens? I
believe not, because:
o) the tokens don't have types, so they're just #define'd to integers,
o) which is why bison doesn't warn about unused tokens, and which implies
o) there's no memory to deallocate.

But I can't find a solid answer to this question online. If it
matters, this is a C++ parser and I'm using bison 3.0.2, gcc 4.8.4,
Linux 3.13.0.

Thanks
Will

An example:
============================================
%token <node> FORVALUES IDENT NUMBER STRING_LITERAL

%token
    LPAREN          "("
    RPAREN          ")"
    LBRACE          "{"
    RBRACE          "}"
    ASSIGN          "="
;

forvalues_cmd:
FORVALUES IDENT "=" NUMBER "(" NUMBER ")" NUMBER "{" STRING_LITERAL "}"
    {
        // do I need to free() or del tokens $3, $5, $7, $9 and $11?

        $1->appendChild("macro_name", $2);
        $1->appendChild("text", $10);

        $1->appendChild("upper", $8);
        $1->appendChild("lower", $4);
        $1->appendChild("increment", $6);

        $$ = $1;
    }

These

_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to