bison-patches
[Top][All Lists]
Advanced

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

06-fyi-lalr-clarify.patch


From: Akim Demaille
Subject: 06-fyi-lalr-clarify.patch
Date: Wed, 05 Dec 2001 08:24:32 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/derives.c (print_derives): Display the ruleno.
        * src/lalr.c (initialize_F, transpose): Better variable locality
        to improve readability.
        Avoid variables used as mere abbreviations.

Index: src/derives.c
--- src/derives.c Fri, 30 Nov 2001 00:04:35 +0100 akim
+++ src/derives.c Sat, 01 Dec 2001 13:57:02 +0100 akim
@@ -19,11 +19,6 @@
    Boston, MA 02111-1307, USA.  */


-/* set_derives finds, for each variable (nonterminal), which rules can
-   derive it.  It sets up the value of derives so that derives[i -
-   ntokens] points to a vector of rule numbers, terminated with -1.
-   */
-
 #include "system.h"
 #include "getargs.h"
 #include "types.h"
@@ -31,8 +26,7 @@
 #include "gram.h"
 #include "derives.h"

-short **derives;
-
+short **derives = NULL;

 static void
 print_derives (void)
@@ -51,7 +45,7 @@
          fprintf (stderr, "\t\t%d:", *sp);
          for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
            fprintf (stderr, " %s", tags[*rhsp]);
-         fputc ('\n', stderr);
+         fprintf (stderr, " (rule %d)\n", -*rhsp);
        }
     }

Index: src/derives.h
--- src/derives.h Sat, 11 Nov 2000 16:04:34 +0100 akim
+++ src/derives.h Sat, 01 Dec 2001 13:54:18 +0100 akim
@@ -1,5 +1,5 @@
 /* Match rules with nonterminals for bison,
-   Copyright 1984, 1989, 2000 Free Software Foundation, Inc.
+   Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.

    This file is part of Bison, the GNU Compiler Compiler.

@@ -21,12 +21,11 @@
 #ifndef DERIVES_H_
 # define DERIVES_H_

+/* DERIVES[SYMBOL - NTOKENS] points to a vector of the number of the
+   rules that SYMBOL derives, terminated with -1.  */
 extern short **derives;

-/* set_derives finds, for each variable (nonterminal), which rules can
-   derive it.  It sets up the value of derives so that derives[i -
-   ntokens] points to a vector of rule numbers, terminated with -1.
-   */
+/* Compute DERIVES.  */

 void set_derives PARAMS((void));
 void free_derives PARAMS((void));
Index: src/lalr.c
--- src/lalr.c Sat, 01 Dec 2001 13:49:03 +0100 akim
+++ src/lalr.c Sat, 01 Dec 2001 14:05:27 +0100 akim
@@ -358,14 +358,11 @@
 {
   int i;
   int j;
-  int k;
-  shifts *sp;
   short *edge;
   unsigned *rowp;
   short *rp;
   short **reads;
   int nedges;
-  int stateno;
   int symbol;
   int nwords;

@@ -379,14 +376,12 @@
   rowp = F;
   for (i = 0; i < ngotos; i++)
     {
-      stateno = to_state[i];
-      sp = state_table[stateno].shift_table;
+      int stateno = to_state[i];
+      shifts *sp = state_table[stateno].shift_table;

       if (sp)
        {
-         k = sp->nshifts;
-
-         for (j = 0; j < k; j++)
+         for (j = 0; j < sp->nshifts; j++)
            {
              symbol = state_table[sp->shifts[j]].accessing_symbol;
              if (ISVAR (symbol))
@@ -394,7 +389,7 @@
              SETBIT (rowp, symbol);
            }

-         for (; j < k; j++)
+         for (; j < sp->nshifts; j++)
            {
              symbol = state_table[sp->shifts[j]].accessing_symbol;
              if (nullable[symbol])
@@ -460,15 +455,13 @@
   short **new_R;
   short **temp_R;
   short *nedges;
-  short *sp;
   int i;
-  int k;

   nedges = XCALLOC (short, n);

   for (i = 0; i < n; i++)
     {
-      sp = R_arg[i];
+      short *sp = R_arg[i];
       if (sp)
        {
          while (*sp >= 0)
@@ -480,27 +473,22 @@
   temp_R = XCALLOC (short *, n);

   for (i = 0; i < n; i++)
-    {
-      k = nedges[i];
-      if (k > 0)
-       {
-         sp = XCALLOC (short, k + 1);
-         new_R[i] = sp;
-         temp_R[i] = sp;
-         sp[k] = -1;
-       }
-    }
+    if (nedges[i] > 0)
+      {
+       short *sp = XCALLOC (short, nedges[i] + 1);
+       new_R[i] = sp;
+       temp_R[i] = sp;
+       sp[nedges[i]] = -1;
+      }

   XFREE (nedges);

   for (i = 0; i < n; i++)
     {
-      sp = R_arg[i];
+      short *sp = R_arg[i];
       if (sp)
-       {
-         while (*sp >= 0)
-           *temp_R[*sp++]++ = i;
-       }
+       while (*sp >= 0)
+         *temp_R[*sp++]++ = i;
     }

   XFREE (temp_R);
@@ -514,18 +502,13 @@
 {
   int i;
   int j;
-  int k;
   short *rulep;
   short *rp;
-  shifts *sp;
-  int length;
   int nedges;
   int done;
   int state1;
   int stateno;
   int symbol1;
-  int symbol2;
-  short *shortp;
   short *edge;
   short *states;
   short **new_includes;
@@ -542,17 +525,16 @@

       for (rulep = derives[symbol1]; *rulep > 0; rulep++)
        {
-         length = 1;
+         int length = 1;
          states[0] = state1;
          stateno = state1;

          for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
            {
-             symbol2 = *rp;
-             sp = state_table[stateno].shift_table;
-             k = sp->nshifts;
+             int symbol2 = *rp;
+             shifts *sp = state_table[stateno].shift_table;

-             for (j = 0; j < k; j++)
+             for (j = 0; j < sp->nshifts; j++)
                {
                  stateno = sp->shifts[j];
                  if (state_table[stateno].accessing_symbol == symbol2)
@@ -584,19 +566,17 @@

       if (nedges)
        {
-         includes[i] = shortp = XCALLOC (short, nedges + 1);
+         includes[i] = XCALLOC (short, nedges + 1);
          for (j = 0; j < nedges; j++)
-           shortp[j] = edge[j];
-         shortp[nedges] = -1;
+           includes[i][j] = edge[j];
+         includes[i][nedges] = -1;
        }
     }

   new_includes = transpose (includes, ngotos);

   for (i = 0; i < ngotos; i++)
-    if (includes[i])
-      XFREE (includes[i]);
-
+    XFREE (includes[i]);
   XFREE (includes);

   includes = new_includes;



reply via email to

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