[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Token types with constructor
From: |
Martin Trautmann |
Subject: |
Re: Token types with constructor |
Date: |
Thu, 02 Sep 2004 17:28:27 +0200 |
Hi,
I was totally blind. There is already an established solution in the
productive version of bison that allows using Token Classes with
constructor. This works via yyoverflow and a solution of type "3a" 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
- Re: Token types with constructor, Martin Trautmann, 2004/09/01
- Re: Token types with constructor, Akim Demaille, 2004/09/03
- Re: Token types with constructor, Hans Aberg, 2004/09/04
- Re: Token types with constructor, Akim Demaille, 2004/09/13
- Re: Token types with constructor, Hans Aberg, 2004/09/13
- Re: Token types with constructor, Akim Demaille, 2004/09/14
- Re: Token types with constructor, Hans Aberg, 2004/09/14
Re: Token types with constructor, Wolfgang Wieser, 2004/09/03