[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bison-1.875: yyerror() declaration and C++ compilation error
From: |
Nelson H. F. Beebe |
Subject: |
bison-1.875: yyerror() declaration and C++ compilation error |
Date: |
Thu, 2 Jan 2003 19:10:03 -0700 (MST) |
After getting bison-1.875 installed on more than a dozen local systems
earlier today, I returned to work on a program that uses a yacc/bison
grammar. On most systems, I compile this C code using C++ compilers,
to obtain stricter type checking and wider compiler testing.
Unfortunately, the bison upgrade has introduced a problem: I now get
errors like this on every system:
% yacc --version
bison (GNU Bison) 1.875
...
% yacc -d hoc.y
% g++ ... -c hoc.c
y.tab.c: In function `int yyparse()':
y.tab.c:2628: `yyerror' undeclared (first use this function)
y.tab.c:2628: (Each undeclared identifier is reported only once for each
function it appears in.)
y.tab.c:2676: parse error before `goto'
hoc.y: In function `void yyerror(char*)':
hoc.y:1982: `void yyerror(char*)' used prior to declaration
A check of the bison manual shows that yyerror() is now expected to be
declared by the user: I don't see why that should be necessary since
bison itself generates calls to it, and thus should provide a suitable
prototype. That prototype will isolate user code from possible future
changes in yyerror()'s interface. [I note that the manual shows a
two-argument form for yyerror() when GLR parsing is selected; however,
when I inserted a %glr-parser directive, bison still produced the
one-argument form.]
So, I changed my grammar file to have in the preamble this prototype:
#if defined(YYBISON)
#define YYCONST const
void yyerror (YYCONST char *);
#endif /* defined(YYBISON) */
Compilation with gcc then succeeds, but compilation with g++ fails in
this code section:
yyerrlab1:
/* Suppress GCC warning that yyerrlab1 is unused when no action
invokes YYERROR. */
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 +
__GNUC_MINOR__)
__attribute__ ((__unused__))
#endif
goto yyerrlab2;
with the message "parse error before goto".
An additional check in the installed yacc.c file is needed:
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 +
__GNUC_MINOR__) && !define(__GNUG__)
but perhaps there is a cleaner way.
Incidentally, I view it a very bad idea to install bison under the
name yacc as well: that masks access to the native yacc when that may
be what the user intended. I hope that that change in bison will be
reconsidered. I routinely test my parsers with bison, (native) yacc,
and Berkeley yacc, so that I can ensure that my grammars work with all
of them. I'm strongly inclined to remove the installed
/usr/local/bin/yacc script on our systems.
Comments?
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- Center for Scientific Computing FAX: +1 801 581 4148 -
- University of Utah Internet e-mail: address@hidden -
- Department of Mathematics, 110 LCB address@hidden address@hidden -
- 155 S 1400 E RM 233 address@hidden -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe -
-------------------------------------------------------------------------------
- bison-1.875: yyerror() declaration and C++ compilation error,
Nelson H. F. Beebe <=