[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bison-1.875: yyerror() declaration and C++ compilation error

From: Nelson H. F. Beebe
Subject: Re: bison-1.875: yyerror() declaration and C++ compilation error
Date: Fri, 3 Jan 2003 18:24:35 -0700 (MST)

Thanks, Paul, for the comments on the reasoning behind the lack of a
prototype for yyerror() in bison's output.

I've made some experiments today with this simplest yacc program:

% cat minprog.y

using bison (1.875), byacc (http://www.math.utah.edu/pub/byacc is its
home, since Bob Corbett no longer maintains it), and native yacc.

Here is what I found:

Parser          Platform                        yyerror declared?
bison           all                             no
byacc           all                             no

yacc            Compaq/DEC Alpha OSF/1 4.0F     no
yacc            HP/Compaq/DEC Alpha OSF/1 5.1   maybe: [extern "C"] void 
yyerror(char *);
                                                [see below]
yacc            IBM PowerPC AIX 4.2             yes: [extern "C"] void 
yyerror(char *)
                                                [C-style with stdio.h, 
C++-style with iostream.h]
yacc            SGI Origin 200 IRIX 6.5         yes: void yyerror(const char *)
yacc            Sun SPARC Solaris 2.[789]       C++: extern "C" void 
yyerror(YYCONST char *)

On OSF/1 5.1, the handling is complex:

        #ifdef __GNUC__
        #if !__STDC__
        #define YY_NOPROTO
        #endif /* __STDC__ */
        #elif !defined(__STDC__) &&  !defined (__cplusplus)
        #define YY_NOPROTO
        #endif /* __STDC__ */
        #ifndef YY_NOPROTO
        #if defined (__cplusplus)
        extern "C" {
        extern void yyerror(char *);
        extern int yylex();
        #else /* __cplusplus */
        extern int yylex(void);
        #endif /* __cplusplus */
        #if defined (__cplusplus)
        #endif /* __cplusplus */
        #endif /* YY_NOPROTO */

On Solaris, the extern "C" is inserted only if __EXTERN_C__ is also

The nuisance for C++ users with these variations is that private
definitions of yyerror need to know whether the const modifier is

Both C and C++ users need to know whether the prototype goes in the
grammar preamble (before the first %%), or the postamble (after the
second %%).  Regrettably, vendors have not been consistent about where
their prototypes get issued, and on at least one (IBM AIX), there are
uses of yyerror() in generated code before the prototype is seen.

Because of the uncertain positioning of any vendor-provided prototype
for yyerror, one cannot simply put

        #define yyerror private_yyerror

in the grammar preamble, since this could affect the vendor prototype

I've used assorted configure.in tests to deal with this, since my code
needs to work under both C and C++ compilers, and with byacc, bison,
and yacc, but it is still a nasty mess.

- 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  -

reply via email to

[Prev in Thread] Current Thread [Next in Thread]