help-bison
[Top][All Lists]
Advanced

[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: Sat, 28 Aug 2004 20:52:47 +0200

Hi Laurence, hi Hans,

>From your discussion I know that you propose two ways of integrating
bison in a C++ framework. But I am not happy with both ways:

1) I would like to use a well supported parser template which works in
future versions of bison in the same way (It doesn't seem to me that the
bison team really stands behind the C++ extension)
2) I don't want to use new and delete in every rule (that is why I don't
like to use pointers to Objects)

What is the problem with the following code in the current bison
version:
class Token
{
  std::string str;
  int i;
};
#define YYSTYPE Token

The problem is that the token is stored within a union. 
Extract of yacc.c:
union yyalloc
{
  short yyss;
  YYSTYPE yyvs;
};

So there is a very easy fix for that problem that only costs two byte
per Token:
struct yyalloc
{
  short yyss;
  YYSTYPE yyvs;
};
  
What about changing this in future versions of bison or offering an
option within the official version to allow Token types with
constructors?

bye

Martin





reply via email to

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