bison-patches
[Top][All Lists]
Advanced

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

14-fyi-private-first-state.patch


From: Akim Demaille
Subject: 14-fyi-private-first-state.patch
Date: Mon, 10 Dec 2001 09:36:24 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/lalr.c (set_state_table): Move to...
        * src/LR0.c: here.
        * src/lalr.c (lalr): Don't call it...
        * src/LR0.c (generate_states): do it.
        * src/LR0.h (first_state): Remove, only the table is used.
        
        
Index: src/LR0.c
--- src/LR0.c Sat, 08 Dec 2001 19:06:46 +0100 akim
+++ src/LR0.c Sat, 08 Dec 2001 20:48:19 +0100 akim
@@ -35,8 +35,8 @@
 
 int nstates;
 int final_state;
-state_t *first_state = NULL;
-shifts *first_shift = NULL;
+static state_t *first_state = NULL;
+static shifts *first_shift = NULL;
 
 static state_t *this_state = NULL;
 static state_t *last_state = NULL;
@@ -601,6 +601,67 @@
 }
 
 
+/*--------------------.
+| Build STATE_TABLE.  |
+`--------------------*/
+
+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_t *sp;
+    for (sp = first_state; sp; sp = sp->next)
+      state_table[sp->number] = sp;
+  }
+
+  /* Pessimization, but simplification of the code: make sure all the
+     states have a shifts, even if reduced to 0 shifts.  */
+  {
+    int i;
+    for (i = 0; i < nstates; i++)
+      if (!state_table[i]->shifts)
+       state_table[i]->shifts = shifts_new (0);
+  }
+
+  /* Initializing the lookaheads members.  Please note that it must be
+     performed after having set some of the other members which are
+     used below.  Change with extreme caution.  */
+  {
+    int i;
+    int count = 0;
+    for (i = 0; i < nstates; i++)
+      {
+       int k;
+       reductions *rp = state_table[i]->reductions;
+       shifts *sp = state_table[i]->shifts;
+
+       state_table[i]->lookaheads = count;
+
+       if (rp
+           && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
+         count += rp->nreds;
+       else
+         state_table[i]->consistent = 1;
+
+       for (k = 0; k < sp->nshifts; k++)
+         if (SHIFT_IS_ERROR (sp, k))
+           {
+             state_table[i]->consistent = 0;
+             break;
+           }
+      }
+
+    /* Seems to be needed by conflicts.c. */
+    state_table[nstates] = STATE_ALLOC (0);
+    state_table[nstates]->lookaheads = count;
+  }
+}
+
 /*-------------------------------------------------------------------.
 | Compute the nondeterministic finite state machine (see state.h for |
 | details) from the grammar.                                         |
@@ -644,4 +705,7 @@
 
   /* set up initial and final states as parser wants them */
   augment_automaton ();
+
+  /* Set up STATE_TABLE. */
+  set_state_table ();
 }
Index: src/LR0.h
--- src/LR0.h Sat, 08 Dec 2001 20:35:55 +0100 akim
+++ src/LR0.h Sat, 08 Dec 2001 20:39:48 +0100 akim
@@ -27,6 +27,5 @@
 
 extern int nstates;
 extern int final_state;
-extern state_t *first_state;
 
 #endif /* !LR0_H_ */
Index: src/lalr.c
--- src/lalr.c Sat, 08 Dec 2001 20:35:55 +0100 akim
+++ src/lalr.c Sat, 08 Dec 2001 20:39:05 +0100 akim
@@ -132,68 +132,6 @@
 }
 
 
-/*--------------------.
-| Build STATE_TABLE.  |
-`--------------------*/
-
-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_t *sp;
-    for (sp = first_state; sp; sp = sp->next)
-      state_table[sp->number] = sp;
-  }
-
-  /* Pessimization, but simplification of the code: make sure all the
-     states have a shifts, even if reduced to 0 shifts.  */
-  {
-    int i;
-    for (i = 0; i < nstates; i++)
-      if (!state_table[i]->shifts)
-       state_table[i]->shifts = shifts_new (0);
-  }
-
-  /* Initializing the lookaheads members.  Please note that it must be
-     performed after having set some of the other members which are
-     used below.  Change with extreme caution.  */
-  {
-    int i;
-    int count = 0;
-    for (i = 0; i < nstates; i++)
-      {
-       int k;
-       reductions *rp = state_table[i]->reductions;
-       shifts *sp = state_table[i]->shifts;
-
-       state_table[i]->lookaheads = count;
-
-       if (rp
-           && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
-         count += rp->nreds;
-       else
-         state_table[i]->consistent = 1;
-
-       for (k = 0; k < sp->nshifts; k++)
-         if (SHIFT_IS_ERROR (sp, k))
-           {
-             state_table[i]->consistent = 0;
-             break;
-           }
-      }
-
-    /* Seems to be needed by conflicts.c. */
-    state_table[nstates] = STATE_ALLOC (0);
-    state_table[nstates]->lookaheads = count;
-  }
-}
-
-
 static void
 initialize_LA (void)
 {
@@ -601,7 +539,6 @@
 {
   tokensetsize = WORDSIZE (ntokens);
 
-  set_state_table ();
   initialize_LA ();
   set_goto_map ();
   initialize_F ();



reply via email to

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