Fix default reduction offset by 2 issue, parser now avoids useless lookahead
authorNick Downing <downing.nick@gmail.com>
Fri, 6 Jul 2018 12:22:17 +0000 (22:22 +1000)
committerNick Downing <downing.nick@gmail.com>
Fri, 6 Jul 2018 12:23:00 +0000 (22:23 +1000)
bison_lr1dfa.py

index e1f3fe2..43ecf10 100644 (file)
@@ -102,8 +102,9 @@ class BisonLR1DFA:
       )[numpy.newaxis, numpy.newaxis, :],
       0
     )
-    self.accessing_symbols = numpy.zeros(
+    self.accessing_symbols = numpy.full(
       (len(lr1dfa.states),),
+      2, # '$undefined'
       numpy.int16
     )
     for i in range(1, len(lr1dfa.states)):
@@ -127,7 +128,7 @@ class BisonLR1DFA:
             (
               action_table[:, :, numpy.newaxis] ==
               numpy.arange(
-                1,
+                -1,
                 -len(lr1dfa.productions),
                 -1,
                 dtype = numpy.int16
@@ -140,6 +141,8 @@ class BisonLR1DFA:
       ),
       1
     )
+    #print(action_table)
+    #print(self.default_action)
     self.default_goto = numpy.argmax(
       numpy.concatenate(
         [
@@ -160,12 +163,16 @@ class BisonLR1DFA:
       ),
       1
     )
+    #print(goto_table)
+    #print(self.default_goto)
 
     # fill in the zero entries in the tables with default reduce or goto
     for i in range(len(lr1dfa.states)):
       action_table[i, action_table[i, :] == 0] = -self.default_action[i]
     for i in range(n_nonterminals):
       goto_table[i, goto_table[i, :] == 0] = self.default_goto[i]
+    #print(action_table)
+    #print(goto_table)
 
     # entry_base indicates the most negative starting index we can expect
     # we maintain entry_size such that entry_used[entry_size:, :] == False