def assignToFor(): right_operand = desde.pop() left_operand = desde.pop() temp = cuadruplo.cuadruplo(count - 1, '=', right_operand, None, left_operand) Quad.append(temp) return True
def popAssign(): size = len(Poper) if size > 0: if Poper[size - 1] == '=': right_operand = PilaO.pop() right_operand = right_operand if right_operand == opMat( right_operand) else opMat(right_operand) right_type = Ptypes.pop() 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() if (left_type == right_type and asignaCompMat(str(right_operand), str(left_operand))): #result = 't' + str(count) temp = cuadruplo.cuadruplo(count - 1, operator, right_operand, None, left_operand) Quad.append(temp) PilaO.append(left_operand) Ptypes.append(left_type) return True else: print("Error: type mismatch, assign") sys.exit() return False return False
def Goto_SI(): temp = cuadruplo.cuadruplo(count - 1, 'Goto', None, None, None) Quad.append(temp) false = Pjumps.pop() Pjumps.append(count - 1) Quad[false].result = count return True
def Goto_While(): end = Pjumps.pop() retur = Pjumps.pop() temp = cuadruplo.cuadruplo(count - 1, 'Goto', None, None, retur) Quad.append(temp) Quad[end].result = count return True
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 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 GotoF_While(): exp_type = Ptypes.pop() if (exp_type != 'boolean'): print('Error: type mismatch, MIENTRAS') sys.exit() return False else: result = PilaO.pop() temp = cuadruplo.cuadruplo(count - 1, 'GotoF', result, None, None) Quad.append(temp) Pjumps.append(count - 1) return True
def popRet(): size = len(Poper) if size > 0: if Poper[size - 1] == 'regresa': right_operand = PilaO.pop() Ptypes.pop() operator = Poper.pop() #result_type = semantic_cube[operator][left_type][right_type] temp = cuadruplo.cuadruplo(count - 1, operator, None, None, right_operand) Quad.append(temp) return True 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
def quadInsert(action, dirIzq, dirDer, Resultado): """Genera un quadruplo y lo inserta en la lista de cuadruplos""" temp = estructura.cuadruplo(contQuad - 1, action, dirIzq, dirDer, Resultado) Quad.append(temp)
def gosub(func): temp = cuadruplo.cuadruplo(count - 1, 'Gosub', None, None, func) Quad.append(temp)
def paramInsert(): params = PilaO.pop() tipo = Ptypes.pop() num = param temp = cuadruplo.cuadruplo(count - 1, 'Param', params, None, num) Quad.append(temp)
def quadInsert(action, dir1, dir2, result): temp = cuadruplo.cuadruplo(count - 1, action, dir1, dir2, result) Quad.append(temp)