bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/4] ielr: make some conditions about items easier to understand


From: Akim Demaille
Subject: [PATCH 2/4] ielr: make some conditions about items easier to understand
Date: Tue, 10 Nov 2020 07:10:26 +0100

Checking that an item index is > 1 means ruling out `$accept: • input
$end` and `$accept: input • $end`.  But actually only the latter is
possible there, i.e., we're checking whether this item is about a
successor of a (kernel) item of the initial state ($accept: input •
$end).

* src/ielr.c (is_successor_of_initial_item): Use a variable to name
this condition.
---
 src/ielr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/ielr.c b/src/ielr.c
index 26754a72..9490ec72 100644
--- a/src/ielr.c
+++ b/src/ielr.c
@@ -413,7 +413,10 @@ ielr_item_has_lookahead (state *s, symbol_number lhs, 
size_t item,
          didn't change this test to an aver just in case the usage of this
          function evolves to need those two cases.  In both cases, the current
          implementation returns the right result.  */
-      if (s->items[item] > 1)
+      aver (s->items[item] != 1);
+      const bool is_successor_of_initial_item = s->items[item] <= 1;
+      aver (!is_successor_of_initial_item);
+      if (!is_successor_of_initial_item)
         {
           /* If the LHS symbol of this item isn't known (because this is a
              top-level invocation), go get it.  */
@@ -622,9 +625,11 @@ ielr_compute_lookaheads (bitsetv follow_kernel_items, 
bitsetv always_follows,
          a special case to avoid the - 2 below, but the next successor can be
          handled fine without special casing it.  */
       aver (t->items[t_item] != 0);
-      if (t->items[t_item] > 1
+      const bool is_successor_of_initial_item = t->items[t_item] <= 1;
+      if (!is_successor_of_initial_item
           && !bitset_empty_p (lookahead_filter[t_item]))
         {
+          /* Is this kernel item next to the beginning of the RHS?  */
           if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
             ielr_compute_goto_follow_set (
               follow_kernel_items, always_follows, s,
-- 
2.29.2




reply via email to

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