bison-patches
[Top][All Lists]
Advanced

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

Re: consistent states and error transitions


From: Joel E. Denny
Subject: Re: consistent states and error transitions
Date: Mon, 28 May 2007 00:14:32 -0400 (EDT)

On Sun, 27 May 2007, Joel E. Denny wrote:

> On Sun, 27 May 2007, Paul Eggert wrote:
> 
> > The change looks OK to me, not that I've thought it through as
> > carefully as you have.

> > However, shouldn't there also be a change to
> > the comment for 'consistent'?  Currently it says:

> How does the following sound?
> 
>   /* If non-zero, then no lookahead sets on reduce actions are needed to 
>      decide what to do in state S.  */
>   char consistent;

I committed the following, which includes all the above.  Of course, I'm 
glad to revise if this discussion determines that further improvement is 
needed.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1703
diff -p -u -r1.1703 ChangeLog
--- ChangeLog   28 May 2007 01:09:11 -0000      1.1703
+++ ChangeLog   28 May 2007 04:05:57 -0000
@@ -1,3 +1,27 @@
+2007-05-28  Joel E. Denny  <address@hidden>
+
+       * src/lalr.c (state_lookahead_tokens_count): For code readability,
+       move the check for disabled transitions to an aver since conflict
+       resolution hasn't happened yet.
+
+       * src/lalr.c (state_lookahead_tokens_count): Remove the check that
+       labels a state as inconsistent just because it has error transitions.
+       The original form of this check appeared in revision 1.1 of lalr.c,
+       which was committed on 1991-12-21.  Now (at least), changing the
+       consistency label on such a state appears to have no useful effect in
+       any of the places it is examined, which I enumerate below.  The key
+       point to understanding each item in this enumeration is that a state
+       with an error transition is labelled consistent in the first place only
+       if it has no rules, so the check cannot matter for states that have
+       rules.  (1) Labelling a state as inconsistent will cause set_conflicts
+       to try to identify its conflicts, and a state must have *rules* to have
+       conflicts.  (2) Labelling a state as inconsistent will affect how
+       action_row sets the default *rule* for the state.  (3) Labelling a
+       state as inconsistent will cause build_relations to add lookback edges
+       to *rules* in that state.
+       * src/state.h (struct state): Word the comment for member consistent
+       more carefully.
+
 2007-05-27  Joel E. Denny  <address@hidden>
 
        Don't depend on C99 features.
Index: src/lalr.c
===================================================================
RCS file: /sources/bison/bison/src/lalr.c,v
retrieving revision 1.114
diff -p -u -r1.114 lalr.c
--- src/lalr.c  28 May 2007 01:09:11 -0000      1.114
+++ src/lalr.c  28 May 2007 04:05:57 -0000
@@ -340,7 +340,6 @@ compute_lookahead_tokens (void)
 static int
 state_lookahead_tokens_count (state *s)
 {
-  int k;
   int n_lookahead_tokens = 0;
   reductions *rp = s->reductions;
   transitions *sp = s->transitions;
@@ -348,21 +347,17 @@ state_lookahead_tokens_count (state *s)
   /* We need a lookahead either to distinguish different
      reductions (i.e., there are two or more), or to distinguish a
      reduction from a shift.  Otherwise, it is straightforward,
-     and the state is `consistent'.  */
+     and the state is `consistent'.  There is no need to check that
+     transition 0 hasn't been disabled before checking if it is a
+     shift since transitions are only disabled during conflict
+     resolution, and that hasn't happened yet.  */
+  aver (sp->num == 0 || !TRANSITION_IS_DISABLED (sp, 0));
   if (rp->num > 1
-      || (rp->num == 1 && sp->num &&
-         !TRANSITION_IS_DISABLED (sp, 0) && TRANSITION_IS_SHIFT (sp, 0)))
+      || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)))
     n_lookahead_tokens += rp->num;
   else
     s->consistent = 1;
 
-  for (k = 0; k < sp->num; k++)
-    if (!TRANSITION_IS_DISABLED (sp, k) && TRANSITION_IS_ERROR (sp, k))
-      {
-       s->consistent = 0;
-       break;
-      }
-
   return n_lookahead_tokens;
 }
 
Index: src/state.h
===================================================================
RCS file: /sources/bison/bison/src/state.h,v
retrieving revision 1.54
diff -p -u -r1.54 state.h
--- src/state.h 28 May 2007 01:09:11 -0000      1.54
+++ src/state.h 28 May 2007 04:05:57 -0000
@@ -202,7 +202,8 @@ struct state
   reductions *reductions;
   errs *errs;
 
-  /* Nonzero if no lookahead is needed to decide what to do in state S.  */
+  /* If non-zero, then no lookahead sets on reduce actions are needed to
+     decide what to do in state S.  */
   char consistent;
 
   /* If some conflicts were solved thanks to precedence/associativity,




reply via email to

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