]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
* doc/bison.texinfo (Stack Overflow): xref to Recursion.
[bison.git] / data / glr.c
index 94e61bfc71c1e8834ad9d21dc21ab24362e02144..6824d2bf310619b09b23bc5790439dd58784b945 100644 (file)
@@ -108,11 +108,12 @@ b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
 /* This is the parser code for GLR (Generalized LR) parser. */
 
 /* FIXME: minimize these */
-#include <stdlib.h>
+#include <assert.h>
 #include <setjmp.h>
-#include <stdio.h>
 #include <stdarg.h>
-#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 /* Identify Bison output.  */
 #define YYBISON        1
@@ -241,7 +242,7 @@ static YYLTYPE yyloc_default;
   ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
 
 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const ]b4_uint_type(b4_translate_max)[ yytranslate[] =
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
 {
   ]b4_translate[
 };
@@ -249,19 +250,19 @@ static const ]b4_uint_type(b4_translate_max)[ yytranslate[] =
 #if YYDEBUG
 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
    YYRHS.  */
-static const ]b4_uint_type(b4_prhs_max)[ yyprhs[] =
+static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
 {
   ]b4_prhs[
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const ]b4_sint_type(b4_rhs_max)[ yyrhs[] =
+static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
 {
   ]b4_rhs[
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const ]b4_uint_type(b4_rline_max)[ yyrline[] =
+static const ]b4_int_type_for([b4_rline])[ yyrline[] =
 {
   ]b4_rline[
 };
@@ -279,25 +280,25 @@ static const char *const yytname[] =
 #endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const ]b4_uint_type(b4_r1_max)[ yyr1[] =
+static const ]b4_int_type_for([b4_r1])[ yyr1[] =
 {
   ]b4_r1[
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const ]b4_uint_type(b4_r2_max)[ yyr2[] =
+static const ]b4_int_type_for([b4_r2])[ yyr2[] =
 {
   ]b4_r2[
 };
 
 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
-static const short yydprec[] =
+static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
 {
   ]b4_dprec[
 };
 
 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
-static const short yymerger[] =
+static const ]b4_int_type_for([b4_merger])[ yymerger[] =
 {
   ]b4_merger[
 };
@@ -305,13 +306,13 @@ static const short yymerger[] =
 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
    doesn't specify something else to do.  Zero means the default is an
    error.  */
-static const short yydefact[] =
+static const ]b4_int_type_for([b4_defact])[ yydefact[] =
 {
   ]b4_defact[
 };
 
 /* YYPDEFGOTO[NTERM-NUM]. */
-static const short yydefgoto[] =
+static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
 {
   ]b4_defgoto[
 };
@@ -319,13 +320,13 @@ static const short yydefgoto[] =
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
 #define YYPACT_NINF ]b4_pact_ninf[
-static const ]b4_sint_type(b4_pact_max)[ yypact[] =
+static const ]b4_int_type_for([b4_pact])[ yypact[] =
 {
   ]b4_pact[
 };
 
 /* YYPGOTO[NTERM-NUM].  */
-static const short yypgoto[] =
+static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
 {
   ]b4_pgoto[
 };
@@ -334,7 +335,7 @@ static const short yypgoto[] =
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.  */
 #define YYTABLE_NINF ]b4_table_ninf[
-static const ]b4_sint_type(b4_table_max)[ yytable[] =
+static const ]b4_int_type_for([b4_table])[ yytable[] =
 {
   ]b4_table[
 };
@@ -343,19 +344,22 @@ static const ]b4_sint_type(b4_table_max)[ yytable[] =
    of conflicting reductions corresponding to action entry for state
    STATE-NUM in yytable.  0 means no conflicts.  The list in yyconfl
    is terminated by a rule number of 0. */
-static const short yyconflp[] =
+static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
 {
   ]b4_conflict_list_heads[
 };
 
 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
    by 0, pointed into by YYCONFLP. */
-static const short yyconfl[] =
+]dnl Do not use b4_int_type_for here, since there are places where
+dnl pointers onto yyconfl are taken, which type is "short *".
+dnl We probably ought to introduce a type for confl.
+[static const short yyconfl[] =
 {
   ]b4_conflicting_rules[
 };
 
-static const short yycheck[] =
+static const ]b4_int_type_for([b4_check])[ yycheck[] =
 {
   ]b4_check[
 };
@@ -1494,7 +1498,8 @@ yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
     {
 #if YYERROR_VERBOSE
       yySymbol* const yytokenp = yystack->yytokenp;
-      int yyn, yyx, yycount, yysize;
+      int yyn, yyx, yycount;
+      size_t yysize;
       const char* yyprefix;
       char* yyp;
       char* yymsg;
@@ -1509,7 +1514,7 @@ yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
          yyprefix = ", expecting ";
          for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
               yyx += 1)
-           if (yycheck[yyx + yyn] == yyx)
+           if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
              yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
                yycount += 1, yyprefix = " or ";
          yymsg = yyp = (char*) malloc (yysize);
@@ -1758,20 +1763,19 @@ static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED;
 static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
 
 static void
-yypstates (yyGLRState* yyst)
+yy_yypstack (yyGLRState* yys)
 {
-  static void
-  yy_yypstack (yyGLRState* yys)
+  if (yys->yypred)
     {
-      if (yys->yypred == NULL)
-       fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn);
-      else
-       {
-         yy_yypstack (yys->yypred);
-         fprintf (stderr, " -> %d@%d", yys->yylrState, yys->yyposn);
-       }
+      yy_yypstack (yys->yypred);
+      fprintf (stderr, " -> ");
     }
+  fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long) yys->yyposn);
+}
 
+static void
+yypstates (yyGLRState* yyst)
+{
   if (yyst == NULL)
     fprintf (stderr, "<null>");
   else
@@ -1796,28 +1800,30 @@ yypdumpstack (yyGLRStack* yystack)
   size_t yyi;
   for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
     {
-      fprintf (stderr, "%3d. ", yyp - yystack->yyitems);
+      fprintf (stderr, "%3lu. ", (unsigned long) (yyp - yystack->yyitems));
       if (*(bool*) yyp)
        {
-         fprintf (stderr, "Res: %d, LR State: %d, posn: %d, pred: %d",
+         fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
                   yyp->yystate.yyresolved, yyp->yystate.yylrState,
-                  yyp->yystate.yyposn,
-                  YYINDEX(yyp->yystate.yypred));
+                  (unsigned long) yyp->yystate.yyposn,
+                  (long) YYINDEX (yyp->yystate.yypred));
          if (! yyp->yystate.yyresolved)
-           fprintf (stderr, ", firstVal: %d",
-                    YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
+           fprintf (stderr, ", firstVal: %ld",
+                    (long) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
        }
       else
        {
-         fprintf (stderr, "Option. rule: %d, state: %d, next: %d",
-                  yyp->yyoption.yyrule, YYINDEX (yyp->yyoption.yystate),
-                  YYINDEX (yyp->yyoption.yynext));
+         fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
+                  yyp->yyoption.yyrule,
+                  (long) YYINDEX (yyp->yyoption.yystate),
+                  (long) YYINDEX (yyp->yyoption.yynext));
        }
       fprintf (stderr, "\n");
     }
   fprintf (stderr, "Tops:");
   for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
-    fprintf (stderr, "%d: %d; ", yyi, YYINDEX (yystack->yytops.yystates[yyi]));
+    fprintf (stderr, "%lu: %ld; ", (unsigned long) yyi,
+            (long) YYINDEX (yystack->yytops.yystates[yyi]));
   fprintf (stderr, "\n");
 }