By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Bison: Problem with %union

P: 1
Hi! I've included some of my classes in the union in my grammar file:
Expand|Select|Wrap|Line Numbers
  1. %union
  2. {
  3.     int int_type;
  4.     char* string_type;
  5.     PNode* pNode;
  6. }
  7.  
  8. %type <int_type>     programs 
  9. %type <pNode>           program
  10.  
Using 'Bison -d program.ypp', what happens is Bison places this in both .hpp and .cpp generated files as
Expand|Select|Wrap|Line Numbers
  1. typedef union YYSTYPE {
  2.     int int_type;
  3.     char* string_type;
  4.     PNode* pNode;
  5. } YYSTYPE;
  6.  
The problem is the .hpp file doesn't have the #include "PNode.h" that it needs to make sense of PNode* so it produces errors. When I try to put #include "PNode.h" in the .hpp file I get a hundred errors like this:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'

Removing this part from the the .hpp file will also produce errors.

I'm using VS2003, Bison 2.1 and Flex 2.5.4a. I hope someone can help me with this. Thanks.
Sep 7 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
The problem is the .hpp file doesn't have the #include "PNode.h" that it needs to make sense of PNode* so it produces errors. When I try to put #include "PNode.h" in the .hpp file I get a hundred errors like this:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
You can use a forward reference:
Expand|Select|Wrap|Line Numbers
  1. class PNode;           //forward reference
  2. typedef union YYSTYPE {
  3.     int int_type;
  4.     char* string_type;
  5.     PNode* pNode;
  6. } YYSTYPE;
  7.  
This is enough informattion for the compiler to allow a PNode* variable.

As to theVisual Studio errors, I would need to se your PNode.h and also to see where you included it. That is, before or after the incluce to cstdio.

Typically errors like this are caused by a) a missing semi-colon after a class/struct/union declaration or b) failing to have a null line as the last line of the header file.
Sep 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.