def xor_binario(param1: Valor, param2: Valor): from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts tipo_resultante = 0 rst = 0 #Solo Se Pueden Valores Numericos if (param1.tipo == 0): if param2.tipo == 0: #Entero tipo_resultante = 0 rst = param1.dar_valor() ^ param2.dar_valor() else: print("Error En Xor Binario Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) Ts.cargar_error( "Error En Xor Binario Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) else: Ts.cargar_error( "Error En Xor Binario Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) print("Error En Xor Binario Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) return Valor(rst, tipo_resultante)
def shift_izquierda(param1: Valor, param2: Valor): tipo_resultante = 0 rst = 0 from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts #Solo Se Pueden Valores Numericos if (param1.tipo == 0): if param2.tipo == 0: #Entero tipo_resultante = 0 rst = param1.dar_valor() << param2.dar_valor() else: print("Error En shift Izquierda Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) Ts.cargar_error( "Error En Shift Izquierda Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) else: Ts.cargar_error( "Error En Shift Izquierda Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) print("Error En Shift Izquierda Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) return Valor(rst, tipo_resultante)
def xor_entero(param1: Valor, param2: Valor): from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts tipo_resultante = 0 rst = 0 # Solo Se Pueden Valores Numericos if param1.tipo == 0: if param2.tipo == 0: # Entero tipo_resultante = 0 if param1.dar_valor() != param2.dar_valor(): rst = 1 else: rst = 0 else: Ts.cargar_error( "Error En XOR Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) print("Error En La Operacion XOR Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) else: Ts.cargar_error( "Error En XOR Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str(), 0, ((0, 0))) print("Error En La Operacion XOR Con Tipos: " + param1.dar_tipo_str() + "," + param2.dar_tipo_str()) return Valor(rst, tipo_resultante)
def p_instrucciones_goto(t): 'instruccion : GOTO IDENTIFICADOR PUNTOCOMA' t[0] = Goto(t[2]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : GOTO IDENTIFICADOR PUNTOCOMA', "t[0] = Goto(t[2])")
def p_instrucciones_exit(t): 'instruccion : EXIT PUNTOCOMA' t[0] = Exit() global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : EXIT PUNTOCOMA', "t[0] = Exit()")
def p_instrucciones_imprimir(t): 'instruccion : IMPRIMIR PARA expresion PARC PUNTOCOMA' t[0] = ABCInstruccion.Imprimir(t[3]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : IMPRIMIR PARA expresion PARC PUNTOCOMA', "t[0] = ABCInstruccion.Imprimir(t[3])")
def p_error(t): global Ts if t is None : Ts.cargar_error("Se Alcanzo El Fin Del Archivo", 20, (0,0)) return Ts.exit_exec = 0 tup=find_column(Ts.texto_analisis, t) Ts.cargar_error("El token con lexema \""+str(t.value)+"\" de tipo \""+str(t.type)+" \" ocasiono un error sintactico",20,tup) print("Error sintáctico en '%s'" % t) # Read ahead looking for a closing '}' #t.lexer.skip(1) global parsito while True: tok = parsito.token() # Get the next token #print(tok) if not tok or tok.type == 'PUNTOCOMA': break tok=parsito.token() parsito.errok()
def p_instrucciones_lista_sin_recursividad_epsilon(t): 'instruccionesp : ' t[0] = ABCInstruccion.ListaInstruccion([]) global Ts Ts.rp_nuevo_nodo('instruccionesp : ', "t[0] = ABCInstruccion.ListaInstruccion([])")
def p_expresion_binaria(t): '''expresion : valor MAS valor | valor MENOS valor | valor POR valor | valor DIVIDIDO valor | valor MOD valor | valor ANDB valor | valor ORB valor | valor XORB valor | valor SHIFTD valor | valor SHIFTI valor | valor AND valor | valor OR valor | valor XOR valor | valor DIFERENTE valor | valor IGUALDOBLE valor | valor MAYOR valor | valor MAYORIGUAL valor | valor MENORIGUAL valor | valor MENOR valor''' t[0] = ABCInstruccion.ExpresionDoble(t[1], t[2], t[3]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[2])) Ts.rp_nuevo_nodo('expresion : valor '+str(t[2])+ ' valor', "t[0] = ABCInstruccion.ExpresionDoble(t[1], t[2], t[3])")
def p_instrucciones_if(t): 'instruccion : IF expresion instruccion ' t[0] = If(t[2], t[3]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : IF expresion instruccion ', "t[0] = If(t[2], t[3])")
def p_instrucciones_lista(t): 'instrucciones : instrucciones instruccion ' t[0] = t[1] t[0].agregar(t[2]) global Ts Ts.nueva_instruaccion(t[2]) Ts.rp_nuevo_nodo('instrucciones : instrucciones instruccion ', "t[0] = Etiqueta(t[3], t[1])")
def p_arreglo_indice(t): 'arra : CORA expresion CORC arra ' t[0] = t[4] t[0].append(t[2]) global Ts Ts.rp_nuevo_nodo('arra : CORA expresion CORC arra ', "t[0] = t[4] t[0].append(t[2])")
def p_etiquetas_lista(t): 'etiquetas : etiquetas etiqueta' t[0] = t[1] t[0].agregar(t[2]) global Ts Ts.rp_nuevo_nodo('etiquetas : etiquetas etiqueta', "t[0] = t[1] \n t[0].agregar(t[2]) ")
def p_etiqueta_contenido(t): 'etiqueta : IDENTIFICADOR ideti instrucciones' t[0] = Etiqueta(t[3], t[1]) global Ts Ts.consolidar_etiqueta() t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('etiqueta : IDENTIFICADOR ideti instrucciones', "t[0] = Etiqueta(t[3], t[1])")
def p_etiqeutas_sin_recursividad_epsilon(t): 'etiquetasp : ' t[0] = ABCInstruccion.ListaEtiqueta([t[-1]]) global Ts Ts.rp_nuevo_nodo('etiquetasp : ', "t[0] = ABCInstruccion.ListaEtiqueta([t[-1]])")
def p_expresion_valor_unico_variable(t): 'valor : DOLAR IDENTIFICADOR arra' t[0] = VariableValor(t[2]) t[0].indices(t[3]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('valor : DOLAR IDENTIFICADOR arra', "t[0] = VariableValor(t[2])")
def p_expresion_cadena(t): 'valor : CADENA' t[0] = ABCInstruccion.Valor(t[1], 2) t[0] = ABCInstruccion.ExpresionSimple(t[0]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('valor : CADENA', "t[0] = ABCInstruccion.Valor(t[1], 2)")
def p_expresion_decimal(t): 'valor : DECIMAL' t[0] = ABCInstruccion.Valor(t[1], 1) t[0] = ABCInstruccion.ExpresionSimple(t[0]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('valor : DECIMAL', "t[0] = ABCInstruccion.Valor(t[1], 1)")
def p_expresion_entero(t): 'valor : ENTERO' t[0] = ABCInstruccion.Valor(t[1], 0) t[0] = ABCInstruccion.ExpresionSimple(t[0]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('valor : ENTERO', "t[0] = ABCInstruccion.Valor(t[1], 0)")
def p_instrucciones_asignar(t): 'instruccion : DOLAR IDENTIFICADOR arra IGUAL expresion PUNTOCOMA' t[0] = Asignar(t[2], t[5]) t[0].indices(t[3]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : DOLAR IDENTIFICADOR arra IGUAL expresion PUNTOCOMA', "t[0] = Asignar(t[2], t[5])")
def p_instrucciones_unset(t): 'instruccion : UNSET PARA DOLAR IDENTIFICADOR arra PARC PUNTOCOMA' t[0] = Unset(t[4]) t[0].indices(t[5]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('instruccion : UNSET PARA DOLAR IDENTIFICADOR arra PARC PUNTOCOMA', "t[0] = Unset(t[4])")
def p_etiqeutas_sin_recursividad(t): 'etiquetasp : etiqueta etiquetasp' t[0] = t[2] t[0].lst.insert(0, t[-1]) global Ts Ts.rp_nuevo_nodo('etiquetasp : etiqueta etiquetasp', "t[0] = t[2] \n t[0].lst.insert(0, t[-1])")
def p_etiqueta_principal(t): 'etiqueta : MAIN ideti instrucciones' t[0] = Etiqueta(t[3], t[1]) global Ts Ts.consolidar_etiqueta() t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('etiqueta : MAIN ideti instrucciones', "t[0] = Etiqueta(t[3], t[1])")
def p_instrucciones_lista_sin_recursividad(t): 'instruccionesp : instruccion instruccionesp' t[0] = t[2] t[0].lst.insert(0, t[1]) global Ts Ts.nueva_instruaccion(t[1]) Ts.rp_nuevo_nodo('instruccionesp : instruccion instruccionesp', "t[0] = t[2] \n t[0].lst.insert(0, t[1])")
def t_error(t): from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts tup = find_column(Ts.texto_analisis, t) Ts.cargar_error( "El token con lexema \"" + str(t.value[0]) + "\" ocasiono un error lexico", 30, tup) print("Illegal character '%s'" % t.value[0]) t.lexer.skip(1)
def p_expresion_agrupacion(t): '''expresion : PARA INT PARC valor | PARA FLOAT PARC valor | PARA CHAR PARC valor''' t[0] = ABCInstruccion.ExpresionSimpleOperacion(t[4], t[2]) global Ts t[0].n_t(find_column(Ts.texto_analisis, t.slice[1])) Ts.rp_nuevo_nodo('expresion : PARA' + str(t[2]) + 'PARC valor', "t[0] = ABCInstruccion.ExpresionSimpleOperacion(t[4], t[2])")
def ejecutar(self): from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts tope = len(self.lst) - 1 lista_invertida = [] for index in range(tope, -1, -1): lista_invertida.append(self.lst[index].ejecutar().dar_valor()) Ts.eliminar_variable(self.vaue,lista_invertida)
def ejecutar(self): condicion: Valor = self.booleano.ejecutar() if condicion.tipo == 0: if condicion.dar_valor() >= 1: return self.cuerpo.ejecutar() else: global Ts Ts.cargar_error( "En La Condicional Del IF Se Necesita El Tipo ENTERO ", 0, self.tupla)
def graficar_sin_consola(): f = open("C:/Users/norki/Desktop/interprete/entrada.txt", "r") #f = open("C:/Users/Esnorki/Desktop/interprete/entrada.txt", "r") input: str = f.read() global Ts Ts.guardar_consola(None) Ts.nueva_ejecucion() raiz_produccion: ListaInstruccion = analizar_ascendente(input) if raiz_produccion is not None: # Ts.cargar_etiquetas(raiz_produccion) # Ts. # print(raiz_produccion.str_arbol()) print(raiz_produccion.str_arbol())
def negar_binario(param1 : Valor): from Contenido.LstInstruccion.ABCInstruccion import Ts global Ts tipo_resultante = 0 rst = 0 #Solo Se Pueden Valores Numericos if(param1.tipo==0): tipo_resultante=param1.tipo rst = ~param1.dar_valor() else: Ts.cargar_error( "Error En Negacion Binario Con Tipos: " + param1.dar_tipo_str() , 0, ((0, 0))) print("Error En La NegacionBinaria Con Tipos: " + param1.dar_tipo_str() ) return Valor(rst, tipo_resultante)