Related articles |
---|
Help with bison drewpvogel@gmail.com (2007-07-26) |
Re: Help with bison gene.ressler@gmail.com (Gene) (2007-07-26) |
Re: Help with bison stephenhorne100@aol.com (Steve Horne) (2007-07-27) |
From: | drewpvogel@gmail.com |
Newsgroups: | comp.compilers |
Date: | Thu, 26 Jul 2007 09:40:31 -0700 |
Organization: | Compilers Central |
Keywords: | parse, yacc, question |
Posted-Date: | 26 Jul 2007 23:19:50 EDT |
I am trying to learn how to use bison/flex. I found a book online
titled "Compiler Construction using Flex and Bison" by Anthony A.
Aaby. It is helpful and easy to read but I am having trouble compiling
the sample compiler he provides. I copy/pasted the code from the back
of the book but bison seems to generate illegitimate C code.
The pertinent portion of Simple.y is:
%union semrec /* The Semantic
Records */
{
int intval; /* Integer
values */
char *id; /*
Identifiers */
struct lbs *lbls; /* For
backpatching */
}
It generates this C code in Simple.tab.c:
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 57 "Simple.y"
semrec /* The Semantic Records */
{
int intval; /* Integer
values */
char *id; /*
Identifiers */
struct lbs *lbls; /* For
backpatching */
}
/* Line 187 of yacc.c. */
#line 196 "Simple.tab.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
The problem is in this portion:
typedef union YYSTYPE
#line 57 "Simple.y"
semrec /* The Semantic Records */
{
gcc gives this error:
Simple.y:58: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '{' token
If I change "typedef union YYSTYPE" to "typedef union" in Simple.tab.c
and Simple.tab.h the code compiles and works as expected. Why is bison
trying to typedef a union to the same name? I don't think this is a
bug in bison because it exists in version 2.3 and 1.85 (the latest
version available when the book was published).
Drew Vogel
"Compiler Construction using Flex and Bison" by Anthony A. Aaby:
http://tinyurl.com/yv65ye
Return to the
comp.compilers page.
Search the
comp.compilers archives again.