def visit_concat(self, rs): result = [concats(rs[:-1] + [rs[-1].accept(self)])] for i in range(len(rs) - 1, 0, -1): if not rs[i].is_nullable(): break result.append(concats(rs[:i - 1] + [rs[i - 1].accept(self)])) return alternatives(result)
def init_table(self): table = {} for qi in self.nfa.states: for qj in self.nfa.states: rs = set(single(c) for c in self.get_labels_from_to(qi, qj)) if qi == qj: rs.add(epsilon()) table[(qi, qj)] = alternatives(rs) return table
def step(self, table, qk): newtable = {} for q1 in self.nfa.states: for q2 in self.nfa.states: ov = table[(q1, q2)] rl = table[(q1, qk)] rrep = table[(qk, qk)] rr = table[(qk, q2)] newtable[(q1, q2)] = alternatives(ov, concats(rl, star(rrep), rr)) return newtable
def step(self, table, qk): new = {} for qi in self.nfa.states: for qj in self.nfa.states: rij = table[(qi, qj)] rik = table[(qi, qk)] rkj = table[(qk, qj)] rkk = table[(qk, qk)] rij_new = alternatives( rij, concats(rik, star(rkk), rkj)) new[(qi, qj)] = rij_new return new
def init_table(self): table = {} for q1 in self.nfa.states: for q2 in self.nfa.states: labels = [ single(i.label) for i in self.nfa.transitions if i.start == q1 and i.end == q2 ] if q1 == q2: labels = labels + [epsilon()] if labels == []: table[(q1, q2)] = empty() else: table[(q1, q2)] = alternatives(labels) return table
def visit_alternative(self, rs): return alternatives(r.accept(self) for r in rs)
def compute_result(self, table): q0 = self.nfa.start_state return alternatives(table[(q0, q)] for q in nfa.final_states)
def compute_result(self, table): start = self.nfa.start_state ends = self.nfa.final_states return alternatives([table[(start, i)] for i in ends])