]> git.saurik.com Git - bison.git/blobdiff - data/yacc.c
* data/glr.cc: New.
[bison.git] / data / yacc.c
index 1a141108659772fd7e62f2f3344843e7e80b1423..7af81941efc0536908f8befd237c26931eff785d 100644 (file)
@@ -36,10 +36,10 @@ m4_define_default([b4_stack_depth_init],  [200])
 ## ------------------------ ##
 
 
-# b4_pure_if(IF-TRUE, IF-FALSE)
-# -----------------------------
+# b4_yacc_pure_if(IF-TRUE, IF-FALSE)
+# ----------------------------------
 # Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
-m4_define([b4_Pure_if],
+m4_define([b4_yacc_pure_if],
 [b4_pure_if([m4_ifset([b4_parse_param],
                       [$1], [$2])],
             [$2])])
@@ -49,7 +49,7 @@ m4_define([b4_Pure_if],
 # ---------------
 # Arguments passed to yyerror: user args plus yylloc.
 m4_define([b4_yyerror_args],
-[b4_Pure_if([b4_location_if([&yylloc, ])])dnl
+[b4_yacc_pure_if([b4_location_if([&yylloc, ])])dnl
 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
 
 
@@ -219,12 +219,25 @@ typedef struct YYLTYPE
 /* Line __line__ of yacc.c.  */
 b4_syncline([@oline@], [@ofile@])[
 
+/* Define YYMODERN_C if this compiler supports C89 or better.  If
+   __STDC__ is defined, the compiler is modern.  IBM xlc 7.0 when run
+   as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
+   reasons, but it defines __C99__FUNC__ so check that as well.
+   Consider a C++ compiler to be modern if it defines __cplusplus.  */
+#ifndef YYMODERN_C
+# if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus)
+#  define YYMODERN_C 1
+# else
+#  define YYMODERN_C 0
+# endif
+#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 +279,7 @@ b4_syncline([@oline@], [@ofile@])[
 #    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 +310,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 +390,7 @@ union yyalloc
 
 #endif
 
-#if defined (__STDC__) || defined (__cplusplus)
+#if YYMODERN_C
    typedef signed char yysigned_char;
 #else
    typedef short int yysigned_char;
@@ -618,15 +628,15 @@ do {                                              \
     YYFPRINTF Args;                            \
 } while (/*CONSTCOND*/ 0)
 
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)         \
-do {                                                           \
-  if (yydebug)                                                 \
-    {                                                          \
-      YYFPRINTF (stderr, "%s ", Title);                                \
-      yysymprint (stderr,                                      \
-                  Type, Value]b4_location_if([, Location])[);  \
-      YYFPRINTF (stderr, "\n");                                        \
-    }                                                          \
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                   \
+do {                                                                     \
+  if (yydebug)                                                           \
+    {                                                                    \
+      YYFPRINTF (stderr, "%s ", Title);                                          \
+      yysymprint (stderr,                                                \
+                  Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+      YYFPRINTF (stderr, "\n");                                                  \
+    }                                                                    \
 } while (/*CONSTCOND*/ 0)
 
 /*------------------------------------------------------------------.
@@ -711,7 +721,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 +745,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 +931,7 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
 /* 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 +969,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)
@@ -1336,7 +1346,8 @@ yyerrlab:
         }
       else
        {
-         yydestruct ("Error: discarding", yytoken, &yylval]b4_location_if([, &yylloc])[);
+         yydestruct ("Error: discarding",
+                      yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
          yychar = YYEMPTY;
        }
     }
@@ -1390,7 +1401,8 @@ yyerrlab1:
        YYABORT;
 
 ]b4_location_if([[      yyerror_range[0] = *yylsp;]])[
-      yydestruct ("Error: popping", yystos[yystate], yyvsp]b4_location_if([, yylsp])[);
+      yydestruct ("Error: popping",
+                  yystos[yystate], yyvsp]b4_location_if([, yylsp])[]b4_user_args[);
       YYPOPSTACK;
       yystate = *yyssp;
       YY_STACK_PRINT (yyss, yyssp);
@@ -1441,11 +1453,11 @@ yyexhaustedlab:
 yyreturn:
   if (yychar != YYEOF && yychar != YYEMPTY)
      yydestruct ("Cleanup: discarding lookahead",
-                yytoken, &yylval]b4_location_if([, &yylloc])[);
+                yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
   while (yyssp != yyss)
     {
       yydestruct ("Cleanup: popping",
-                 yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
+                 yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[]b4_user_args[);
       YYPOPSTACK;
     }
 #ifndef yyoverflow