예제 #1
0
파일: regex.py 프로젝트: Debug-Orz/Sypy
 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
예제 #2
0
 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
예제 #3
0
파일: regex.py 프로젝트: Debug-Orz/Sypy
 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
예제 #4
0
 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
예제 #5
0
파일: regex.py 프로젝트: Debug-Orz/Sypy
 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
예제 #6
0
 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