def build_myt(regex): MYTState.count = 0 postfix = to_postfix(regex) stack = [] for ch in postfix: if ch.isalpha(): stack.append(SymbolMYT(ch)) elif ch == '*': top = stack.pop() stack.append(StarMYT(top)) else: rhs = stack.pop() lhs = stack.pop() if ch == '|': stack.append(UnionMYT(lhs, rhs)) elif ch == '.': stack.append(ConcatMYT(lhs, rhs))
return stack[0]
评论