def analizar(self): if self.tipoArchivo == ".html": Lexico.lexHTML(self.plainTextEdit.toPlainText()) elif self.tipoArchivo == ".js": Lexico.lexJS(self.plainTextEdit.toPlainText()) elif self.tipoArchivo == ".css": self.textEdit_2.setText( Lexico.lexCSS(self.plainTextEdit.toPlainText())) elif self.tipoArchivo == ".rmt": self.textEdit_2.setText( Sintax.sintaxParentesis(self.plainTextEdit.toPlainText()))
def tytus_ejecutar(self): # Getting widget index = self.ta_input.index(self.ta_input.select()) ta_input = self.array_tabs[index] # Delete old lexical report if os.path.exists("reports/error_lexical.txt"): os.remove("reports/error_lexical.txt") # Delete old syntactic report if os.path.exists("reports/error_syntactic.txt"): os.remove("reports/error_syntactic.txt") # Delete old semantic report if os.path.exists("reports/error_semantic.txt"): os.remove("reports/error_semantic.txt") # Delete old output self.ta_output.delete('1.0', END) if ta_input.compare("end-1c", "!=", "1.0"): # Gets new input tytus = ta_input.get(1.0, END) # Start parser ins = g.parse(tytus) st_global = st.SymbolTable() if not ins: messagebox.showerror( "ERROR", "Ha ocurrido un error. Verificar reportes.") else: self.do_body(ins, st_global) else: messagebox.showerror("INFO", "El campo de entrada esta vacío.")
def __init__(self, file): self.arquivo = open(file, 'r') self.lexico = Lexico.Arquivo(self.arquivo.read()) self.tabSimb = {} self.temp = 0 self.label = 0 self.atual_bloco = 0
def opera( string ): par = 0 #~ print "" #~ string = raw_input( "Escribe una ecuacion:\n" ) lex = Lexico.lexico( string ) t = len(lex) for i in range(t): if lex[ i ] == '4': par = par + 1 elif lex[ i ] == '5': par = par - 1 if par < 0: break; lis = "".join(lex) print "" print "------------------------------------------------------------------------" print "" if( sintactico( lis ) == 0 and par == 0): print string, "es una operacion valida" else: print string, "no es una operacion valida" print "" print "------------------------------------------------------------------------" print ""
def blocoPrincipal(codeFile, fileTable): # Para nao printar em um arquivo a tabela de simbolos: if fileTable == None: lexico = Lexico.Lexico() sintatico = Sintatico.Sintatico(lexico, codeFile) parser = sintatico.parser() # Para printar em um arquivo a tabela de simbolos: else: lexico = Lexico.Lexico() sintatico = Sintatico.Sintatico(lexico, codeFile) parser = sintatico.parser() tabela = Archive.Archive(None, fileTable) listReserv = [] aux = [] # Pega as palavras reservadas for r in lexico.reservadas: aux.append(r.split()) # Retira da string completa, so o que precisa: for i in aux: a = len(str(i)) -2 listReserv.append(str(i)[2:a]) # Manda criar a tabela: tabela.criaTabela(sintatico.listIdent,sintatico.listTipo,sintatico.listLinha, listReserv)
def tytus_ejecutar(self): global GC3D # Getting widget index = self.ta_input.index(self.ta_input.select()) ta_input = self.array_tabs[index] # Delete old lexical report if os.path.exists("reports/error_lexical.txt"): os.remove("reports/error_lexical.txt") # Delete old syntactic report if os.path.exists("reports/error_syntactic.txt"): os.remove("reports/error_syntactic.txt") # Delete old semantic report if os.path.exists("reports/error_semantic.txt"): os.remove("reports/error_semantic.txt") if ta_input.compare("end-1c", "!=", "1.0"): # Gets new input tytus = ta_input.get(1.0, END) # Start parser ins = g.parse(tytus) #g.gramaticaBNF(tytus) #Contador de temporales utilizados temp = g.contador gen = Generador(temp, 0, ins.getInstruccion()) gen.ejecutar() GC3D = gen.codigo3d #reporteOptimizacion(reglasOpt) C3D = g.codigo_3D crearArchivo(C3D, gen.codigo3d) st_global = st.SymbolTable() es_global = es.ListaErroresSemanticos() ct_global = ct.crearTabla() if not ins: messagebox.showerror( "ERROR", "Ha ocurrido un error. Verificar reportes.") else: self.do_body(ins.getInstruccion(), st_global, es_global, ct_global) self.raiz_ast = ins.getNodo() self.new_output( "--- SE HA GENERADO EL ARCHIVO ÉXITOSAMENTE ---") else: messagebox.showerror("INFO", "El campo de entrada esta vacío.")
def tytus_ejecutar(self): # Getting widget index = self.ta_input.index(self.ta_input.select()) ta_input = self.array_tabs[index] # Delete old lexical report if os.path.exists("reports/error_lexical.txt"): os.remove("reports/error_lexical.txt") # Delete old syntactic report if os.path.exists("reports/error_syntactic.txt"): os.remove("reports/error_syntactic.txt") # Delete old semantic report if os.path.exists("reports/error_semantic.txt"): os.remove("reports/error_semantic.txt") if ta_input.compare("end-1c", "!=", "1.0"): # Gets new input tytus = ta_input.get(1.0, END) # Start parser ins = g.parse(tytus) temp = g.contador gen = Generador(temp, 0, ins.getInstruccion()) gen.ejecutar() C3D = g.codigo_3D crearArchivo(C3D) ##g.analizar(tytus) st_global = st.SymbolTable() es_global = es.ListaErroresSemanticos() ct_global = ct.crearTabla() if not ins: messagebox.showerror( "ERROR", "Ha ocurrido un error. Verificar reportes.") else: #self.do_body(ins.getInstruccion(), st_global, es_global, ct_global) self.raiz_ast = ins.getNodo() else: messagebox.showerror("INFO", "El campo de entrada esta vacío.")
def __init__(self): with open('entrada.txt', 'r') as Archivo: self.Cadena = Archivo.read() + '$' Archivo.close() #=============================================================== self.Suma = Arbol.Suma self.Multi = Arbol.Multi self.Asign = Arbol.Asignacion self.ReservIf = Arbol.ReservIf self.ReservPrint = Arbol.ReservPrint self.Separador = Arbol.Separador self.Signo = Arbol.Signo self.ExpresionArb = Arbol.Expre self.Bloque = Arbol.Bloque self.ReservElse = Arbol.ReservElse self.ReservWhile = Arbol.ReservWhile self.Logico = Arbol.Logico self.Relacional = Arbol.Relacional self.Identi = Arbol.Identificador self.Entero = Arbol.Entero self.Flotante = Arbol.Flotante self.CadenaArb = Arbol.Cadena #=============================================================== self.ListaArbolesBloque = [[], [], [], [], []] # Permite Anidación de hasta 5 niveles. self.ListaArboles = [] self.ArbolActual = [] self.ArbolPila = [] self.lexico = Lexico.Lexico(self.Cadena) self.Cadena = '' self.PalabReserv = ['if', 'else', 'do', 'while', 'print'] self.BloqueActivo = [False, False, False, False, False] # Permite Anidación de hasta 5 niveles.
def ast_report(self): g = Graficar() g.graficar_arbol(self.raiz_ast)
#!/usr/bin/env python # -*- coding: utf-8 -*- import hashlib import re import unicodedata from Caller import * from Lexico import * from Classes import * file = open('ARQSAIDA.txt', 'w') analisador = Lexico() analisador.run() Tokens = analisador.Tokens['tokens'] Lexemes = analisador.Tokens['lexeme'] Lines = analisador.Tokens['lines'] index = None aux1 = 0 aux2 = 1 composer = {} auxilier = 0 base = 0 type = [] armazem = {} #Tabela de símbolos, configurando todos os IDs def SymbolTable(): for i in range(0, len(Tokens)): #Reconhece se é um ID, através da análise obtida do léxico
def graficar(self, raiz): g = graficar() g.graficar_arbol(raiz)
''' Analisador Sintatico ''' import Lexico Token = Lexico.Token() Atual = Lexico.Atual() class ErroSintatico(Exception): """docstring for ErroSintatico""" def __init__(self, tk): self.token = tk # Atual = Lexico.Atual() def __str__(self): return "ERRO: era esperado o Token " + str( Token.msg[self.token]) + ", mas veio o Token " + str( Token.msg[Atual.token]) + ": linha " + str( Atual.linha) + ", coluna: " + str(Atual.coluna) + "\n" class ErroSemantico(Exception): """docstring for ErroSintatico""" def __init__(self, lex): self.lexema = lex # Atual = Lexico.Atual() def __str__(self): return "ERRO: a variavel '" + str(self.lexema) + "': linha " + str( Atual.linha) + ", coluna: " + str(Atual.coluna) + "\n"