help-bison
[Top][All Lists]
Advanced

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

When to free RHS tokens?


From: William Brannon
Subject: When to free RHS tokens?
Date: Mon, 26 Dec 2016 18:48:18 -0500

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



reply via email to

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