bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02-fyi-reduce-nterms.patch


From: Akim Demaille
Subject: 02-fyi-reduce-nterms.patch
Date: Fri, 30 Nov 2001 11:43:07 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/reduce.c (nonterminals_reduce): Instead of throwing away
        useless nonterminals, move them at the end of the symbol arrays.
        (reduce_output): Adjust.
        * tests/reduce.at (Useless Nonterminals): Adjust.

Index: NEWS
--- NEWS Thu, 29 Nov 2001 21:52:19 +0100 akim
+++ NEWS Thu, 29 Nov 2001 22:48:53 +0100 akim
@@ -3,6 +3,9 @@

 Changes in version 1.30f:

+* Reduced Grammars
+  Fixed bugs when reporting useless nonterminals.
+
 Changes in version 1.30e:

 * Error messages
Index: src/reduce.c
--- src/reduce.c Thu, 29 Nov 2001 22:30:19 +0100 akim
+++ src/reduce.c Thu, 29 Nov 2001 22:45:45 +0100 akim
@@ -342,26 +342,38 @@
      in the map means it was useless and is being eliminated.  */

   short *nontermmap = XCALLOC (short, nvars) - ntokens;
-  for (i = ntokens; i < nsyms; i++)
-    nontermmap[i] = -1;
-
   n = ntokens;
   for (i = ntokens; i < nsyms; i++)
     if (BITISSET (V, i))
       nontermmap[i] = n++;
+  for (i = ntokens; i < nsyms; i++)
+    if (!BITISSET (V, i))
+      nontermmap[i] = n++;

-  /* Shuffle elements of tables indexed by symbol number.  */

-  for (i = ntokens; i < nsyms; i++)
-    {
-      n = nontermmap[i];
-      if (n >= 0)
-       {
-         sassoc[n] = sassoc[i];
-         sprec[n] = sprec[i];
-         tags[n] = tags[i];
-       }
-    }
+  /* Shuffle elements of tables indexed by symbol number.  */
+  {
+    short *sassoc_sorted = XMALLOC (short, nvars) - ntokens;
+    short *sprec_sorted  = XMALLOC (short, nvars) - ntokens;
+    char **tags_sorted   = XMALLOC (char *, nvars) - ntokens;
+
+    for (i = ntokens; i < nsyms; i++)
+      {
+       n = nontermmap[i];
+       sassoc_sorted[n] = sassoc[i];
+       sprec_sorted[n]  = sprec[i];
+       tags_sorted[n]   = tags[i];
+      }
+    for (i = ntokens; i < nsyms; i++)
+      {
+       sassoc[i] = sassoc_sorted[i];
+       sprec[i]  = sprec_sorted[i];
+       tags[i]   = tags_sorted[i];
+      }
+    free (sassoc_sorted + ntokens);
+    free (sprec_sorted + ntokens);
+    free (tags_sorted + ntokens);
+  }

   /* Replace all symbol numbers in valid data structures.  */

@@ -403,9 +415,8 @@
     {
       fprintf (out, _("Useless nonterminals:"));
       fprintf (out, "\n\n");
-      for (i = ntokens; i < nsyms; i++)
-       if (!BITISSET (V, i))
-         fprintf (out, "   %s\n", tags[i]);
+      for (i = 0; i < nuseless_nonterminals; ++i)
+       fprintf (out, "   %s\n", tags[nsyms + i]);
     }
   b = FALSE;
   for (i = 0; i < ntokens; i++)
Index: tests/reduce.at
--- tests/reduce.at Thu, 29 Nov 2001 21:52:19 +0100 akim
+++ tests/reduce.at Thu, 29 Nov 2001 22:46:51 +0100 akim
@@ -88,10 +88,12 @@ exp: useful;
 exp: useful;
 ]])

-AT_CHECK([[bison input.y]])
+AT_CHECK([[bison input.y]], 0, [],
+[[input.y contains 9 useless nonterminals
+]])

 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
-[[Terminals which are not used:
+[[Useless nonterminals:
    useless1
    useless2
    useless3



reply via email to

[Prev in Thread] Current Thread [Next in Thread]