From: Akim Demaille <akim@epita.fr>
Date: Thu, 27 Dec 2001 18:17:39 +0000 (+0000)
Subject: * src/output.c (output_gram): Rely on nritems, not the
X-Git-Tag: before-m4-back-end~79
X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/3db472b9ebf3e4f58154af02c713e29d258926f5

* src/output.c (output_gram): Rely on nritems, not the
0-sentinel.  See below.
Use -1 as separator, not 0.
* src/bison.simple (yyparse): Subtract 1 to the rule numbers.
Rely on -1 as separator in yyrhs, instead of 0.
* tests/calc.at (AT_CHECK_CALC): Now, the parsers no longer issue
twice `Now at end of input', therefore there are two lines less to
expect.
---

diff --git a/ChangeLog b/ChangeLog
index 984bbc97..da19c05a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-12-27  Akim Demaille  <akim@epita.fr>
+
+	* src/output.c (output_gram): Rely on nritems, not the
+	0-sentinel.  See below.
+	Use -1 as separator, not 0.
+	* src/bison.simple (yyparse): Subtract 1 to the rule numbers.
+	Rely on -1 as separator in yyrhs, instead of 0.
+	* tests/calc.at (AT_CHECK_CALC): Now, the parsers no longer issue
+	twice `Now at end of input', therefore there are two lines less to
+	expect.
+
+	
 2001-12-27  Akim Demaille  <akim@epita.fr>
 
 	* tests/regression.at (Unresolved SR Conflicts):
diff --git a/src/bison.simple b/src/bison.simple
index 593eadf3..5403492f 100644
--- a/src/bison.simple
+++ b/src/bison.simple
@@ -222,7 +222,7 @@ static const short yyprhs[] =
   %%prhs
 };
 
-/* YYRHS -- A `0'-separated list of the rules' RHS. */
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
 static const short yyrhs[] =
 {
   %%rhs
@@ -899,10 +899,10 @@ yyreduce:
       int yyi;
 
       YYFPRINTF (YYSTDERR, "Reducing via rule %d (line %d), ",
-		 yyn, yyrline[yyn]);
+		 yyn - 1, yyrline[yyn]);
 
       /* Print the symbols being reduced, and their result.  */
-      for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
+      for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++)
 	YYFPRINTF (YYSTDERR, "%s ", yytname[yyrhs[yyi]]);
       YYFPRINTF (YYSTDERR, " -> %s\n", yytname[yyr1[yyn]]);
     }
diff --git a/src/output.c b/src/output.c
index 49e63944..4ad8f4e8 100644
--- a/src/output.c
+++ b/src/output.c
@@ -195,19 +195,16 @@ output_gram (void)
   muscle_insert ("prhs", obstack_finish (&format_obstack));
 
   {
-    size_t yyrhs_size = 1;
-    short *yyrhs, *sp;
+    short *yyrhs;
     int i;
 
-    for (sp = ritem + 1; *sp; sp++)
-      ++yyrhs_size;
-    yyrhs = XMALLOC (short, yyrhs_size);
+    yyrhs = XMALLOC (short, nritems);
 
-    for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)
-      yyrhs[i] = *sp >= 0 ? *sp : 0;
+    for (i = 1; i < nritems; ++i)
+      yyrhs[i] = ritem[i] >= 0 ? ritem[i] : -1;
 
     output_table_data (&format_obstack, yyrhs,
-		       ritem[0], 1, yyrhs_size);
+		       ritem[0], 1, nritems);
     muscle_insert ("rhs", obstack_finish (&format_obstack));
 
     XFREE (yyrhs);
diff --git a/tests/calc.at b/tests/calc.at
index 49cf4e23..db308dfd 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -371,7 +371,7 @@ _AT_CHECK_CALC([$1],
 1 - (2 - 3) = 2
 
 2^2^3 = 256
-(2^2)^3 = 64], [488])
+(2^2)^3 = 64], [486])
 
 # Some parse errors.
 _AT_CHECK_CALC_ERROR([$1], [0 0], [10],