def inicia(self): case = 0 lex = Lex() # # 1 ER PALAVRAS RESERVADAS a1 = lex.lexer('reservado', case) dict = a1.getDictAutomato() case += len(dict) # # 2 ER IDENTIFICADORES a2 = lex.lexer('identificadores', case) # # 3 GRAMATICA DE SESPECIAL terminais = ['+', '-', '=', '/', '*', '>', '<', '!'] nTerminais = ['S'] producoes = {'S': ['+', '-', '=', '/', '*', '>', '<', '!']} inicial = 'S' g = Grammar(producoes,terminais, nTerminais, inicial) s, i, f = g.convertGtoAF() a3 = Automato(s, i, f) a3.determina() a3.printAtomato() print("\n") dict = a2.getDictAutomato() case += len(dict) a3 = lex.renameState(a3, case) # # 4 GRAMATICA SEPARADORES terminais2 = [':',';', ' ', '(', ')', '[', ']', ',', '\n'] nTerminais2 = ['S'] producoes2 = {'S': [':',';', ' ', '(', ')', '[', ']', ',', '\n']} inicial2 = 'S' g = Grammar(producoes2,terminais2, nTerminais2, inicial2) s2, i2, f2 = g.convertGtoAF() a4 = Automato(s2, i2, f2) a4.determina() a4.printAtomato() print("\n") dict = a3.getDictAutomato() case += len(dict) a4 = lex.renameState(a4, case) # ER CONSTANTES dict = a4.getDictAutomato() case += len(dict) a5 = lex.lexer('constantes', case) r = a5 r = a1.oU([a2, a3, a4, a5]) print ("\n") r.determina() r.printAtomato() with open('automato.pkl', 'wb') as output: pickle.dump(r, output, pickle.HIGHEST_PROTOCOL)
def gramaticaAutomato(input): input = entrytext.get() l = LeitorG(input) dict, termi,nonter,ini = l.ler() g = Grammar(dict,termi,nonter,ini) s, inicial, final = g.convertGtoAF() a = Automato(s,inicial,final) a.printAtomato() a.writeAutomataToFile(input) input = input.replace('.in', '') data_file = open('../testes/'+input+'.out') data = data_file.read() data_file.close() test = Tk.Tk() Results = Tk.Label(test, text = data) Results.grid(row = 20, column = 3, sticky= Tk.W)