def p_seen_local_variable(p): """Seen_Local_Variable : """ type = p[-4] if type[0] == "i" or type[0] == "f": size = 4 else: size = 1 # Check if variable has dimensions if len(state.arr_dim) > 0: # Multiplies all the items in the dimensions list elements = reduce(lambda x, y: x * y, state.arr_dim) # Number of elements in the array for dim in state.arr_dim: type += "[]" sem.fill_local_variables_table(p[-3], type, [elements * size] + state.arr_dim, state.arr_m_list) state.arr_dim = [] state.arr_r = 1 state.arr_m_list = [] else: sem.fill_local_variables_table(p[-3], type, [size, 1], None) p[0] = type
def p_seen_local_variable_1(p): """Seen_Local_Variable1 : """ type = p[-3] if type[0] == "i" or type[0] == "f": size = 4 else: size = 1 # Check if variable has dimensions if len(state.arr_dim) > 0: dims = [0] # List to hold temporal values of dimensions m_list = [] # List to hold temporal values of m # Appends brackets to type for each dimension for dim in state.arr_dim: type += "[]" dims.append(-1) m_list.append(-1) sem.fill_local_variables_table(p[-2], type, dims, m_list) # Temporal values state.arr_dim = [] else: sem.fill_local_variables_table(p[-2], type, [size, 1], None) p[0] = type