bison-patches
[Top][All Lists]
Advanced

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

19-fyi-rule-t.patch


From: Akim Demaille
Subject: 19-fyi-rule-t.patch
Date: Mon, 19 Nov 2001 10:03:12 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/gram.h (rule_t): New.
        (rule_table): New.
        (rrhs, rlhs): Remove, part of state_t.
        * src/print_graph.c, src/closure.c, src/conflicts.c, src/derives.c,
        * src/lalr.c, src/nullable.c, src/output.c, src/print.c,
        * src/reader.c, src/reduce.c: Adjust.
        
        
Index: src/print_graph.c
--- src/print_graph.c Thu, 15 Nov 2001 23:11:56 +0100 akim
+++ src/print_graph.c Fri, 16 Nov 2001 00:54:30 +0100 akim
@@ -76,9 +76,10 @@
       rule = -(*sp);
 
       obstack_fgrow1 (node_obstack, "%d: ", rule);
-      obstack_fgrow1 (node_obstack, " %s  ->  ", quote (tags[rlhs[rule]]));
+      obstack_fgrow1 (node_obstack, " %s  ->  ",
+                     quote (tags[rule_table[rule].lhs]));
 
-      for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
+      for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
        obstack_fgrow1 (node_obstack, "%s ", quote (tags[*sp]));
 
       obstack_1grow (node_obstack, '.');
@@ -181,7 +182,7 @@
   if (state_table[state].consistent && redp)
     {
       rule = redp->rules[0];
-      symbol = rlhs[rule];
+      symbol = rule_table[rule].lhs;
       if (obstack_object_size (node_obstack) > node_output_size)
        obstack_sgrow (node_obstack, "\\n");
       obstack_fgrow2 (node_obstack, _("$default\treduce using rule %d (%s)"),
Index: src/closure.c
--- src/closure.c Fri, 28 Sep 2001 09:33:42 +0200 akim
+++ src/closure.c Fri, 16 Nov 2001 00:48:36 +0100 akim
@@ -130,7 +130,7 @@
       sp = derives[i];
       while (*sp >= 0)
        {
-         symbol = ritem[rrhs[*sp++]];
+         symbol = ritem[rule_table[*sp++].rhs];
          if (ISVAR (symbol))
            {
              symbol -= ntokens;
@@ -287,7 +287,7 @@
            {
              if (word & (1 << b))
                {
-                 itemno = rrhs[ruleno];
+                 itemno = rule_table[ruleno].rhs;
                  while (csp < csend && *csp < itemno)
                    *itemsetend++ = *csp++;
                  *itemsetend++ = itemno;
Index: src/conflicts.c
--- src/conflicts.c Thu, 15 Nov 2001 23:53:01 +0100 akim
+++ src/conflicts.c Fri, 16 Nov 2001 00:58:19 +0100 akim
@@ -587,7 +587,8 @@
        {
          if (mask & *fp3)
            fprintf (out, _("    %-4s\t[reduce using rule %d (%s)]\n"),
-                    tags[i], default_rule, tags[rlhs[default_rule]]);
+                    tags[i], default_rule,
+                    tags[rule_table[default_rule].lhs]);
 
          mask <<= 1;
          if (mask == 0)
@@ -598,7 +599,7 @@
        }
 
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
-              default_rule, tags[rlhs[default_rule]]);
+              default_rule, tags[rule_table[default_rule].lhs]);
     }
   else if (n - m >= 1)
     {
@@ -687,7 +688,7 @@
                          rule = LAruleno[j];
                          fprintf (out,
                                   _("    %-4s\treduce using rule %d (%s)\n"),
-                                  tags[i], rule, tags[rlhs[rule]]);
+                                  tags[i], rule, tags[rule_table[rule].lhs]);
                        }
                      else
                        defaulted = 1;
@@ -701,13 +702,13 @@
                          rule = LAruleno[default_LA];
                          fprintf (out,
                                   _("    %-4s\treduce using rule %d (%s)\n"),
-                                  tags[i], rule, tags[rlhs[rule]]);
+                                  tags[i], rule, tags[rule_table[rule].lhs]);
                          defaulted = 0;
                        }
                      rule = LAruleno[j];
                      fprintf (out,
                               _("    %-4s\t[reduce using rule %d (%s)]\n"),
-                              tags[i], rule, tags[rlhs[rule]]);
+                              tags[i], rule, tags[rule_table[rule].lhs]);
                    }
                }
 
