Пример #1
0
def p_seen_operand_1(p):
    """Seen_Operand1 : """
    if sem.is_declared(p[-2]):
        var = sem.get_variable(p[-2])
        if state.arr_current_dim == 0 or "[]" not in var[1][0]:
            expr.add_operand(sem.get_variable(p[-2]))
            state.assign_list.append(var[1][0])
Пример #2
0
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()
Пример #3
0
def p_seen_operand(p):
    """Seen_Operand : """
    if sem.is_declared(p[-1]):
        var = sem.get_variable(p[-1])
        if state.arr_current_dim == 0 or "[]" not in var[1][0]:
            expr.add_operand(var)
            if not state.arr_parsing and not state.func_parsing:
                state.assign_list.append(var[1][0])
Пример #4
0
def p_generate_dir(p):
    """Generate_Dir : """
    var = sem.get_variable(p[-3])
    state.arr_parsing = False
    # If size is zero variable is unresolved
    if var[1][2][0] <= 0:
        state.unresolved_vars[sem.scope][var[0]].append(len(state.quads))
    arr.generate_dir(var[1][1], var[1][3])  # Starting address, scope
    state.assign_list.append(var[1][0][: -2 * state.arr_current_dim])
    state.arr_dim_stack.append(state.arr_current_dim)
    expr.pop_operator()
Пример #5
0
def p_verify_limit(p):
    """Verify_Limit : """
    state.arr_current_dim += 1  # First position holds the array size in bytes
    index = state.operand_stack.pop()
    var = sem.get_variable(p[-4])

    if var[1][2][0] <= 0:
        if state.unresolved_vars.get(sem.scope) == None:
            state.unresolved_vars[sem.scope] = {}
        if state.unresolved_vars[sem.scope].get(var[0]) == None:
            state.unresolved_vars[sem.scope][var[0]] = []
        state.unresolved_vars[sem.scope][var[0]].append(len(state.quads))

    arr.generate_verify(index, var[1][2][state.arr_current_dim] - 1)  # Gets dimension limits
    arr.generate_multiply_m(index, var[1][4][state.arr_current_dim - 1])  # Gets mn

    p[0] = p[-4]
Пример #6
0
def p_seen_param_call(p):
    """Seen_Param_Call : """
    param = state.operand_stack.pop()
    var = sem.get_variable(p[-1])
    type = var[1][0]
    # Check if it's a dimentional parameter
    if "[]" in type and "[]" in sem.func_table[state.current_call][1][state.param_counter]:
        arg = sem.func_table[state.current_call][2][state.param_counter]  # Gets variable to replace
        if sem.var_table[state.current_call][arg][1] < 0:  # If variable is not yet assigned
            dir = max(
                map(lambda x: x[1][1] + x[1][2][0], sem.var_table[state.current_call].items()) + [0]
            )  # Gets the last available address
            sem.var_table[state.current_call][arg][1] = dir  # Updates the starting address
            sem.var_table[state.current_call][arg][2] = (
                [var[1][2][0] / max(sum(var[1][2][1 : state.arr_current_dim + 1]), 1)]
                + var[1][2][state.arr_current_dim + 1 :]
            )  # Updates the size and dimensions of the variable with the passed parameter
            sem.var_table[state.current_call][arg][4] = var[1][4][
                state.arr_current_dim :
            ]  # Updates the m of each dimension
    func.generate_param(param)
    for x in range(0, state.arr_current_dim):
        type = type[:-2]
    state.signature.append(type)
Пример #7
0
def p_generate_read(p):
    """Generate_Read : """
    rw.read_quad(p[-3], sem.get_variable(p[-1]))