Re: %union in Bison

basireddym@rediffmail.com (manohar)
25 Jan 2003 00:45:35 -0500

          From comp.compilers

Related articles
%union in Bison belgioioso@libero.it (Davide Rizzo) (2003-01-12)
Re: %union in Bison haberg@math.su.se (2003-01-17)
Re: %union in Bison j.rauser@science-factory.com (James Rauser) (2003-01-17)
Re: %union in Bison wicklund@eskimo.com (2003-01-17)
Re: %union in Bison basireddym@rediffmail.com (2003-01-25)
| List of all articles for this month |

From: basireddym@rediffmail.com (manohar)
Newsgroups: comp.compilers
Date: 25 Jan 2003 00:45:35 -0500
Organization: http://groups.google.com/
References: 03-01-048
Keywords: C++, yacc
Posted-Date: 25 Jan 2003 00:45:35 EST

"Davide Rizzo" <belgioioso@libero.it> wrote
> [ putting a C++ "string" type in a bison %union doesn't work]
> when I try to compile (Dev-C++ gcc compiler) I get a "member `class string
> {anonymous union}::str' with constructor not allowed in union" error. I
> suppose I can't use classes in unions, but I would like to be sure of that
> (or is it just a string particular mood?)
> thanx for your help, regards
> Davide
> reply at belgioioso@libero.it
> [Bison generates C code, not C++ code. -John]


hi friend,
                    As Bison doesn't support c++ string(which consists constructor),
the best way would be declare pointer to the string and do allocate memory
whereever needed.


declare YYSTYPE as
typedef union{
        string *str;
        int integer;
  } YYSTYPE;


bye,
mano


Post a followup to this message

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