]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
Add src/system.h; this isn't really needed, but it keeps "make update"
[bison.git] / data / glr.c
index 6a18bcb92da9502083c796b11c764725e49d213f..a8d4aa2401d42c4c0204c93040e57a56f2528e40 100644 (file)
@@ -54,9 +54,25 @@ m4_define([b4_user_formals],
 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
 
 
+# b4_yyerror_args
+# ---------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_yyerror_args],
+[b4_pure_if([b4_location_if([yylocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
+# b4_lyyerror_args
+# ----------------
+# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
+m4_define([b4_lyyerror_args],
+[b4_pure_if([b4_location_if([yyllocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
 # b4_pure_args
 # ------------
-# Arguments passed to yyerror: user args plus yylloc.
+# Arguments needed by yyerror: user args plus yylloc.
 m4_define([b4_pure_args],
 [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
 
@@ -99,7 +115,7 @@ m4_define([b4_lhs_value],
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[yyvsp@<:@m4_eval([$2 - $1])@:>@.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])])
+[yyvsp@{m4_eval([$2 - $1])@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])])
 
 
 
@@ -119,38 +135,13 @@ m4_define([b4_lhs_location],
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[yyvsp@<:@m4_eval([$2 - $1])@:>@.yystate.yyloc])
-
-
-
-## ------------------- ##
-## Output file names.  ##
-## ------------------- ##
-
-m4_define_default([b4_input_suffix], [.y])
-
-m4_define_default([b4_output_parser_suffix],
-[m4_translit(b4_input_suffix, [yY], [cC])])
-
-m4_define_default([b4_output_parser_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]])
-
-
-m4_define_default([b4_output_header_suffix],
-[m4_translit(b4_input_suffix, [yY], [hH])])
-
-m4_define_default([b4_output_header_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]])
-
-m4_define_default([b4_header_guard],
-                  [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name),
-                                [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
+[yyvsp@{m4_eval([$2 - $1])@}.yystate.yyloc])
 
 
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
-#output "b4_output_parser_name"
+@output @output_parser_name@
 b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
 [
 /* This is the parser code for GLR (Generalized LR) parser. */
@@ -195,10 +186,10 @@ b4_pre_prologue[
 
 #ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"],
+b4_syncline([@oline@], [@ofile@])],
 [typedef int yystype;])[
 # define YYSTYPE yystype
 # define YYSTYPE_IS_TRIVIAL 1
@@ -218,7 +209,7 @@ typedef struct yyltype
 
 /* Default (constant) values used for initialization for null
    right-hand sides.  Unlike the standard bison.simple template,
-   here we set the default values of the $$ and $@ to zeroed-out
+   here we set the default values of $$ and $@@ to zeroed-out
    values.  Since the default value of these quantities is undefined,
    this behavior is technically correct. */
 static YYSTYPE yyval_default;
@@ -228,7 +219,7 @@ static YYLTYPE yyloc_default;
 ]b4_post_prologue[
 
 ]/* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"
+b4_syncline([@oline@], [@ofile@])
 [
 #if ! defined (__cplusplus)
    typedef char bool;
@@ -581,7 +572,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...)
       va_start (yyap, yyformat);
       yystack->yyerrflag = 1;
       vsprintf (yymsg, yyformat, yyap);
-      yyerror (yymsg]b4_pure_args[);
+      yyerror (]b4_yyerror_args[yymsg);
     }
   longjmp (yystack->yyexception_buffer, 1);
 }
@@ -599,7 +590,7 @@ yytokenName (yySymbol yytoken)
 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
  *  and top stack item YYVSP.  YYLVALP points to place to put semantic
  *  value ($$), and yylocp points to place for location information
- *  (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
+ *  (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
  *  yyerr for YYERROR, yyabort for YYABORT. */
 static YYRESULTTAG
 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
@@ -636,7 +627,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
 # undef YYBACKUP
 # define YYBACKUP(Token, Value)                                                     \
   do {                                                                      \
-    yyerror ("syntax error: cannot back up"]b4_pure_args[);                 \
+    yyerror (]b4_yyerror_args["syntax error: cannot back up");              \
     YYERROR;                                                                \
   } while (0)
 
@@ -656,7 +647,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
 # undef yyclearin
 # undef YYRECOVERING
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"
+b4_syncline([@oline@], [@ofile@])
 }
 \f
 
@@ -691,12 +682,17 @@ yylhsNonterm (yyRuleNum yyrule)
   return yyr1[yyrule];
 }
 
+#define yyis_pact_ninf(yystate) \
+  ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
+        0,
+        ((yystate) == YYPACT_NINF))[
+
 /** True iff LR state STATE has only a default reduction (regardless
  *  of token). */
 static inline bool
 yyisDefaultedState (yyStateNum yystate)
 {
-  return yypact[yystate] == YYPACT_NINF;
+  return yyis_pact_ninf (yypact[yystate]);
 }
 
 /** The default reduction for STATE, assuming it has one. */
@@ -706,6 +702,11 @@ yydefaultAction (yyStateNum yystate)
   return yydefact[yystate];
 }
 
+#define yyis_table_ninf(yyindex) \
+  ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
+        0,
+        ((yyindex) == YYTABLE_NINF))[
+
 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
  *  Result R means
  *    R < 0:  Reduce on rule -R.
@@ -724,7 +725,7 @@ yygetLRActions (yyStateNum yystate, int yytoken,
       *yyaction = -yydefact[yystate];
       *yyconflicts = yyconfl;
     }
-  else if (yytable[yyindex] != YYTABLE_NINF)
+  else if (! yyis_table_ninf (yyindex))
     {
       *yyaction = yytable[yyindex];
       *yyconflicts = yyconfl + yyconflp[yyindex];
@@ -1591,12 +1592,12 @@ yyreportParseError (yyGLRStack* yystack,
                    yyprefix = " or ";
                  }
            }
-         yyerror (yymsg]b4_lpure_args[);
+         yyerror (]b4_lyyerror_args[yymsg);
          free (yymsg);
        }
       else
 #endif
-       yyerror ("parse error"]b4_lpure_args[);
+       yyerror (]b4_lyyerror_args["parse error");
       yynerrs += 1;
     }
 }
@@ -1629,7 +1630,7 @@ yyrecoverParseError (yyGLRStack* yystack,
        *yytokenp = YYTRANSLATE (yychar);
        YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp)));
        yyj = yypact[yystack->yytops.yystates[0]->yylrState];
-       if (yyj == YYPACT_NINF)
+       if (yyis_pact_ninf (yyj))
          /* Something's not right; we shouldn't be here.  */
          yyFail (yystack][]b4_lpure_args[, NULL);
        yyj += *yytokenp;
@@ -1638,7 +1639,7 @@ yyrecoverParseError (yyGLRStack* yystack,
            if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
              return;
          }
-       else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF)
+       else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
          return;
       }
 
