bison-patches
[Top][All Lists]
Advanced

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

15-fyi-LArule.patch


From: Akim Demaille
Subject: 15-fyi-LArule.patch
Date: Sun, 07 Apr 2002 17:24:01 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/lalr.h, src/lalr.c (LAruleno): Replace with...
        (LArule): this, which is an array to rule_t*.
        * src/print.c, src/conflicts.c: Adjust.
        
        
Index: src/conflicts.c
--- src/conflicts.c Sun, 03 Mar 2002 12:18:39 +0100 akim
+++ src/conflicts.c Thu, 04 Apr 2002 19:15:20 +0200 akim
@@ -46,7 +46,9 @@
     obstack_fgrow4 (&output_obstack,
                    _("\
 Conflict in state %d between rule %d and token %s resolved as %s.\n"),
-                   state->number, LAruleno[LAno], symbols[token]->tag,
+                   state->number,
+                   LArule[LAno]->number,
+                   symbols[token]->tag,
                    resolution);
 }
 
@@ -95,7 +97,7 @@
 {
   int i;
   /* find the rule to reduce by to get precedence of reduction  */
-  int redprec = rules[LAruleno[lookahead]].prec;
+  int redprec = LArule[lookahead]->prec;
   errs *errp = errs_new (ntokens + 1);
   errp->nerrs = 0;
 
@@ -172,7 +174,7 @@
      check for shift-reduce conflict, and try to resolve using
      precedence */
   for (i = 0; i < state->nlookaheads; ++i)
-    if (rules[LAruleno[state->lookaheadsp + i]].prec
+    if (LArule[state->lookaheadsp + i]->prec
        && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
       {
        resolve_sr_conflict (state, state->lookaheadsp + i);
Index: src/lalr.c
--- src/lalr.c Sat, 23 Mar 2002 12:44:36 +0100 akim
+++ src/lalr.c Thu, 04 Apr 2002 19:27:19 +0200 akim
@@ -1,5 +1,6 @@
 /* Compute look-ahead criteria for bison,
-   Copyright 1984, 1986, 1989, 2000, 2001  Free Software Foundation, Inc.
+   Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002
+   Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -40,7 +41,7 @@
 /* All the decorated states, indexed by the state number.  */
 state_t **states = NULL;
 
-short *LAruleno = NULL;
+rule_t **LArule = NULL;
 bitsetv LA = NULL;
 size_t nLA;
 
@@ -134,21 +135,21 @@
 {
   size_t i;
   int j;
-  short *np;
+  rule_t **np;
 
   /* Avoid having to special case 0.  */
   if (!nLA)
     nLA = 1;
 
   LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
-  LAruleno = XCALLOC (short, nLA);
+  LArule = XCALLOC (rule_t *, nLA);
   lookback = XCALLOC (shorts *, nLA);
 
-  np = LAruleno;
+  np = LArule;
   for (i = 0; i < nstates; i++)
     if (!states[i]->consistent)
       for (j = 0; j < states[i]->reductions->nreds; j++)
-       *np++ = states[i]->reductions->rules[j];
+       *np++ = &rules[states[i]->reductions->rules[j]];
 }
 
 
@@ -296,10 +297,10 @@
   shorts *sp;
 
   for (i = 0; i < state->nlookaheads; ++i)
-    if (LAruleno[state->lookaheadsp + i] == ruleno)
+    if (LArule[state->lookaheadsp + i]->number == ruleno)
       break;
 
-  assert (LAruleno[state->lookaheadsp + i] == ruleno);
+  assert (LArule[state->lookaheadsp + i]->number == ruleno);
 
   sp = XCALLOC (shorts, 1);
   sp->next = lookback[state->lookaheadsp + i];
@@ -561,7 +562,7 @@
          if (bitset_test (LA[states[i]->lookaheadsp + j], j))
            fprintf (out, "   on %d (%s) -> rule %d\n",
                     k, symbols[k]->tag,
-                    -LAruleno[states[i]->lookaheadsp + j] - 1);
+                    LArule[states[i]->lookaheadsp + j]->number - 1);
     }
   fprintf (out, "Lookaheads: END\n");
 }
Index: src/lalr.h
--- src/lalr.h Fri, 01 Mar 2002 15:43:21 +0100 akim
+++ src/lalr.h Thu, 04 Apr 2002 19:27:50 +0200 akim
@@ -1,5 +1,5 @@
 /* Compute look-ahead criteria for bison,
-   Copyright 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -26,6 +26,8 @@
 /* Import the definition of CORE, SHIFTS and REDUCTIONS. */
 # include "state.h"
 
+/* Import the definition of RULE_T. */
+# include "gram.h"
 
 /* Compute how to make the finite state machine deterministic; find
    which rules need lookahead in each state, and which lookahead
@@ -50,16 +52,15 @@
 extern short *from_state;
 extern short *to_state;
 
-/* LARULENO is a vector which records the rules that need lookahead in
-   various states.  The elements of LARULENO that apply to state S are
-   those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1.  Each element
-   of LARULENO is a rule number.
+/* LARULE is a vector which records the rules that need lookahead in
+   various states.  The elements of LARULE that apply to state S are
+   those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1.
 
-   If LR is the length of LAruleno, then a number from 0 to LR-1 can
+   If LR is the length of LArule, then a number from 0 to LR-1 can
    specify both a rule and a state where the rule might be applied.
    */
 
-extern short *LAruleno;
+extern rule_t **LArule;
 
 /* LA is a lr by ntokens matrix of bits.  LA[l, i] is 1 if the rule
    LAruleno[l] is applicable in the appropriate state when the next
Index: src/output.c
--- src/output.c Wed, 03 Apr 2002 23:01:52 +0200 akim
+++ src/output.c Thu, 04 Apr 2002 19:29:34 +0200 akim
@@ -348,7 +348,7 @@
          /* and record this rule as the rule to use if that
             token follows.  */
          if (bitset_test (LA[state->lookaheadsp + i], j))
-           actrow[j] = -LAruleno[state->lookaheadsp + i];
+           actrow[j] = -LArule[state->lookaheadsp + i]->number;
     }
 
   /* Now see which tokens are allowed for shifts in this state.  For
@@ -395,7 +395,7 @@
          for (i = 0; i < state->nlookaheads; i++)
            {
              int count = 0;
-             int rule = -LAruleno[state->lookaheadsp + i];
+             int rule = -LArule[state->lookaheadsp + i]->number;
              int j;
 
              for (j = 0; j < ntokens; j++)
@@ -918,7 +918,7 @@
 
   token_actions ();
   bitsetv_free (LA);
-  XFREE (LAruleno);
+  free (LArule);
 
   goto_actions ();
   XFREE (goto_map + ntokens);
Index: src/print.c
--- src/print.c Mon, 25 Mar 2002 21:34:54 +0100 akim
+++ src/print.c Thu, 04 Apr 2002 19:25:10 +0200 akim
@@ -1,5 +1,6 @@
 /* Print information on generated parser, for bison,
-   Copyright 1984, 1986, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002
+   Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -213,24 +214,26 @@
 
   if (state->nlookaheads == 1 && !nodefault)
     {
-      int default_rule = LAruleno[state->lookaheadsp];
+      rule_t *default_rule = LArule[state->lookaheadsp];
 
       bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
 
       for (i = 0; i < ntokens; i++)
        if (bitset_test (lookaheadset, i))
          fprintf (out, _("    %-4s\t[reduce using rule %d (%s)]\n"),
-                  escape (symbols[i]->tag), default_rule - 1,
-                  escape2 (rules[default_rule].lhs->tag));
+                  escape (symbols[i]->tag),
+                  default_rule->number - 1,
+                  escape2 (default_rule->lhs->tag));
 
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
-              default_rule - 1, escape (rules[default_rule].lhs->tag));
+              default_rule->number - 1,
+              escape (default_rule->lhs->tag));
     }
   else if (state->nlookaheads >= 1)
     {
       int cmax = 0;
       int default_LA = -1;
-      int default_rule = 0;
+      rule_t *default_rule = NULL;
 
       if (!nodefault)
        for (i = 0; i < state->nlookaheads; ++i)
@@ -248,7 +251,7 @@
              {
                cmax = count;
                default_LA = state->lookaheadsp + i;
-               default_rule = LAruleno[state->lookaheadsp + i];
+               default_rule = LArule[state->lookaheadsp + i];
              }
 
            bitset_or (shiftset, shiftset, lookaheadset);
@@ -275,8 +278,8 @@
                      fprintf (out,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
-                              LAruleno[state->lookaheadsp + j] - 1,
-                              escape2 (rules[LAruleno[state->lookaheadsp + 
j]].lhs->tag));
+                              LArule[state->lookaheadsp + j]->number - 1,
+                              escape2 (LArule[state->lookaheadsp + 
j]->lhs->tag));
                    else
                      defaulted = 1;
 
@@ -288,22 +291,22 @@
                      fprintf (out,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
-                              LAruleno[default_LA] - 1,
-                              escape2 (rules[LAruleno[default_LA]].lhs->tag));
+                              LArule[default_LA]->number - 1,
+                              escape2 (LArule[default_LA]->lhs->tag));
                    defaulted = 0;
                    fprintf (out,
                             _("    %-4s\t[reduce using rule %d (%s)]\n"),
                             escape (symbols[i]->tag),
-                            LAruleno[state->lookaheadsp + j] - 1,
-                            escape2 (rules[LAruleno[state->lookaheadsp + 
j]].lhs->tag));
+                            LArule[state->lookaheadsp + j]->number - 1,
+                            escape2 (LArule[state->lookaheadsp + 
j]->lhs->tag));
                  }
              }
        }
 
       if (default_LA >= 0)
        fprintf (out, _("    $default\treduce using rule %d (%s)\n"),
-                default_rule - 1,
-                escape (rules[default_rule].lhs->tag));
+                default_rule->number - 1,
+                escape (default_rule->lhs->tag));
     }
 }
 



reply via email to

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