def to_afd(self): af = automato_finito.AutomatoFinito() af.inicial = self.arvore.value final = '#' alfabeto = self.expr.lstrip('+|*?()') positions = () Dstates = set()
def to_afnd(self): af = automato_finito.AutomatoFinito() final = '_F_' af.estados = self.variaveis.union((final, )) af.inicial = self.inicial af.finais.add(final) for v in self.variaveis: for e in self.transicoes[v]: if e[0] == '&' and e[1] == '&': af.finais.add(v) elif e[0] != '&' and e[1] == '&': if (v, e[0]) in af.transicoes.keys(): af.transicoes[(v, e[0])].append(final) else: af.transicoes[(v, e[0])] = [final] else: if (v, e[0]) in af.transicoes.keys(): af.transicoes[(v, e[0])].append(e[1]) else: af.transicoes[(v, e[0])] = [e[1]] return af
while t_input[0] != 'exit': if mode == 0: print('Menu inicial') t_input = input().split() l = len(t_input) if mode == 0 and l > 0: if t_input[0] == 'help': print('new [af|gr|er] [nome]') print('edit [af|gr|er] [nome]') print('del [af|gr|er] [nome]') print('list') continue elif t_input[0] == 'new' and l > 2: ling = None if t_input[1] == 'af': ling = automato_finito.AutomatoFinito(t_input[2]) if t_input[1] == 'gr': ling = gramatica_regular.GramaticaRegular(t_input[2]) if t_input[1] == 'er': ling = expressao_regular.ExpressaoRegular(nome=t_input[2]) listas[t_input[1]].append(ling) t_open = t_input[1] n_open = len(listas[t_open]) - 1 nome_dict[(t_open, t_input[2])] = n_open mode = 1 continue elif t_input[0] == 'edit' and l > 2: t_open = t_input[1] n_open = nome_dict[(t_open, t_input[2])] mode = 1 continue
import automato_finito af = automato_finito.AutomatoFinito() af.add_transicao('q0', 'a', 'q0') af.add_transicao('q0', 'a', 'q1') af.add_transicao('q1', 'b', 'qf') af.add_estados_finais('qf') af.set_estado_inicial('q0') print('Automato teste1') print(af.print()) print('Automato teste1 após determinização') print(af.to_afd(0, {}).print())
import automato_finito af1 = automato_finito.AutomatoFinito() af2 = automato_finito.AutomatoFinito() af1.add_transicao('q0', 'a', 'qf') af1.add_transicao('qf', 'b', 'qf') af1.add_transicao('qf', 'a', 'qf') af1.add_estados_finais('qf') af1.set_estado_inicial('q0') af2.add_transicao('q0', 'a', 'q1') af2.add_transicao('q1', 'b', 'q2') af2.add_transicao('q2', 'b', 'q3') af2.add_transicao('q3', 'a', 'qf') af2.add_transicao('qf', 'a', 'qf') af2.add_estados_finais('qf') af2.set_estado_inicial('q0') print('Automato 1 teste6 (a(a|b)*)') print(af1.print()) print('Automato 2 teste6 (abba*)') print(af2.print()) print('Automato 1 Intersecao Automato 2 (abba*): \n') print(af1.intersecao(af2).print())