예제 #1
0
    def generate_stmt_foreach_code(self, p, q1, q2, q3, q4, q5, temp, temp2,
                                   temp3, temp4):
        dec = 'int ' + p[3] + ';\n'
        if dec not in self.variables:
            self.variables += dec
        self.variables += 'int ' + temp + ';\n'
        self.variables += 'int ' + temp2 + ';\n'
        self.variables += 'int ' + temp3 + ';\n'
        self.variables += 'int ' + temp4 + ';\n'

        iteration_exp = LogicTerminal()
        iteration_exp.address = q3
        iteration_exp.code += q3 + ": if (" + temp2 + ' < ' + temp4 + ") goto -;\n"
        iteration_exp.code += q4 + ": goto -;\n"
        iteration_exp.true_list = [q3]
        iteration_exp.false_list = [q4]

        p[0] = StatementTerminal()
        p[0].code = temp + ' = ' + p[
            5] + ';\n' + temp3 + ' = arr[' + temp + '];\n' + temp2 + ' = ' + temp + ' + 1;\n' + temp4 + ' = ' + temp2 + ' + ' + temp3 + ';\n'
        if iteration_exp.address:
            q1 = iteration_exp.address
        p[7].next_list_back_patch(q5)
        iteration_exp.true_list_back_patch(q2)
        if iteration_exp.address:
            p[0].code += iteration_exp.code
        else:
            p[0].code += q1 + ": " + iteration_exp.code
        p[0].code += q2 + ": " + p[3] + ' = arr[' + temp2 + '];\n' + p[7].code
        p[0].code += q5 + ": " + temp2 + " = " + temp2 + " + 1;\ngoto " + q1 + ";\n"
        p[0].next_list = iteration_exp.false_list
예제 #2
0
    def generate_case_code(self, p, q1, q2, q3):
        logical_exp = LogicTerminal()
        logical_exp.address = q1
        logical_exp.code += q1 + ": if (" + p[2].get_value(
        ) + " == $) goto -;\n"
        logical_exp.code += q2 + ": goto -;\n"
        logical_exp.true_list = [q1]
        logical_exp.false_list = [q2]

        p[0] = LogicTerminal()
        p[0].address = logical_exp.address
        if p[4].address:
            q3 = p[4].address
        logical_exp.true_list_back_patch(q3)
        p[0].code = logical_exp.code
        if p[4].address:
            p[0].code += p[4].code
        else:
            p[0].code += q3 + ': ' + p[4].code
        p[0].false_list = logical_exp.false_list