def make_automaton(self): dfas = [reg.make_automaton().make_deterministic() for reg in self.regs] [dfa.optimize() for dfa in dfas] nfas = [dfa.make_nondeterministic() for dfa in dfas] result_nfa = NFA() start_state = result_nfa.add_state(start=True) for i, nfa in enumerate(nfas): final_state = result_nfa.add_state(self.names[i], final=True, unmergeable=True) state_map = {} for j, name in enumerate(nfa.names): start = j in nfa.start_states final = j in nfa.final_states newstate = result_nfa.add_state(name) state_map[j] = newstate if start: result_nfa.add_transition(start_state, newstate) if final: result_nfa.add_transition(newstate, final_state) for state, subtransitions in nfa.transitions.iteritems(): for input, states in subtransitions.iteritems(): newstate = state_map[state] newstates = [state_map[s] for s in states] for newtargetstate in newstates: result_nfa.add_transition( newstate, newtargetstate, input) return result_nfa
def make_automaton(self): nfa = NFA() startstate = nfa.add_state(start=True) finalstate = nfa.add_state(final=True) for i in range(ord(self.fromchar), ord(self.tochar) + 1): char = chr(i) nfa.add_transition(startstate, finalstate, char) return nfa
def make_automaton(self): nfa = NFA() firstfinal = not self.string state = nfa.add_state(start=True, final=firstfinal) for i, char in enumerate(self.string): final = i == len(self.string) - 1 next_state = nfa.add_state(final=final) nfa.add_transition(state, next_state, char) state = next_state return nfa
def make_automaton(self): dfas = [reg.make_automaton().make_deterministic() for reg in self.regs] [dfa.optimize() for dfa in dfas] nfas = [dfa.make_nondeterministic() for dfa in dfas] result_nfa = NFA() start_state = result_nfa.add_state(start=True) for i, nfa in enumerate(nfas): final_state = result_nfa.add_state(self.names[i], final=True, unmergeable=True) state_map = {} for j, name in enumerate(nfa.names): start = j in nfa.start_states final = j in nfa.final_states newstate = result_nfa.add_state(name) state_map[j] = newstate if start: result_nfa.add_transition(start_state, newstate) if final: result_nfa.add_transition(newstate, final_state) for state, subtransitions in nfa.transitions.iteritems(): for input, states in subtransitions.iteritems(): newstate = state_map[state] newstates = [state_map[s] for s in states] for newtargetstate in newstates: result_nfa.add_transition(newstate, newtargetstate, input) return result_nfa