bison-patches
[Top][All Lists]
Advanced

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

01-fyi-formatting-reduce.patch


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

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        * src/reduce.c: Various comment/formatting changes.
        (nonterminals_reduce): New, extracted from...
        (reduce_grammar_tables): here.
        (reduce_grammar): Call nonterminals_reduce.
        
Index: src/main.c
--- src/main.c Sat, 24 Nov 2001 17:01:37 +0100 akim
+++ src/main.c Thu, 29 Nov 2001 22:26:02 +0100 akim
@@ -62,8 +62,7 @@
   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: src/reduce.c
--- src/reduce.c Thu, 29 Nov 2001 21:52:19 +0100 akim
+++ src/reduce.c Thu, 29 Nov 2001 22:27:22 +0100 akim
@@ -38,11 +38,18 @@
 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 @@
            }
        }
     }
+}
 
-  /* remove useless symbols */
-  if (nuseless_nonterminals > 0)
-    {
 
-      int i, n;
-/*      short  j; JF unused */
-      short *nontermmap;
-      rule r;
-
-      /* Create a map of nonterminal number to new nonterminal
-        number. -1 in the map means it was useless and is being
-        eliminated.  */
+/*------------------------------.
+| Remove useless nonterminals.  |
+`------------------------------*/
 
-      nontermmap = XCALLOC (short, nvars) - ntokens;
-      for (i = ntokens; i < nsyms; i++)
-       nontermmap[i] = -1;
+static void
+nonterminals_reduce (void)
+{
+  int i, n;
+  rule r;
 
-      n = ntokens;
-      for (i = ntokens; i < nsyms; i++)
-       if (BITISSET (V, i))
-         nontermmap[i] = n++;
+  /* Create a map of nonterminal number to new nonterminal number. -1
+     in the map means it was useless and is being eliminated.  */
 
-      /* Shuffle elements of tables indexed by symbol number.  */
+  short *nontermmap = XCALLOC (short, nvars) - ntokens;
+  for (i = ntokens; i < nsyms; i++)
+    nontermmap[i] = -1;
 
-      for (i = ntokens; i < nsyms; i++)
-       {
-         n = nontermmap[i];
-         if (n >= 0)
-           {
-             sassoc[n] = sassoc[i];
-             sprec[n] = sprec[i];
-             tags[n] = tags[i];
-           }
-       }
+  n = ntokens;
+  for (i = ntokens; i < nsyms; i++)
+    if (BITISSET (V, i))
+      nontermmap[i] = n++;
 
-      /* Replace all symbol numbers in valid data structures.  */
+  /* Shuffle elements of tables indexed by symbol number.  */
 
-      for (i = 1; i <= nrules; i++)
+  for (i = ntokens; i < nsyms; i++)
+    {
+      n = nontermmap[i];
+      if (n >= 0)
        {
-         /* 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];
+         sassoc[n] = sassoc[i];
+         sprec[n] = sprec[i];
+         tags[n] = tags[i];
        }
+    }
 
-      for (r = ritem; *r; r++)
-       if (ISVAR (*r))
-         *r = nontermmap[*r];
+  /* Replace all symbol numbers in valid data structures.  */
 
-      start_symbol = nontermmap[start_symbol];
+  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];
+    }
 
-      nsyms -= nuseless_nonterminals;
-      nvars -= nuseless_nonterminals;
+  for (r = ritem; *r; r++)
+    if (ISVAR (*r))
+      *r = nontermmap[*r];
 
-      free (&nontermmap[ntokens]);
-    }
+  start_symbol = nontermmap[start_symbol];
+
+  nsyms -= nuseless_nonterminals;
+  nvars -= nuseless_nonterminals;
+
+  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 @@
           tags[start_symbol]);
 
   reduce_grammar_tables ();
+  if (nuseless_nonterminals > 0)
+    nonterminals_reduce ();
 
   if (trace_flag)
     {



reply via email to

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