Пример #1
0
def p_bool_expressions_or(p):
    """bool_expressions     : OR pair"""
    first_arg = p[2]["first_arg"]
    second_arg = p[2]["second_arg"]
    if "t_list" not in first_arg:
        code_array.create_simple_if_check(first_arg)
    if "t_list" not in second_arg:
        p[2]["second_quad_index"] = code_array.create_simple_if_check(
            second_arg)
    temp_var = symbol_table.get_new_temp_variable("bool")
    code_array.emit('=', temp_var, {"value": 1, "type": "bool"}, None)
    code_array.backpatch_e_list(first_arg["t_list"],
                                code_array.get_current_quad_index())
    code_array.emit('goto', None, p[2]["second_quad_index"], None)
    code_array.emit('=', temp_var, {"value": 0, "type": "bool"}, None)
    code_array.backpatch_e_list(first_arg["f_list"],
                                code_array.get_current_quad_index())
    code_array.emit('goto', None, p[2]["second_quad_index"], None)
    code_array.create_simple_if_check(temp_var)
    code_array.backpatch_e_list(second_arg["f_list"],
                                code_array.get_current_quad_index() - 2)
    p[0] = {
        "t_list":
        code_array.merge_e_lists(temp_var["t_list"], second_arg["t_list"]),
        "f_list":
        temp_var["f_list"],
        "type":
        "bool"
    }
    return
Пример #2
0
def p_bool_expressions_or_else(p):
    """bool_expressions     : OR ELSE pair"""
    first_arg = p[3]["first_arg"]
    second_arg = p[3]["second_arg"]
    if "t_list" not in first_arg:
        code_array.create_simple_if_check(first_arg)
    if "t_list" not in second_arg:
        p[3]["second_quad_index"] = code_array.create_simple_if_check(
            second_arg)
    code_array.backpatch_e_list(first_arg["f_list"], p[3]["second_quad_index"])
    p[0] = {
        "f_list":
        second_arg["f_list"],
        "t_list":
        code_array.merge_e_lists(first_arg["t_list"], second_arg["t_list"]),
        "type":
        "bool"
    }
    return
Пример #3
0
def p_statement_list(p):
    """statement_list       : statement SEMICOLON
                            | statement_list statement SEMICOLON"""
    if len(p) == 3:
        new_statement = p[1]
        old_statements = None
    else:
        new_statement = p[2]
        old_statements = p[1]
    if new_statement and "exit_when_quad_index" in new_statement:
        if old_statements and "exit_when_quad_index" in old_statements:
            p[0] = {
                "exit_when_quad_index":
                code_array.merge_e_lists(
                    new_statement["exit_when_quad_index"],
                    old_statements["exit_when_quad_index"])
            }
        else:
            p[0] = new_statement
    else:
        p[0] = old_statements
    return