@@ -727,7 +728,7 @@
 
       if (default_LA >= 0)
        fprintf (out, _("    $default\treduce using rule %d (%s)\n"),
-                default_rule, tags[rlhs[default_rule]]);
+                default_rule, tags[rule_table[default_rule].lhs]);
     }
 }
 
Index: src/derives.c
--- src/derives.c Fri, 28 Sep 2001 09:33:42 +0200 akim
+++ src/derives.c Fri, 16 Nov 2001 00:48:35 +0100 akim
@@ -74,7 +74,7 @@
   p = delts;
   for (i = nrules; i > 0; i--)
     {
-      lhs = rlhs[i];
+      lhs = rule_table[i].lhs;
       if (lhs >= 0)
        {
          p->next = dset[lhs];
Index: src/gram.c
--- src/gram.c Fri, 28 Sep 2001 09:33:42 +0200 akim
+++ src/gram.c Fri, 16 Nov 2001 00:55:15 +0100 akim
@@ -1,5 +1,5 @@
 /* Allocate input grammar variables for bison,
-   Copyright 1984, 1986, 1989 Free Software Foundation, Inc.
+   Copyright 1984, 1986, 1989, 2001 Free Software Foundation, Inc.
 
 This file is part of Bison, the GNU Compiler Compiler.
 
@@ -20,6 +20,7 @@
 
 
 #include "system.h"
+#include "gram.h"
 
 void dummy PARAMS((void));
 
@@ -32,8 +33,7 @@
 int nvars;
 
 short *ritem = NULL;
-short *rlhs = NULL;
-short *rrhs = NULL;
+rule_t *rule_table = NULL;
 short *rprec = NULL;
 short *rprecsym = NULL;
 short *sprec = NULL;
Index: src/gram.h
--- src/gram.h Fri, 28 Sep 2001 09:33:42 +0200 akim
+++ src/gram.h Fri, 16 Nov 2001 00:52:55 +0100 akim
@@ -1,5 +1,5 @@
 /* Data definitions for internal representation of bison's input,
-   Copyright 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
+   Copyright 1984, 1986, 1989, 1992, 2001  Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -38,21 +38,27 @@
    The rules receive rule numbers 1 to nrules in the order they are
    written.  Actions and guards are accessed via the rule number.
 
-   The rules themselves are described by three arrays: rrhs, rlhs and
-   ritem.  rlhs[R] is the symbol number of the left hand side of rule
-   R.  The right hand side is stored as symbol numbers in a portion of
-   ritem.  rrhs[R] contains the index in ritem of the beginning of the
+   The rules themselves are described by several arrays: amongst which
+   RITEM, and RULE_TABLE.
+
+   RULE_TABLE is an array of struct rule_s, which members are:
+
+   RULE_TABLE[R].lhs -- the symbol number of the left hand side of
+   rule R.  If -1, the rule has been thrown out by reduce.c and should
+   be ignored.
+
+   RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
    portion for rule R.
 
-   If rlhs[R] is -1, the rule has been thrown out by reduce.c and
-   should be ignored.
+   The right hand side is stored as symbol numbers in a portion of
+   RITEM.
 
    The length of the portion is one greater than the number of symbols
    in the rule's right hand side.  The last element in the portion
    contains minus R, which identifies it as the end of a portion and
    says which rule it is for.
 
-   The portions of ritem come in order of increasing rule number and
+   The portions of RITEM come in order of increasing rule number and
    are followed by an element which is zero to mark the end.  nitems
    is the total length of ritem, not counting the final zero.  Each
    element of ritem is called an "item" and its index in ritem is an
@@ -84,8 +90,7 @@
 extern int nvars;
 
 extern short *ritem;
-extern short *rlhs;
-extern short *rrhs;
+
 extern short *rprec;
 extern short *rprecsym;
 extern short *sprec;
@@ -95,6 +100,13 @@
 
 extern int start_symbol;
 
+typedef struct rule_s
+{
+  short lhs;
+  short rhs;
+} rule_t;
+
+extern struct rule_s *rule_table;
 
 /* associativity values in elements of rassoc, sassoc.  */
 typedef enum
Index: src/lalr.c
--- src/lalr.c Fri, 16 Nov 2001 00:14:13 +0100 akim
+++ src/lalr.c Fri, 16 Nov 2001 00:48:35 +0100 akim
@@ -561,7 +561,7 @@
          states[0] = state1;
          stateno = state1;
 
-         for (rp = ritem + rrhs[*rulep]; *rp > 0; rp++)
+         for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
            {
              symbol2 = *rp;
              sp = state_table[stateno].shift_table;
Index: src/nullable.c
--- src/nullable.c Fri, 28 Sep 2001 09:33:42 +0200 akim
+++ src/nullable.c Fri, 16 Nov 2001 00:50:36 +0100 akim
@@ -69,7 +69,7 @@
     {
       if (*r < 0)
        {
-         symbol = rlhs[-(*r++)];
+         symbol = rule_table[-(*r++)].lhs;
          if (symbol >= 0 && !nullable[symbol])
            {
              nullable[symbol] = 1;
@@ -111,7 +111,7 @@
          p = p->next;
          if (--rcount[ruleno] == 0)
            {
-             symbol = rlhs[ruleno];
+             symbol = rule_table[ruleno].lhs;
              if (symbol >= 0 && !nullable[symbol])
                {
                  nullable[symbol] = 1;
Index: src/output.c
--- src/output.c Thu, 15 Nov 2001 23:53:01 +0100 akim
+++ src/output.c Fri, 16 Nov 2001 00:52:08 +0100 akim
@@ -319,8 +319,15 @@
   if (!semantic_parser && !no_parser_flag)
     obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n");
 
-  output_short_table (&table_obstack, NULL, "yyprhs", rrhs,
-                     0, 1, nrules + 1);
+  {
+    int i;
+    short *values = XCALLOC (short, nrules + 1);
+    for (i = 0; i < nrules + 1; ++i)
+      values[i] = rule_table[i].rhs;
+    output_short_table (&table_obstack, NULL, "yyprhs", values,
+                       0, 1, nrules + 1);
+    XFREE (values);
+  }
 
   {
     size_t yyrhs_size = 1;
@@ -455,19 +462,24 @@
     }
 
   /* Output YYR1. */
-  output_short_table (&table_obstack,
+  {
+    short *values = XCALLOC (short, nrules + 1);
+    for (i = 0; i < nrules + 1; ++i)
+      values[i] = rule_table[i].lhs;
+    output_short_table (&table_obstack,
              "YYR1[YYN] -- Symbol number of symbol that rule YYN derives",
-                     "yyr1", rlhs,
-                     0, 1, nrules + 1);
-  XFREE (rlhs + 1);
+                       "yyr1", values,
+                       0, 1, nrules + 1);
+    XFREE (values);
+  }
 
   obstack_1grow (&table_obstack, '\n');
 
   /* Output YYR2. */
   short_tab = XMALLOC (short, nrules + 1);
   for (i = 1; i < nrules; i++)
-    short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;
-  short_tab[nrules] = nitems - rrhs[nrules] - 1;
+    short_tab[i] = rule_table[i + 1].rhs - rule_table[i].rhs - 1;
+  short_tab[nrules] = nitems - rule_table[nrules].rhs - 1;
   output_short_table (&table_obstack,
         "YYR2[YYN] -- Number of symbols composing right hand side of rule YYN",
                      "yyr2", short_tab,
@@ -476,7 +488,7 @@
 
   XFREE (short_tab);
 
-  XFREE (rrhs + 1);
+  XFREE (rule_table + 1);
 }
 
 
Index: src/print.c
--- src/print.c Thu, 15 Nov 2001 23:11:56 +0100 akim
+++ src/print.c Fri, 16 Nov 2001 00:52:27 +0100 akim
@@ -68,9 +68,9 @@
        sp++;
 
       rule = -(*sp);
-      fprintf (out, "    %s  ->  ", tags[rlhs[rule]]);
+      fprintf (out, "    %s  ->  ", tags[rule_table[rule].lhs]);
 
-      for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
+      for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
        {
          fprintf (out, "%s ", tags[*sp]);
        }
@@ -168,7 +168,7 @@
   if (state_table[state].consistent && redp)
     {
       rule = redp->rules[0];
-      symbol = rlhs[rule];
+      symbol = rule_table[rule].lhs;
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
               rule, tags[symbol]);
     }
@@ -230,10 +230,10 @@
   fprintf (out, "\n%s\n\n", _("Grammar"));
   for (i = 1; i <= nrules; i++)
     /* Don't print rules disabled in reduce_grammar_tables.  */
-    if (rlhs[i] >= 0)
+    if (rule_table[i].lhs >= 0)
       {
-       fprintf (out, _("rule %-4d %s ->"), i, tags[rlhs[i]]);
-       rule = &ritem[rrhs[i]];
+       fprintf (out, _("rule %-4d %s ->"), i, tags[rule_table[i].lhs]);
+       rule = &ritem[rule_table[i].rhs];
        if (*rule > 0)
          while (*rule > 0)
            fprintf (out, " %s", tags[*rule++]);
@@ -256,7 +256,7 @@
        sprintf (buffer, " (%d)", i);
 
        for (j = 1; j <= nrules; j++)
-         for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+         for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
            if (*rule == token_translations[i])
              {
                END_TEST (65);
@@ -274,9 +274,9 @@
 
       for (j = 1; j <= nrules; j++)
        {
-         if (rlhs[j] == i)
+         if (rule_table[j].lhs == i)
            left_count++;
-         for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+         for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
            if (*rule == i)
              {
                right_count++;
@@ -298,7 +298,7 @@
          for (j = 1; j <= nrules; j++)
            {
              END_TEST (65);
-             if (rlhs[j] == i)
+             if (rule_table[j].lhs == i)
                sprintf (buffer + strlen (buffer), " %d", j);
            }
        }
@@ -311,7 +311,7 @@
          sprintf (buffer + strlen (buffer), _(" on right:"));
          for (j = 1; j <= nrules; j++)
            {
-             for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+             for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
                if (*rule == i)
                  {
                    END_TEST (65);
Index: src/reader.c
--- src/reader.c Fri, 16 Nov 2001 00:41:22 +0100 akim
+++ src/reader.c Fri, 16 Nov 2001 00:53:49 +0100 akim
@@ -1874,8 +1874,7 @@
   bucket *ruleprec;
 
   ritem = XCALLOC (short, nitems + 1);
-  rlhs = XCALLOC (short, nrules) - 1;
-  rrhs = XCALLOC (short, nrules) - 1;
+  rule_table = XCALLOC (rule_t, nrules) - 1;
   rprec = XCALLOC (short, nrules) - 1;
   rprecsym = XCALLOC (short, nrules) - 1;
   rassoc = XCALLOC (short, nrules) - 1;
@@ -1886,8 +1885,8 @@
   p = grammar;
   while (p)
     {
-      rlhs[ruleno] = p->sym->value;
-      rrhs[ruleno] = itemno;
+      rule_table[ruleno].lhs = p->sym->value;
+      rule_table[ruleno].rhs = itemno;
       ruleprec = p->ruleprec;
 
       p = p->next;
Index: src/reduce.c
--- src/reduce.c Sat, 10 Nov 2001 14:09:09 +0100 akim
+++ src/reduce.c Fri, 16 Nov 2001 00:53:47 +0100 akim
@@ -100,7 +100,7 @@
   /* A production is useful if all of the nonterminals in its appear
      in the set of useful nonterminals.  */
 
-  for (r = &ritem[rrhs[i]]; *r > 0; r++)
+  for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
     if (ISVAR (n = *r))
       if (!BITISSET (N0, n - ntokens))
        return FALSE;
@@ -149,7 +149,7 @@
            {
              if (useful_production (i, N))
                {
-                 SETBIT (Np, rlhs[i] - ntokens);
+                 SETBIT (Np, rule_table[i].lhs - ntokens);
                  SETBIT (P, i);
                }
            }
@@ -211,9 +211,9 @@
        Vp[i] = V[i];
       for (i = 1; i <= nrules; i++)
        {
-         if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rlhs[i]))
+         if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, 
rule_table[i].lhs))
            {
-             for (r = &ritem[rrhs[i]]; *r >= 0; r++)
+             for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
                {
                  if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens))
                    {
@@ -279,15 +279,15 @@
              np++;
              if (pn != np)
                {
-                 rlhs[np] = rlhs[pn];
+                 rule_table[np].lhs = rule_table[pn].lhs;
                  rline[np] = rline[pn];
                  rprec[np] = rprec[pn];
                  rassoc[np] = rassoc[pn];
-                 rrhs[np] = rrhs[pn];
-                 if (rrhs[np] != ni)
+                 rule_table[np].rhs = rule_table[pn].rhs;
+                 if (rule_table[np].rhs != ni)
                    {
-                     pi = rrhs[np];
-                     rrhs[np] = ni;
+                     pi = rule_table[np].rhs;
+                     rule_table[np].rhs = ni;
                      while (ritem[pi] >= 0)
                        ritem[ni++] = ritem[pi++];
                      ritem[ni++] = -np;
@@ -319,7 +319,7 @@
        {
          if (!BITISSET (P, pn))
            {
-             rlhs[pn] = -1;
+             rule_table[pn].lhs = -1;
            }
        }
     }
@@ -368,8 +368,8 @@
       for (i = 1; i <= nrules; i++)
        {
          /* Ignore the rules disabled above.  */
-         if (rlhs[i] >= 0)
-           rlhs[i] = nontermmap[rlhs[i]];
+         if (rule_table[i].lhs >= 0)
+           rule_table[i].lhs = nontermmap[rule_table[i].lhs];
          if (ISVAR (rprecsym[i]))
            /* Can this happen?  */
            rprecsym[i] = nontermmap[rprecsym[i]];
@@ -434,8 +434,8 @@
          if (!BITISSET (P, i))
            {
              fprintf (out, "#%-4d  ", i);
-             fprintf (out, "%s :\t", tags[rlhs[i]]);
-             for (r = &ritem[rrhs[i]]; *r >= 0; r++)
+             fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
+             for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
                fprintf (out, " %s", tags[*r]);
              fprintf (out, ";\n");
            }
@@ -464,8 +464,8 @@
   for (i = 1; i <= nrules; i++)
     {
       fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
-              i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
-      for (r = &ritem[rrhs[i]]; *r > 0; r++)
+              i, rprec[i], rassoc[i], rule_table[i].lhs, rule_table[i].rhs);
+      for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
        fprintf (out, "%5d", *r);
       fprintf (out, " [%d]\n", -(*r));
     }
@@ -473,8 +473,8 @@
   fprintf (out, _("Rules interpreted\n-----------------\n\n"));
   for (i = 1; i <= nrules; i++)
     {
-      fprintf (out, "%-5d  %s :", i, tags[rlhs[i]]);
-      for (r = &ritem[rrhs[i]]; *r > 0; r++)
+      fprintf (out, "%-5d  %s :", i, tags[rule_table[i].lhs]);
+      for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
        fprintf (out, " %s", tags[*r]);
       fputc ('\n', out);
     }



reply via email to

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