def p_ver3(p): ''' ver3 : ''' temp = quad.PilaO.pop() quad.Ptypes.pop() loc = Tablas.findLVector(Tablas.isVector) lim1 = Tablas.findCteVM(0) if loc == True: lim2 = Tablas.vectLTable[Tablas.isVector].lim1 else: lim2 = Tablas.vectGTable[Tablas.isVector].lim1 quad.quadInsert('Ver', temp, lim1, lim2) quad.count += 1 temp2 = quad.PilaO.pop() result = mv.getMemoTemp('int', Tablas.isGlobal,1) if (Tablas.isGlobal): Tablas.gtempAddSize('int',1) else: Tablas.tempAddSize('int',1) quad.quadInsert('+', temp, temp2, result) quad.count += 1 result2 = mv.getMemoTemp('int', Tablas.isGlobal,1) if (Tablas.isGlobal): Tablas.gtempAddSize('int',1) else: Tablas.tempAddSize('int',1) dir = Tablas.findCteVM(Tablas.isVector) quad.quadInsert('+', result, dir, result2) quad.count += 1 quad.PilaO.append('('+str(result2)+')')
def popRel(glob): size = len(Poper) if size > 0: if Poper[size - 1] == '>' or Poper[size - 1] == '<' or Poper[ size - 1] == '>=' or Poper[size - 1] == '<=' or Poper[ size - 1] == '==' or Poper[size - 1] == '!=': right_operand = PilaO.pop() right_type = Ptypes.pop() left_operand = PilaO.pop() left_type = Ptypes.pop() operator = Poper.pop() result_type = semantic_cube[operator][left_type][right_type] if (result_type != 'err'): result = mv.getMemoTemp(result_type, glob, 1) if (glob): Tabla.gtempAddSize(result_type, 1) else: Tabla.tempAddSize(result_type, 1) temp = cuadruplo.cuadruplo(count - 1, operator, left_operand, right_operand, result) Quad.append(temp) PilaO.append(result) Ptypes.append(result_type) return True else: print("Error: type mismatch, <,<=,>,>=") sys.exit() return False
def p_ver2(p): ''' ver2 : ''' temp = quad.PilaO.pop() quad.Ptypes.pop() #quad.PilaO.append(temp) loc = Tablas.findLVector(Tablas.isVector) lim1 = Tablas.findCteVM(0) if loc == True: lim2 = Tablas.vectLTable[Tablas.isVector].lim1 m = Tablas.vectLTable[Tablas.isVector].m else: lim2 = Tablas.vectGTable[Tablas.isVector].lim1 m = Tablas.vectGTable[Tablas.isVector].m quad.quadInsert('Ver', temp, lim1, lim2) quad.count += 1 result = mv.getMemoTemp('int',Tablas.isGlobal,1) if (Tablas.isGlobal): Tablas.gtempAddSize('int',1) else: Tablas.tempAddSize('int',1) quad.quadInsert('*', temp, m, result) quad.count += 1 quad.PilaO.append(result)
def popMat(glob): size = len(Poper) if size > 0: if Poper[size - 1] != '(': if Poper[size - 1] == '$' or Poper[size - 1] == '¡' or Poper[size - 1] == '?': temp = operand = PilaO.pop() operand = operand if operand == opMat(operand) else opMat( operand) o_type = Ptypes.pop() operator = Poper.pop() if operator == '¡': result_type = o_type elif operator == '$': if (o_type == 'char'): print( 'Error: No se puede el determinante de una matriz de chars' ) sys.exit() else: result_type = o_type else: result_type = semantic_cube['/'][o_type]['float'] tam = compMatSize(operand, temp, operand, temp, operator) if tam == 0: print( 'Error: Esta es una funcion especial para solo matrices' ) sys.exit() elif tam == 1: salto = 1 else: salto = tamMat(tam) if (result_type != 'err'): result = mv.getMemoTemp(result_type, glob, salto) if (salto > 1 and len(tam) == 1): result = str(result) + '[' + tam[0] elif (salto > 1 and len(tam) == 2): result = str(result) + '[' + tam[0] + '[' + tam[1] if (glob): Tabla.gtempAddSize(result_type, salto) else: Tabla.tempAddSize(result_type, salto) temp = cuadruplo.cuadruplo(count - 1, operator, operand, None, result) Quad.append(temp) PilaO.append(result) Ptypes.append(result_type) return True else: print('Error: type mismatch,¡,$,?') sys.exit() return False
def parcheguad(func, glob): gvarTable = Tabla.gvarTable for ids in gvarTable: if ids == func: dir = gvarTable[func].dir tipo = gvarTable[func].type if (dir == None): return False else: result = mv.getMemoTemp(tipo, glob, 1) if (glob): Tabla.gtempAddSize(tipo, 1) else: Tabla.tempAddSize(tipo, 1) temp = cuadruplo.cuadruplo(count - 1, '=', dir, None, result) Quad.append(temp) PilaO.append(result) Ptypes.append(tipo) return True
def addToFor(glob): result_type = 'int' result = mv.getMemoTemp(result_type, glob, 1) if (glob): Tabla.gtempAddSize(result_type, 1) else: Tabla.tempAddSize(result_type, 1) left_operand = desde.pop() dir = mv.getMemoCte('int') temp = Tabla.cteInsert(1, 'int', dir) if (temp == False): mv.restMemo('int') right_operand = Tabla.findCteVM(1) temp = cuadruplo.cuadruplo(count - 1, '+', left_operand, right_operand, result) desde.append(left_operand) desde.append(result) Quad.append(temp) return True
def popFact(glob): size = len(Poper) if size > 0: if Poper[size - 1] != '(': if Poper[size - 1] == '*' or Poper[size - 1] == '/': tempR = right_operand = PilaO.pop() right_operand = right_operand if right_operand == opMat( right_operand) else opMat(right_operand) right_type = Ptypes.pop() tempL = left_operand = PilaO.pop() left_operand = left_operand if left_operand == opMat( left_operand) else opMat(left_operand) left_type = Ptypes.pop() operator = Poper.pop() result_type = semantic_cube[operator][left_type][right_type] tam = compMatSize(right_operand, tempR, left_operand, tempL, operator) if tam == 1: salto = 1 else: salto = tamMat(tam) if (result_type != 'err'): result = mv.getMemoTemp(result_type, glob, salto) if (salto > 1 and len(tam) == 1): result = str(result) + '[' + tam[0] elif (salto > 1 and len(tam) == 2): result = str(result) + '[' + tam[0] + '[' + tam[1] if (glob): Tabla.gtempAddSize(result_type, salto) else: Tabla.tempAddSize(result_type, salto) temp = cuadruplo.cuadruplo(count - 1, operator, left_operand, right_operand, result) Quad.append(temp) PilaO.append(result) Ptypes.append(result_type) return True else: print("Error: type mismatch,*,/") sys.exit() return False
def compareFor(glob): right_operand = PilaO.pop() right_type = Ptypes.pop() left_operand = PilaO.pop() left_type = Ptypes.pop() result_type = semantic_cube['<='][left_type][right_type] if (result_type != 'err'): desde.append(left_operand) result = mv.getMemoTemp(result_type, glob, 1) if (glob): Tabla.gtempAddSize(result_type, 1) else: Tabla.tempAddSize(result_type, 1) temp = cuadruplo.cuadruplo(count - 1, '<=', left_operand, right_operand, result) Quad.append(temp) PilaO.append(result) Ptypes.append(result_type) return True else: print("Error: type mismatch, FOR") sys.exit() return False