def do(self, stacks): sym1_type, sym1_val = self.__get_operands__(stacks, self.arg2) if sym1_type != Argument.type_string: raise WrongOperandsType(f" {self.opCode} {self.order}") res_value = len(sym1_val) stacks[self.arg1.frame].assign(self.arg1, Argument.type_int, res_value) return super().do(stacks)
def do(self, stacks): sym2_type, sym2_val = stacks["Data"].pop() sym1_type, sym1_val = stacks["Data"].pop() if sym1_type == sym2_type or sym1_type == Argument.type_nil or sym2_type == Argument.type_nil: pass else: raise WrongOperandsType(f" {self.opCode} {self.order}") return (sym1_val != sym2_val, False), stacks["label"].get(self.arg1)
def do(self, stacks): sym1_type, sym1_val = self.__get_operands__(stacks, self.arg2) sym2_type, sym2_val = self.__get_operands__(stacks, self.arg3) if sym1_type == sym2_type or sym1_type == Argument.type_nil or sym2_type == Argument.type_nil: pass else: raise WrongOperandsType(f" {self.opCode} {self.order}") return (sym1_val == sym2_val, False), stacks["label"].get(self.arg1)
def do(self, stacks): sym2_type, sym2_val = stacks["Data"].pop() sym1_type, sym1_val = stacks["Data"].pop() if sym1_type != sym2_type or sym1_type == Argument.type_nil or sym2_type == Argument.type_nil: raise WrongOperandsType(f" {self.opCode} {self.order}") res_value = sym1_val > sym2_val stacks["Data"].append((Argument.type_bool, res_value)) return super().do(stacks)
def do(self, stacks): sym1_type, sym1_val = self.__get_operands__(stacks, self.arg2) sym2_type, sym2_val = self.__get_operands__(stacks, self.arg3) if sym1_type != sym2_type or sym1_type == Argument.type_nil or sym2_type == Argument.type_nil: raise WrongOperandsType(f" {self.opCode} {self.order}") res_value = sym1_val > sym2_val stacks[self.arg1.frame].assign(self.arg1, Argument.type_bool, res_value) return super().do(stacks)
def do(self, stacks): i_type, val = (self.arg1.i_type, self.arg1.value) if self.arg1.i_type == Argument.type_var: i_type, val = stacks[self.arg1.frame].get(self.arg1) if i_type != Argument.type_int: raise WrongOperandsType(f" {self.opCode} {self.order}") if val not in range(0, 50): raise BadValueError(f" {self.opCode} {self.order}") sys.exit(val)
def do(self, stacks): sym1_type, sym1_val = self.__get_operands__(stacks, self.arg2) sym2_type, sym2_val = self.__get_operands__(stacks, self.arg3) if sym1_type != Argument.type_string or sym2_type != Argument.type_int: raise WrongOperandsType(f" {self.opCode} {self.order}") if sym2_val not in range(0, len(sym1_val)): raise StringOperationError(f" {self.opCode} {self.order}") res_value = sym1_val[sym2_val] stacks[self.arg1.frame].assign(self.arg1, Argument.type_string, res_value) return super().do(stacks)
def do(self, stacks): res_type, res_val = stacks[self.arg1.frame].get(self.arg1) sym1_type, sym1_val = self.__get_operands__(stacks, self.arg2) sym2_type, sym2_val = self.__get_operands__(stacks, self.arg3) if sym1_type != Argument.type_int or sym2_type != Argument.type_string or res_type != Argument.type_string: raise WrongOperandsType(f" {self.opCode} {self.order}") if sym1_val not in range(0, len(res_val)) or len(sym2_val) == 0: raise StringOperationError(f" {self.opCode} {self.order}") res_val = list(res_val) res_val[sym1_val] = sym2_val[0] res_value = "".join(res_val) stacks[self.arg1.frame].assign(self.arg1, res_type, res_value) return super().do(stacks)