bison-patches
[Top][All Lists]
Advanced

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

05-fyi-nstates.patch


From: Akim Demaille
Subject: 05-fyi-nstates.patch
Date: Thu, 27 Dec 2001 18:58:06 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        All the hacks using a final pseudo state are now useless.

        * src/LR0.c (set_state_table): state_table holds exactly nstates.
        * src/lalr.c (nLA): New.
        (initialize_LA, compute_lookaheads, initialize_lookaheads): Use it
        instead of lookaheadsp from the pseudo state (nstate + 1).

Index: src/LR0.c
--- src/LR0.c Sun, 09 Dec 2001 11:48:23 +0100 akim
+++ src/LR0.c Wed, 26 Dec 2001 18:08:57 +0100 akim
@@ -541,10 +541,7 @@
 static void
 set_state_table (void)
 {
-  /* NSTATES + 1 because lookahead for the pseudo state number NSTATES
-     might be used (see conflicts.c).  It is too opaque for me to
-     provide a probably less hacky implementation. --akim */
-  state_table = XCALLOC (state_t *, nstates + 1);
+  state_table = XCALLOC (state_t *, nstates);

   {
     state_t *sp;
Index: src/lalr.c
--- src/lalr.c Wed, 26 Dec 2001 16:56:38 +0100 akim
+++ src/lalr.c Wed, 26 Dec 2001 17:38:30 +0100 akim
@@ -33,14 +33,13 @@
 #include "derives.h"
 #include "getargs.h"

-/* All the decorated states, indexed by the state number.  Warning:
-   there is a state_TABLE in LR0.c, but it is different and static.
-   */
+/* All the decorated states, indexed by the state number.  */
 state_t **state_table = NULL;

 int tokensetsize;
 short *LAruleno;
 unsigned *LA;
+size_t nLA;

 static int ngotos;
 short *goto_map;
@@ -140,7 +139,7 @@
   short *np;
   reductions *rp;

-  size_t nLA = state_table[nstates]->lookaheadsp;
+  /* Avoid having to special case 0.  */
   if (!nLA)
     nLA = 1;

@@ -504,10 +503,10 @@
 static void
 compute_lookaheads (void)
 {
-  int i;
+  size_t i;
   shorts *sp;

-  for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
+  for (i = 0; i < nLA; i++)
     for (sp = lookback[i]; sp; sp = sp->next)
       {
        int size = LA (i + 1) - LA (i);
@@ -517,7 +516,7 @@
       }

   /* Free LOOKBACK. */
-  for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
+  for (i = 0; i < nLA; i++)
     LIST_FREE (shorts, lookback[i]);

   XFREE (lookback);
@@ -533,7 +532,7 @@
 initialize_lookaheads (void)
 {
   int i;
-  int count = 0;
+  nLA = 0;
   for (i = 0; i < nstates; i++)
     {
       int k;
@@ -555,13 +554,9 @@
          }

       state_table[i]->nlookaheads = nlookaheads;
-      state_table[i]->lookaheadsp = count;
-      count += nlookaheads;
+      state_table[i]->lookaheadsp = nLA;
+      nLA += nlookaheads;
     }
-
-  /* Seems to be needed by conflicts.c. */
-  state_table[nstates] = STATE_ALLOC (0);
-  state_table[nstates]->lookaheadsp = count;
 }

 void



reply via email to

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