def p_punto_termino_pop(p): ''' punto_termino_pop : ''' global stack_operators, arr_quadruples, cube, stack_operands, stack_type if len(stack_operators) != 0: top = stack_operators.pop() if top == '*' or top == '/': value = None value_type = None op1 = stack_operands.pop() op2 = stack_operands.pop() type_aux_1 = stack_type.pop() type_aux_2 = stack_type.pop() value_type = cube.get_type(type_aux_1, type_aux_2, top) if value_type == 5: #todo: error raise Exception("ERROR: Type Mismatch en multiplicacion o division") else: dir_memory_aux = memory.get_value_memory(value_type, scope, True, False) semantic_var.add_variables(value_type, scope, 'temp_variable', None, None, dir_memory_aux, 0) q = Quadruple(top, op2, op1, dir_memory_aux ) arr_quadruples.append(q.get_quadruple()) stack_operands.append(dir_memory_aux) stack_type.append(value_type) else: stack_operators.append(top)
def p_punto_pop_relacional(p): ''' punto_pop_relacional : ''' global stack_operators, arr_quadruples, stack_type,stack_operands top = stack_operators.pop() if top == '>' or top == '<' or top == '>=' or top == '<=' or top == '==' or top =='<>': op1 = stack_operands.pop() # 9 - dir op2 = stack_operands.pop() # aglobal - dir type_1 = stack_type.pop() type_2 = stack_type.pop() value_type = cube.get_type(type_1, type_2, top) if value_type != 5: dir_memory_aux = memory.get_value_memory(4, scope, True, False) semantic_var.add_variables(4, scope, 'temp_variable', None, None, dir_memory_aux, 0) q = Quadruple(top, op2, op1, dir_memory_aux) arr_quadruples.append(q.get_quadruple()) stack_operands.append(dir_memory_aux) stack_type.append(4) else: raise Exception("ERROR: Type Mismatch con operadores relacionales") stack_operators.append(top)
def p_pop_and(p): ''' pop_and : ''' global stack_operators, arr_quadruples, stack_operands,stack_type if len(stack_operators) != 0: top = stack_operators.pop() if top == 'and': op1 = stack_operands.pop() # memory dir op2 = stack_operands.pop() type_1 = stack_type.pop() type_2 = stack_type.pop() value_type = cube.get_type(type_1, type_2, top) #todo: checar tipos if value_type != 5: # 1 memory dir : scope, 'bool', temp dir_memory_aux = memory.get_value_memory(4, scope, True, False) # 3 agregar esa direccion de memoria a _global variables temp semantic_var.add_variables(4, scope, 'temp_variable', None, None, dir_memory_aux, 0) q = Quadruple(top, op2, op1, dir_memory_aux) arr_quadruples.append(q.get_quadruple()) stack_operands.append(dir_memory_aux) stack_type.append(4) else: raise Exception("ERROR: Type mismatch en and") else: stack_operators.append(top)
def p_punto_return_value(p): ''' punto_return_value : ''' global semantic_var # id - type semantic_var.add_function_id_return_value(p[-2], p[-4]) return_type = None if p[-4] == 'int': return_type = 1 elif p[-4] == 'float': return_type = 2 elif [p-4] == 'char': return_type = 3 memory_dir = memory.get_value_memory(return_type, 'global', False, False) semantic_var.add_variables(return_type, 'global', 'function', p[-2], None, memory_dir, 0 )
def p_punto_push_param(p): ''' punto_push_param : ''' global semantic_var param_type = -1 if p[-2] == 'int': param_type = 1 elif p[-2] == 'char': param_type = 3 elif p[-2] == 'float': param_type = 2 var_memory= memory.get_value_memory(param_type,scope,False,False) semantic_var.add_variables(param_type, scope, 'param',p[-1],None,var_memory,0) semantic_var.add_parameter_type(scope, param_type) semantic_var._global['functions'][scope]['variables']['name_var'].add(p[-1])
def p_punto_pop_or(p): ''' punto_pop_or : ''' global stack_operators, arr_quadruples, stack_operands, semantic_var, stack_type if len(stack_operators) != 0: top = stack_operators.pop() if top == 'or': op1 = stack_operands.pop() # memory dir op2 = stack_operands.pop() type_1 = stack_type.pop() type_2 = stack_type.pop() value_type = cube.get_type(type_1, type_2, top) if value_type != 5: # 1 memory dir : scope, 'bool', temp dir_memory_aux = memory.get_value_memory(4, scope, True, False) # 2 agregar esa direccion de memoria a _global variables temp semantic_var.add_variables(4, scope, 'temp_variable', None, None, dir_memory_aux, 0) # 3 crear cuadruplo = (or false true memory_dir) q = Quadruple(top, op2, op1, dir_memory_aux) arr_quadruples.append(q.get_quadruple()) stack_type.append(value_type) stack_operands.append(dir_memory_aux) else: raise Exception("ERROR: Type mismatch en or") else: stack_operators.append(top)