def generate_exp_assign_code(self, p, q1, q2, q3): p[0] = StatementTerminal() p[0].place = p[1] p[0].address = p[3].address if isinstance(p[3], StatementTerminal): p[0].next_list = p[3].next_list if isinstance(p[3], LogicTerminal): p[3].true_list_back_patch(q1) p[3].false_list_back_patch(q2) p[0].code = p[3].code + q1 + ': ' + p[ 1] + ' = ' + '1;\n' + q3 + ': goto -;\n' + q2 + ': ' + p[ 1] + ' = ' + '0;\n' p[0].next_list = [q3] else: p[0].code = p[3].code + p[1] + ' = ' + p[3].get_value() + ';\n'
def generate_exp_fun_code(self, p, temp, temp2, q1, q2): self.variables += "int " + temp + ";\n" self.variables += "int " + temp2 + ";\n" p[0] = StatementTerminal() p[0].code = f'arr[stack_p] = arr_p;\n' \ f'stack_p = stack_p - 1;\n' \ f'{temp2} = 0;\n' \ f'forward_jmp(arr_p);\n' \ f'{q1}: if({temp2} == 1) goto -;\n' \ f'arr_p = arr_p + 64;\n' \ f'{temp2} = 1;\n' p[0].next_list = [q1] if p[1] in self.function_dict.keys(): p[0].code += f'goto {self.function_dict[p[1]]};\n' else: p[0].code += f'goto ?;\n' p[0].code += f'{q2}: stack_p = stack_p + 1;\n' \ f'{temp} = arr[stack_p];\n' p[0].place = temp p[0].next_list_back_patch(q2)
def generate_lvalue_code(self, p, temp, temp2, temp3, q1, q2, q3): p[0] = StatementTerminal() p[0].address = p[3].address p[0].place = temp p[0].code = p[3].code + temp2 + ' = ' + p[3].get_value( ) + ' + 1;\n' + temp3 + ' = ' + p[1] + ' + ' + temp2 + ';\n' self.variables += 'int ' + temp + ';\n' self.variables += 'int ' + temp2 + ';\n' self.variables += 'int ' + temp3 + ';\n' if isinstance(p[6], StatementTerminal): p[0].next_list = p[6].next_list if isinstance(p[6], LogicTerminal): p[6].true_list_back_patch(q1) p[6].false_list_back_patch(q2) p[0].code += p[ 6].code + q1 + ": arr[" + temp3 + "] = 1;\n" + q3 + ': goto -;\n' + q2 + ": arr[" + temp3 + "] = 0;\n" p[0].next_list = [q3] else: p[0].code += p[6].code + "arr[" + temp3 + "] = " + p[6].get_value( ) + ';\n' p[0].code += temp + ' = ' + "arr[" + temp3 + "];\n"