]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
* configure.ac (AC_ARG_ENABLE): Use -Wextra -Wno-sign-compare
[bison.git] / data / glr.c
index 45fb79e6a2d24f197311122deb8d39e3c4f780f7..7c3d998d29aadbf89b82638d1831a5f01d8d99dc 100644 (file)
@@ -159,28 +159,31 @@ m4_if(b4_prefix, [yy], [],
 #define yychar  b4_prefix[]char
 #define yydebug b4_prefix[]debug
 #define yynerrs b4_prefix[]nerrs
-#define yylloc  b4_prefix[]lloc])
+#define yylloc  b4_prefix[]lloc])[
+
+/* Copy the first part of user declarations.  */
+]b4_pre_prologue
 
 dnl # b4_shared_declarations
 dnl # ----------------------
 dnl # Declaration that might either go into the header (if --defines)
 dnl # or open coded in the parser body.
 m4_define([b4_shared_declarations],
-[b4_token_enums(b4_tokens)[
+[m4_ifdef([b4_start_header],
+[[/* Copy the %start-header blocks.  */
+]b4_start_header])[]dnl
 
-/* Copy the first part of user declarations.  */
-]b4_pre_prologue[
+b4_token_enums(b4_tokens)
 
-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+[#ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
-[typedef union b4_union_name
-b4_stype
-/* Line __line__ of glr.c.  */
-b4_syncline([@oline@], [@ofile@])
-       YYSTYPE;],
-[typedef int YYSTYPE;])[
-# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
+[[typedef union ]b4_union_name[
+]b4_user_stype[
+       YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1]],
+[m4_if(b4_tag_seen_flag, 0,
+[[typedef int YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1]])])[
 #endif
 
 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
@@ -198,7 +201,11 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_DECLARED 1
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
-]])
+
+]m4_ifdef([b4_end_header],
+[[/* Copy the %end-header blocks.  */
+]b4_end_header])[]dnl
+])
 
 b4_defines_if([#include @output_header_name@],
              [b4_shared_declarations])[
@@ -229,11 +236,8 @@ b4_defines_if([#include @output_header_name@],
 static YYSTYPE yyval_default;
 
 /* Copy the second part of user declarations.  */
-]b4_post_prologue[
+]b4_user_post_prologue[
 
-]/* Line __line__ of glr.c.  */
-b4_syncline([@oline@], [@ofile@])
-[
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -926,9 +930,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
 ]])[
   switch (yyn)
     {
-      ]b4_actions
-/* Line __line__ of glr.c.  */
-b4_syncline([@oline@], [@ofile@])[
+      ]b4_user_actions[
       default: break;
     }
 
@@ -2259,7 +2261,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
            }
        }
 ]b4_locations_if([[      yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
-      yydestroyGLRState ("Error: popping", yys]b4_user_args[);
+      if (yys->yypred != NULL)
+       yydestroyGLRState ("Error: popping", yys]b4_user_args[);
       yystackp->yytops.yystates[0] = yys->yypred;
       yystackp->yynextFree -= 1;
       yystackp->yyspaceLeft += 1;
@@ -2302,19 +2305,17 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
   yylval = yyval_default;
 ]b4_locations_if([
 #if YYLTYPE_IS_TRIVIAL
-  yylloc.first_line   = yylloc.last_line   = 1;
-  yylloc.first_column = yylloc.last_column = 0;
+  yylloc.first_line   = yylloc.last_line   = ]b4_location_initial_line[;
+  yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
 #endif
 ])
 m4_ifdef([b4_initial_action], [
 m4_pushdef([b4_at_dollar],     [yylloc])dnl
 m4_pushdef([b4_dollar_dollar], [yylval])dnl
   /* User initialization code.  */
-  b4_initial_action
+  b4_user_initial_action
 m4_popdef([b4_dollar_dollar])dnl
-m4_popdef([b4_at_dollar])dnl
-/* Line __line__ of glr.c.  */
-b4_syncline([@oline@], [@ofile@])])dnl
+m4_popdef([b4_at_dollar])])dnl
 [
   if (! yyinitGLRStack (yystackp, YYINITDEPTH))
     goto yyexhaustedlab;
@@ -2373,8 +2374,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
              if (yyisShiftAction (yyaction))
                {
                  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-                 if (yychar != YYEOF)
-                   yychar = YYEMPTY;
+                 yychar = YYEMPTY;
                  yyposn += 1;
                  yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
                  if (0 < yystack.yyerrState)
@@ -2490,7 +2490,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
   goto yyreturn;
 
  yyreturn:
-  if (yychar != YYEOF && yychar != YYEMPTY)
+  if (yychar != YYEMPTY)
     yydestruct ("Cleanup: discarding lookahead",
                YYTRANSLATE (yychar),
                &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
@@ -2512,7 +2512,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
                  {
                    yyGLRState *yys = yystates[yyk];
 ]b4_locations_if([[                yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[                 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
+)[                 if (yys->yypred != NULL)
+                     yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
                    yystates[yyk] = yys->yypred;
                    yystack.yynextFree -= 1;
                    yystack.yyspaceLeft += 1;