def p_clear_current_dimension(p): """Clear_Current_Dimension : """ expr.add_operator("#") state.arr_parsing = True # state.assign_list = [] state.arr_current_dim = 0 p[0] = p[-1]
def p_seen_call(p): """Seen_Call : """ state.func_parsing = True expr.add_operator("#") state.return_dir_stack.append(state.temp_dir) func_name = p[-2] state.current_call = func_name type = sem.func_table[func_name][0][0] # [[primitive, dir, size, scope], dir, size] if type != "void": # Function has a return value if type[0] == "i" or type[0] == "f": size = 4 else: size = 1 # Creates a temporal to save return value func.generate_era(func_name, [func_name, [type, state.temp_dir, [size, 1], "t"]]) state.temp_dir -= size else: func.generate_era(func_name, None) state.assign_list.append(type)
def p_update_offset(p): """Update_Offset : """ var = sem.get_variable(p[-2]) type = var[1][0] expr.add_operator("#") for x in range(state.arr_current_dim - 1): expr.add_operator("+") expr.generate_quad(2) # Generates quads to sum all the indices if type[0] == "i" or type[0] == "f": sem.fill_symbol_table_constant(4, "int", 4) expr.add_operand(sem.get_variable(4)) expr.add_operator("*") expr.generate_quad(1) expr.pop_operator()
def p_seen_operator(p): """Seen_Operator : """ expr.add_operator(p[-1]) p[0] = p[-1]
def p_seen_unary_operator(p): """Seen_Unary_Operator : """ expr.add_operator("u" + str(p[-1])) p[0] = p[-1]