"John P. Hartmann" <[EMAIL PROTECTED]> writes: > CC=xlc make bison build, but I see a couple of problems in compiling: > > "scan-gram.c", line 2332.49: 1506-010 (E) Macro gram_wrap invoked with a null > argument for parameter n.
Thanks for reporting all these problems. This first diagnostic is due to a bug in the flex version we used to generate Bison 2.1; see <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. I assume the workaround at the end of this message will fix things for you. > The calc++ example generates massive amounts of ld warnings about duplicate > symbols and a couple of errors. > > Here are the first few warnings. > > xlC_r -g -o calc++ calc++-scanner.o calc++.o calc++-driver.o > calc++-parser.o > ld: 0711-224 WARNING: Duplicate symbol: .std::basic_string > <char,std::char_traits<char>,std::allocator<char> >::basic_string(const char*) I don't know what a warning like that means. Perhaps a C++ expert can comment. If they're just warnings I guess we can live with them until someone can tell us how to fix them. > ld: 0711-317 ERROR: Undefined symbol: yy::position::initial_line > ld: 0711-317 ERROR: Undefined symbol: yy::position::initial_column This sounds like some sort of C++ incompatibility. The simplest fix is to remove those symbols. I installed the following patch in an attempt to accomplish this. Perhaps a C++ expert could do better. > However it is frustrating that Bison generates a parser that > compiles with prototypes disabled, even though the compiler > presumably supports prototypes well. If you can suggest a > better approach (maybe 'cc' supports another predefined macro?) > I'm all ears. I looked at the IBM documentation, and it seems to claim that cc defines __STDC_VERSION__. It can't hurt to check for that as well, so I installed the following patch. Does this patch fix your problems? 2005-10-10 Paul Eggert <[EMAIL PROTECTED]> Work around portability problems with Visual Age C compiler (xlc and xlC_r) reported by John P. Hartmann. * data/location.cc (initial_column, initial_line): Remove. All uses replaced by 0 and 1. * src/scan-gram.l (gram_wrap): Redefine to avoid bug in flex 2.5.31 that xlc complains about. * src/scan-skel.l (skel_wrap): Likewise. * data/c.m4 (b4_c_function_def): Look at __STDC_VERSION__ as well as __STDC__, as IBM cc defines the former but not the latter. * data/yacc.c (YYMODERN_C): New macro, which also looks at __STDC_VERSION__. Use it everywhere instead of looking at __STDC__ and __cplusplus. --- data/location.cc 2 Oct 2005 18:17:23 -0000 1.1 +++ data/location.cc 11 Oct 2005 05:05:44 -0000 @@ -43,20 +43,14 @@ namespace yy /// Abstract a position. class position { - public: - /// Initial column number. - static const unsigned int initial_column = 0; - /// Initial line number. - static const unsigned int initial_line = 1; - /** \name Ctor & dtor. ** \{ */ public: /// Construct a position. position () : filename (0), - line (initial_line), - column (initial_column) + line (1), + column (0) { } /** \} */ @@ -68,19 +62,19 @@ namespace yy /// (line related) Advance to the COUNT next lines. inline void lines (int count = 1) { - column = initial_column; + column = 0; line += count; } /// (column related) Advance to the COUNT next columns. inline void columns (int count = 1) { - int leftmost = initial_column; + int leftmost = 0; int current = column; if (leftmost <= current + count) column += count; else - column = initial_column; + column = 0; } /** \} */ --- src/scan-gram.l 2 Oct 2005 18:49:15 -0000 1.76 +++ src/scan-gram.l 11 Oct 2005 05:05:44 -0000 @@ -24,6 +24,11 @@ %option prefix="gram_" outfile="lex.yy.c" %{ +/* Work around a bug in flex 2.5.31. See Debian bug 333231 + <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */ +#undef gram_wrap +#define gram_wrap() 1 + #include "system.h" #include <mbswidth.h> --- src/scan-skel.l 2 Oct 2005 17:44:49 -0000 1.34 +++ src/scan-skel.l 11 Oct 2005 05:05:44 -0000 @@ -23,6 +23,11 @@ %option prefix="skel_" outfile="lex.yy.c" %{ +/* Work around a bug in flex 2.5.31. See Debian bug 333231 + <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */ +#undef skel_wrap +#define skel_wrap() 1 + #include "system.h" #include <error.h> --- data/c.m4 6 Oct 2005 07:17:21 -0000 1.36 +++ data/c.m4 11 Oct 2005 05:32:15 -0000 @@ -232,7 +232,7 @@ m4_define([b4_token_enums_defines], # ---------------------------------------------------------- # Declare the function NAME. m4_define([b4_c_function_def], -[#if defined (__STDC__) || defined (__cplusplus) +[#if defined (__STDC__) || defined (__STDC_VERSION__) || defined (__cplusplus) b4_c_ansi_function_def($@) #else $2 --- data/yacc.c 6 Oct 2005 07:17:21 -0000 1.113 +++ data/yacc.c 11 Oct 2005 05:32:15 -0000 @@ -219,12 +219,23 @@ typedef struct YYLTYPE /* Line __line__ of yacc.c. */ b4_syncline([EMAIL PROTECTED]@], [EMAIL PROTECTED]@])[ +/* Define YYMODERN_C if this compiler supports C89 or better. Some + modern compilers (e.g., IBM xlc 7.0) don't define __STDC__ for + pedantic reasons, but they define __STDC_VERSION__ so check that + as well. Consider a C++ compiler to be modern if it defines + __cplusplus. */ +#if defined (__STDC__) || defined (__STDC_VERSION__) || defined (__cplusplus) +# define YYMODERN_C 1 +#else +# define YYMODERN_C 0 +#endif + #ifndef YYSIZE_T # if defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ # elif defined (size_t) # define YYSIZE_T size_t -# elif ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus)) +# elif ! defined (YYSIZE_T) && YYMODERN_C # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -266,8 +277,7 @@ b4_syncline([EMAIL PROTECTED]@], [EMAIL PROTECTED]@])[ # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if (! defined (_ALLOCA_H) && ! defined (_STDLIB_H) \ - && (defined (__STDC__) || defined (__cplusplus))) +# if ! defined (_ALLOCA_H) && ! defined (_STDLIB_H) && YYMODERN_C # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 @@ -298,15 +308,13 @@ extern "C" { # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if (! defined (malloc) && ! defined (_STDLIB_H) \ - && (defined (__STDC__) || defined (__cplusplus))) +# if ! defined (malloc) && ! defined (_STDLIB_H) && YYMODERN_C void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if (! defined (free) && ! defined (_STDLIB_H) \ - && (defined (__STDC__) || defined (__cplusplus))) +# if ! defined (free) && ! defined (_STDLIB_H) && YYMODERN_C void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif @@ -380,7 +388,7 @@ union yyalloc #endif -#if defined (__STDC__) || defined (__cplusplus) +#if YYMODERN_C typedef signed char yysigned_char; #else typedef short int yysigned_char; @@ -711,7 +719,7 @@ int yydebug; # else /* Return the length of YYSTR. */ static YYSIZE_T -# if defined (__STDC__) || defined (__cplusplus) +# if YYMODERN_C yystrlen (const char *yystr) # else yystrlen (yystr) @@ -735,7 +743,7 @@ yystrlen (yystr) /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * -# if defined (__STDC__) || defined (__cplusplus) +# if YYMODERN_C yystpcpy (char *yydest, const char *yysrc) # else yystpcpy (yydest, yysrc) @@ -921,7 +929,7 @@ yysyntax_error (char *yyresult, int yyst /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) +# if YYMODERN_C int yyparse (void *YYPARSE_PARAM); # else int yyparse (); @@ -959,7 +967,7 @@ b4_pure_if([], `----------*/ #ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) +# if YYMODERN_C int yyparse (void *YYPARSE_PARAM) # else int yyparse (YYPARSE_PARAM)
