def concat(self, n1, n2): s = self.new_state() m = self.new_state() e = self.new_state() nfa = NFA(s) nfa.insert(s, n1, m) nfa.insert(m, n2, e) nfa.add_final_state(e) return nfa
def concat(self, n1, n2): s = self.new_state() m = self.new_state() e = self.new_state() nfa = NFA(s) nfa.insert(s, n1, m) nfa.insert(m, n2, e) nfa.add_final_state(e) return nfa
def star(self, n): s = self.new_state() m1 = self.new_state() m2 = self.new_state() e = self.new_state() nfa = NFA(s) nfa.add_transition(s, EPSILON, m1) nfa.add_transition(s, EPSILON, e) nfa.insert(m1, n, m2) nfa.add_transition(m2, EPSILON, m1) nfa.add_transition(m2, EPSILON, e) nfa.add_final_state(e) return nfa
def star(self, n): s = self.new_state() m1 = self.new_state() m2 = self.new_state() e = self.new_state() nfa = NFA(s) nfa.add_transition(s, EPSILON, m1) nfa.add_transition(s, EPSILON, e) nfa.insert(m1, n, m2) nfa.add_transition(m2, EPSILON, m1) nfa.add_transition(m2, EPSILON, e) nfa.add_final_state(e) return nfa
def choice(self, n1, n2): s = self.new_state() s1 = self.new_state() s2 = self.new_state() e1 = self.new_state() e2 = self.new_state() e = self.new_state() nfa = NFA(s) nfa.add_transition(s, EPSILON, s1) nfa.add_transition(s, EPSILON, s2) nfa.insert(s1, n1, e1) nfa.insert(s2, n2, e2) nfa.add_transition(e1, EPSILON, e) nfa.add_transition(e2, EPSILON, e) nfa.add_final_state(e) return nfa
def choice(self, n1, n2): s = self.new_state() s1 = self.new_state() s2 = self.new_state() e1 = self.new_state() e2 = self.new_state() e = self.new_state() nfa = NFA(s) nfa.add_transition(s, EPSILON, s1) nfa.add_transition(s, EPSILON, s2) nfa.insert(s1, n1, e1) nfa.insert(s2, n2, e2) nfa.add_transition(e1, EPSILON, e) nfa.add_transition(e2, EPSILON, e) nfa.add_final_state(e) return nfa