[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %union errors
From: |
Laurence Finston |
Subject: |
Re: %union errors |
Date: |
Mon, 8 Dec 2008 10:24:04 +0100 (CET) |
On Fri, 5 Dec 2008, Benny Hardage wrote:
> %union
> {
> int intVal;
> bool boolVal;
> char* strVal;
> std::list<const Variable::Qualifier*>* qList;
> Variable* var;
> UnaryOperation* uop;
> BinaryOperation* binop;
> Expression* expr;
> DataLiteral* datalit;
> }
>
I had a problem trying to use types defined in the STL in the `%union'.
I don't remember the details, but I believe it involved types where the
size isn't known at compile-time not being permitted in unions. I think
there was something about constructors as well. I believe this is
documented in the section about unions in Stroustrup's _The C++ Programming
Language_. At any rate, I couldn't get it to work.
My unions for Bison usually contain an `int', a `float', a `char' vector, and
a `void*' for everything else. `void*' as `YYSTYPE' would do the trick,
but I find it convenient to have semantic values of the other types
without having to use casts.
Laurence Finston
On Fri, 5 Dec 2008, Benny Hardage wrote:
> Hello,
>
> I'm receiving the following errors when I compile:
>
> In file included from compiler.l:17:
> parser.y:27: error: ISO C++ forbids declaration of 'list' with no type
> parser.y:27: error: invalid use of '::'
> parser.y:27: error: expected ';' before '<' token
> parser.y:28: error: ISO C++ forbids declaration of 'Variable' with no type
> parser.y:28: error: expected ';' before '*' token
> parser.y:29: error: ISO C++ forbids declaration of 'UnaryOperation' with no
> type
> parser.y:29: error: expected ';' before '*' token
> parser.y:30: error: ISO C++ forbids declaration of 'BinaryOperation'
> with no type
> parser.y:30: error: expected ';' before '*' token
> parser.y:31: error: ISO C++ forbids declaration of 'Expression' with no type
> parser.y:31: error: expected ';' before '*' token
> parser.y:32: error: ISO C++ forbids declaration of 'DataLiteral' with no type
> parser.y:32: error: expected ';' before '*' token
>
> I've seen a fairly old thread that attempted to address this issue,
> saying that my include files might not be in the right order, but the
> top of my file looks like the following:
>
> %error-verbose
>
> %{
>
> int yylex();
>
> #include <iostream>
> #include "expressions.hpp"
> #include "statements.hpp"
>
> extern bool outputTokens;
> extern bool outputParser;
>
> void yyerror( char* msg )
> {
> std::cerr << msg << std::endl;
> }
>
> %}
>
> %union
> {
> int intVal;
> bool boolVal;
> char* strVal;
> std::list<const Variable::Qualifier*>* qList;
> Variable* var;
> UnaryOperation* uop;
> BinaryOperation* binop;
> Expression* expr;
> DataLiteral* datalit;
> }
>
> expressions.hpp contains the datatypes in question.
>
> I was wondering if someone might let me know what I was doing wrong.
>
> Thanks,
> B.J.
>
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>