@@ -1656,14 +1657,18 @@ yyrecoverParseError (yyGLRStack* yystack,
   /* Now pop stack until we find a state that shifts the error token. */
   while (yystack->yytops.yystates[0] != NULL)
     {
-      yyj = yypact[yystack->yytops.yystates[0]->yylrState] + YYTERROR;
-      if (yyj != YYPACT_NINF + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
-         yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))
+      yyj = yypact[yystack->yytops.yystates[0]->yylrState];
+      if (! yyis_pact_ninf (yyj))
        {
-         yyglrShift (yystack, 0, yytable[yyj],
-                     yystack->yytops.yystates[0]->yyposn,
-                     *yylvalp, yyllocp]b4_user_args[);
-         break;
+         yyj += YYTERROR;
+         if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
+             && yyisShiftAction (yytable[yyj]))
+           {
+             yyglrShift (yystack, 0, yytable[yyj],
+                         yystack->yytops.yystates[0]->yyposn,
+                         *yylvalp, yyllocp]b4_user_args[);
+             break;
+           }
        }
       yystack->yytops.yystates[0] = yystack->yytops.yystates[0]->yypred;
       yystack->yynextFree -= 1;
@@ -1837,7 +1842,7 @@ yy_yypstack (yyGLRState* yys)
       yy_yypstack (yys->yypred);
       fprintf (stderr, " -> ");
     }
-  fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long) yys->yyposn);
+  fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long) yys->yyposn);
 }
 
 static void
@@ -1897,21 +1902,20 @@ yypdumpstack (yyGLRStack* yystack)
 
 b4_epilogue
 m4_if(b4_defines_flag, 0, [],
-[#output "b4_output_header_name"
+[@output @output_header_name@
 b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
-#ifndef b4_header_guard
-# define b4_header_guard
 
 b4_token_defines(b4_tokens)
 
 #ifndef YYSTYPE
 m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"],
+b4_syncline([@oline@], [@ofile@])],
 [typedef int yystype;])
 # define YYSTYPE yystype
+# define YYSTYPE_IS_TRIVIAL 1
 #endif
 
 b4_pure_if([],
@@ -1932,5 +1936,4 @@ typedef struct yyltype
 m4_if(b4_pure, [0],
 [extern YYLTYPE b4_prefix[]lloc;])
 ])
-#endif /* not b4_header_guard */
 ])