help-bison
[Top][All Lists]
Advanced

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

How to correctly deallocate some token types ...


From: Ricardo Rafael
Subject: How to correctly deallocate some token types ...
Date: Mon, 12 May 2003 00:27:31 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312

Hi,

      given the following declarations:


%union
{
   BOOL        boolean_val;
   int         integer_val;
   char      * string_val;
   SomeClass * action;

   struct
   {
     SomeClass * items;
     int         length;
   } n_list;

   struct expression
   {
     SomeClass * a,
               * b,
               * c;
   } expression;
} // YYSTYPE

/* These come (allocated) from Flex ... */
%type <boolean_val> BOOLEAN_TOKEN
%type <integer_val> INTEGER_TOKEN
%type <string_val>  STRING_TOKEN

/* These are allocated and used in/by Bison ... */
%type <action>      program stmt ...
%type <n_list>      arg_list
%type <expression>  expr

/* Bison destructors ( current syntax ) ... */
%destructor { free( $$ ); } STRING_TOKEN

/* Test is taken because some rules can be NULL! */
%destructor { if ( $$ ) delete $$; } program stmt ...

%destructor { delete $$; } arg_list
%destructor { delete $$; } expr

   I have the following questions:

      a) Should I care to deallocate BOOLEAN_TOKEN and INTEGER_TOKEN?
b) Do I need to deallocate anything else in case of non-terminals: <arg_list> and <expr>?


P.S.: I use free() for STRING_TOKEN because I use malloc() in Flex. I use delete for the other because I use new SomeClass() elsewhere.


Sincerely,

Ricardo Rafael.





reply via email to

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