Re: Initialise tokens in bison/flex

haberg@matematik.su.se (Hans Aberg)
11 Mar 2002 02:09:38 -0500

          From comp.compilers

Related articles
Initialise tokens in bison/flex rupp@fzi.de (Torsten Rupp) (2002-03-09)
Re: Initialise tokens in bison/flex haberg@matematik.su.se (2002-03-11)
Re: Initialise tokens in bison/flex {spamtrap}@qeng-ho.org (Maneki Neko) (2002-03-17)
Re: Initialise tokens in bison/flex clint@0lsen.net (Clint Olsen) (2002-03-17)
Re: Initialise tokens in bison/flex chrisd@reservoir.com (2002-03-17)
| List of all articles for this month |

From: haberg@matematik.su.se (Hans Aberg)
Newsgroups: comp.compilers
Date: 11 Mar 2002 02:09:38 -0500
Organization: Mathematics
References: 02-03-046
Keywords: yacc, lex
Posted-Date: 11 Mar 2002 02:09:37 EST

Torsten Rupp <rupp@fzi.de> wrote:
>Does anybody know how I can handle resource allocation/free resources
>in tokens for bison/flex?
...
>[lex, yacc, and their variants don't handle this very well, particularly
>if you try to do error recovery. My usual approach is to chain all the
>allocated storage together, then zip through after each parse and give
>it all back. -John]


As John Levine says, Bison/Flex do not handle this well under C:


So my approach is to use C++. The current Bison (1.33-1.34) generated
parser compiles well under C, but its dynamic stack uses raw memory
copying (memcpy) alone, and thus does not invoke any C++ copy-constructors
when re-allocating the stack. You can get around this by allocating as
much static stack that the dynamic stack is never invoked.


The right fix is to use proper C++ containers for stack (like std::deque,
etc.). I wrote my own skeleton file and Bison tweaks doing just that.


The Bison development team (Akim Demaille) says that soon (one month or
so), they will have their own proper Bison C++ support. (But there may be
delays on this.)


    Hans Aberg * Email: Hans Aberg <haberg@member.ams.org>
                                    * Home Page: <http://www.matematik.su.se/~haberg/>
                                    * AMS member listing: <http://www.ams.org/cml/>


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.