def _construct_prefix_minimal_dfa(self, postfix_minimal_dfa): self.dfa = postfix_minimal_dfa.simplify() reversed_nfa = self.reverse() nfa2dfa = NFA2DFA(reversed_nfa) minimal_dfa = nfa2dfa.convert() return minimal_dfa
def compile(self, pattern, use_dfa=False): lexer = Lexer(pattern) lexer.analyse() parser = Parser(lexer) postfix_expr = parser.parse() nfa_stack = TokenToNFA(postfix_expr).translate() if len(nfa_stack) != 1: raise PatternSyntaxError automaton = nfa_stack[0] if use_dfa: nfa2dfa = NFA2DFA(automaton) automaton = nfa2dfa.convert() return automaton
import MicroRegEx from MicroRegEx.Automaton.NFA2DFA import NFA2DFA nfa = MicroRegEx.compile("(a|b)c?") dfa = NFA2DFA(nfa).convert() dfa.plot()
import MicroRegEx from MicroRegEx.Automaton.NFA2DFA import NFA2DFA nfa = MicroRegEx.compile("(a|b)c?") dfa = NFA2DFA(nfa).convert().simplify() dfa.plot()
def _construct_postfix_minimal_dfa(self): reversed_nfa = self.reverse() nfa2dfa = NFA2DFA(reversed_nfa) postfix_minimal_dfa = nfa2dfa.convert() return postfix_minimal_dfa