]> git.saurik.com Git - bison.git/commitdiff
* src/reduce.c: Various comment/formatting changes.
authorAkim Demaille <akim@epita.fr>
Fri, 30 Nov 2001 10:47:56 +0000 (10:47 +0000)
committerAkim Demaille <akim@epita.fr>
Fri, 30 Nov 2001 10:47:56 +0000 (10:47 +0000)
(nonterminals_reduce): New, extracted from...
(reduce_grammar_tables): here.
(reduce_grammar): Call nonterminals_reduce.

ChangeLog
src/main.c
src/reduce.c

index 4a8ddbcb61376ce0e9bea6e81f8e0a7a438b1615..1606c8dd5e5dbce2b33568b71d38c8befc0da7ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-11-30  Akim Demaille  <akim@epita.fr>
+
+       * src/reduce.c: Various comment/formatting changes.
+       (nonterminals_reduce): New, extracted from...
+       (reduce_grammar_tables): here.
+       (reduce_grammar): Call nonterminals_reduce.
+
 2001-11-29  Paul Eggert  <eggert@twinsun.com>
 
        * src/bison.simple (YYSTACK_REALLOC): Remove.
index 8070446683212b4a47598e89431979d34588d70f..76caf7a0242b58b0e6c4d360b26aa609d0001f75 100644 (file)
@@ -64,8 +64,7 @@ main (int argc, char *argv[])
   if (complain_message_count)
     exit (1);
 
-  /* Find useless nonterminals and productions and reduce the grammar.
-     In file reduce.c.  */
+  /* Find useless nonterminals and productions and reduce the grammar. */
   reduce_grammar ();
 
   /* Record other info about the grammar.  In files derives and
index 02dff622698d755323320bebed8c75e6a32355be..911fb929c5bebfad4ee66931fca9a7904a0007ea 100644 (file)
@@ -38,11 +38,18 @@ typedef unsigned *BSet;
 typedef short *rule;
 
 
-/* N is set of all nonterminals which are not useless.  P is set of
-   all rules which have no useless nonterminals in their RHS.  V is
-   the set of all accessible symbols.  */
+/* Set of all nonterminals which are not useless.  */
+static BSet N;
 
-static BSet N, P, V, V1;
+/* Set of all rules which have no useless nonterminals in their RHS.  */
+static BSet P;
+
+/* Set of all accessible symbols.  */
+static BSet V;
+
+/* Set of symbols used to define rule precedence (so they are
+   `useless', but no warning should be issued).  */
+static BSet V1;
 
 static int nuseful_productions;
 static int nuseless_productions;
@@ -318,71 +325,72 @@ reduce_grammar_tables (void)
            }
        }
     }
+}
 
-  /* remove useless symbols */
-  if (nuseless_nonterminals > 0)
-    {
 
-      int i, n;
-/*      short  j; JF unused */
-      short *nontermmap;
-      rule r;
+/*------------------------------.
+| Remove useless nonterminals.  |
+`------------------------------*/
 
-      /* Create a map of nonterminal number to new nonterminal
-        number. -1 in the map means it was useless and is being
-        eliminated.  */
+static void
+nonterminals_reduce (void)
+{
+  int i, n;
+  rule r;
 
-      nontermmap = XCALLOC (short, nvars) - ntokens;
-      for (i = ntokens; i < nsyms; i++)
-       nontermmap[i] = -1;
+  /* Create a map of nonterminal number to new nonterminal number. -1
+     in the map means it was useless and is being eliminated.  */
 
-      n = ntokens;
-      for (i = ntokens; i < nsyms; i++)
-       if (BITISSET (V, i))
-         nontermmap[i] = n++;
+  short *nontermmap = XCALLOC (short, nvars) - ntokens;
+  for (i = ntokens; i < nsyms; i++)
+    nontermmap[i] = -1;
 
-      /* Shuffle elements of tables indexed by symbol number.  */
+  n = ntokens;
+  for (i = ntokens; i < nsyms; i++)
+    if (BITISSET (V, i))
+      nontermmap[i] = n++;
 
-      for (i = ntokens; i < nsyms; i++)
+  /* Shuffle elements of tables indexed by symbol number.  */
+
+  for (i = ntokens; i < nsyms; i++)
+    {
+      n = nontermmap[i];
+      if (n >= 0)
        {
-         n = nontermmap[i];
-         if (n >= 0)
-           {
-             sassoc[n] = sassoc[i];
-             sprec[n] = sprec[i];
-             tags[n] = tags[i];
-           }
+         sassoc[n] = sassoc[i];
+         sprec[n] = sprec[i];
+         tags[n] = tags[i];
        }
+    }
 
-      /* Replace all symbol numbers in valid data structures.  */
+  /* Replace all symbol numbers in valid data structures.  */
 
-      for (i = 1; i <= nrules; i++)
-       {
-         /* Ignore the rules disabled above.  */
-         if (rule_table[i].lhs >= 0)
-           rule_table[i].lhs = nontermmap[rule_table[i].lhs];
-         if (ISVAR (rule_table[i].precsym))
-           /* Can this happen?  */
-           rule_table[i].precsym = nontermmap[rule_table[i].precsym];
-       }
+  for (i = 1; i <= nrules; i++)
+    {
+      /* Ignore the rules disabled above.  */
+      if (rule_table[i].lhs >= 0)
+       rule_table[i].lhs = nontermmap[rule_table[i].lhs];
+      if (ISVAR (rule_table[i].precsym))
+       /* Can this happen?  */
+       rule_table[i].precsym = nontermmap[rule_table[i].precsym];
+    }
 
-      for (r = ritem; *r; r++)
-       if (ISVAR (*r))
-         *r = nontermmap[*r];
+  for (r = ritem; *r; r++)
+    if (ISVAR (*r))
+      *r = nontermmap[*r];
 
-      start_symbol = nontermmap[start_symbol];
+  start_symbol = nontermmap[start_symbol];
 
-      nsyms -= nuseless_nonterminals;
-      nvars -= nuseless_nonterminals;
+  nsyms -= nuseless_nonterminals;
+  nvars -= nuseless_nonterminals;
 
-      free (&nontermmap[ntokens]);
-    }
+  free (&nontermmap[ntokens]);
 }
 
 
-/*-----------------------------------------------------------------.
-| Ouput the detailed results of the reductions.  For FILE.output.  |
-`-----------------------------------------------------------------*/
+/*------------------------------------------------------------------.
+| Output the detailed results of the reductions.  For FILE.output.  |
+`------------------------------------------------------------------*/
 
 void
 reduce_output (FILE *out)
@@ -537,6 +545,8 @@ reduce_grammar (void)
           tags[start_symbol]);
 
   reduce_grammar_tables ();
+  if (nuseless_nonterminals > 0)
+    nonterminals_reduce ();
 
   if (trace_flag)
     {