help-bison
[Top][All Lists]
Advanced

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

Re: Token types with constructor


From: Hans Aberg
Subject: Re: Token types with constructor
Date: Thu, 2 Sep 2004 19:38:58 +0200

At 17:28 +0200 2004/09/02, Martin Trautmann wrote:
>I was totally blind. There is already an established solution in the
>productive version of bison...

What do you mean by "estblished solution".

> that allows using Token Classes with
>constructor. This works via yyoverflow and a solution of type "3a"
...
>Like this no memory should be left. The memory originally allocated by
>bison on the stack of yyparse is freed automatically calling
>destructors.
>And as I already described all other copying of Tokens uses the
>approriate operator=().

But you still need to make a C++ copy over when the stack re-allocates.
Check, for example, the suggestion by Wolfgang Wieser.

Before that, it is no solution at all, and certainly no "established" if
you by that mean supported.

But if you and Wolfgang Wieser want to work up a reliable compile C as C++
option, then report it in the Bug-Bison and/or Bison-Patches lists.

>...may
>be implemented as follows:
>
>#define yyoverflow handle_stack_overflow
>    namespace adlparser
>    {
>      short *parserstack_yyss = 0;
>      Token *parserstack_yyvs = 0;
>
>      void init_stack()
>      {
>        parserstack_yyss = 0;
>        parserstack_yyvs = 0;
>      }
>      void free_stack()
>      {
>        if( parserstack_yyss != 0 ) delete[] parserstack_yyss;
>        if( parserstack_yyvs != 0 ) delete[] parserstack_yyvs;
>        init_stack();
>      }
>      void handle_stack_overflow( char*, short ** yyss, size_t, Token
>**yyvs, size_t, size_t *yystacksize )
>      {
>        if( parserstack_yyss != 0 ) assert( *yyss == parserstack_yyss );
>        if( parserstack_yyvs != 0 ) assert( *yyvs == parserstack_yyvs );
>        size_t new_yystacksize = *yystacksize * 2;
>        short *new_yyss = new short[new_yystacksize];
>        Token *new_yyvs = new Token[new_yystacksize];
>        *yyss = new_yyss;
>        *yyvs = new_yyvs;
>        *yystacksize = new_yystacksize;
>        free_stack();
>        parserstack_yyss = new_yyss;
>        parserstack_yyvs = new_yyvs;
>      }
>%{
><rules>
>%}
>void parser_adl()
>{
>   init_stack();
>   yyparse();
>   free_stack();
>}
>
>Like this no memory should be left. The memory originally allocated by
>bison on the stack of yyparse is freed automatically calling
>destructors.
>And as I already described all other copying of Tokens uses the
>approriate operator=().
>
>bye
>
>Martin
>
>
>
>_______________________________________________
>address@hidden http://lists.gnu.org/mailman/listinfo/help-bison







reply via email to

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