eob_state = len(_dfa.start_action)
# state 0 is the jam state, make it exist but have empty acclist
- self.acclist = numpy.zeros((0x100,), numpy.int16)
+ self.acclist = numpy.zeros((0x100,), numpy.uint16)
n_acclist = 0
- self.accept = numpy.zeros((0x100,), numpy.int16)
+ self.accept = numpy.zeros((0x100,), numpy.uint16)
n_states = 1
# transitions[i, j] is transition on character j in state i
# however, in the flex way these are both 0 (don't care),
# the distinction being that failure has no associated action
# thus all entries of states are filled, with 0 as a catch-all
- transitions = numpy.zeros((0x100, 0x101), numpy.int16)
+ transitions = numpy.zeros((0x100, 0x101), numpy.uint16)
# generate acclist, accept and transition tables
while n_states < len(flex_state_to_action):
# extend accept
new_accept = numpy.zeros(
(self.accept.shape[0] * 2,),
- numpy.int16
+ numpy.uint16
)
new_accept[:self.accept.shape[0]] = self.accept
self.accept = new_accept
# extend acclist
new_acclist = numpy.zeros(
(self.acclist.shape[0] * 2,),
- numpy.int16
+ numpy.uint16
)
new_acclist[:self.acclist.shape[0]] = self.acclist
self.acclist = new_acclist
# extend transitions
new_transitions = numpy.zeros(
(transitions.shape[0] * 2, 0x101),
- numpy.int16
+ numpy.uint16
)
new_transitions[:transitions.shape[0], :] = transitions
transitions = new_transitions
if n_states >= self.accept.shape[0]:
new_accept = numpy.zeros(
(self.accept.shape[0] * 2,),
- numpy.int16
+ numpy.uint16
)
new_accept[:self.accept.shape[0]] = self.accept
self.accept = new_accept
# calculate default states by constructing minimum spanning tree
# heap contains n states todo followed by n_states - n states done
# each heap entry is [distance, hop count, state done, state todo]
- heap = numpy.zeros((n_states, 4), numpy.int16)
+ heap = numpy.zeros((n_states, 4), numpy.uint16)
heap[:-1, 0] = numpy.sum(transitions[1:, :] != transitions[:1, :], 1)
- heap[:-1, 3] = numpy.arange(1, n_states, dtype = numpy.int16)
+ heap[:-1, 3] = numpy.arange(1, n_states, dtype = numpy.uint16)
numpy_heap.heapify(heap, n_states - 1)
for n in range(n_states - 2, 0, -1):
if n % 100 == 0:
numpy_heap.bubble_up(heap, i, key)
# state 0 is the jam state, the EOB state will be added later on
- self.states = numpy.zeros((n_states, 2), numpy.int16) # base, def
- self.entries = numpy.full((0x200, 2), -1, numpy.int16) # nxt, chk
+ self.states = numpy.zeros((n_states, 2), numpy.uint16) # base, def
+ self.entries = numpy.full((0x200, 2), -1, numpy.uint16) # nxt, chk
self.entries[:0x101, :] = 0 # jam state just returns to jam state
self.entries[0, 0] = eob_state # except for the EOB transition
entries_free = numpy.full(0x200, True, numpy.bool)
new_entries = numpy.full(
(self.entries.shape[0] * 2, 2),
-1,
- numpy.int16
+ numpy.uint16
)
new_entries[:n_entries, :] = self.entries[:n_entries, :]
self.entries = new_entries
fout.write(
'''/* GENERATE TABLES BEGIN */
#define YY_END_OF_BUFFER {0:d}
-static const flex_int16_t yy_acclist[] = {{{1:s}
+static const flex_uint16_t yy_acclist[] = {{{1:s}
}};
-static const flex_int16_t yy_accept[] = {{{2:s}
+static const flex_uint16_t yy_accept[] = {{{2:s}
}};
-static const flex_int16_t yy_base[] = {{{3:s}
+static const flex_uint16_t yy_base[] = {{{3:s}
}};
-static const flex_int16_t yy_def[] = {{{4:s}
+static const flex_uint16_t yy_def[] = {{{4:s}
}};
-static const flex_int16_t yy_nxt[] = {{{5:s}
+static const flex_uint16_t yy_nxt[] = {{{5:s}
}};
-static const flex_int16_t yy_chk[] = {{{6:s}
+static const flex_uint16_t yy_chk[] = {{{6:s}
}};
/* GENERATE TABLES END */
'''.format(