def Evaluate(self, SymbolTable, whileFlag=0): value_obj = self.children[0].Evaluate(SymbolTable, whileFlag) value = value_obj.getValue() if (self.value == "-"): result = Value("int") result.setValue(value * -1) return result elif (self.value == "not"): if value_obj.type == "boolean": result = Value("boolean") result.setValue(not value) return result else: raise ValueError("Operand must be a boolean") else: return
def Evaluate(self, SymbolTable, whileFlag=0, nodeId=None): value1_obj = self.children[0].Evaluate(SymbolTable, whileFlag) self.generateAsm(SymbolTable, "push", whileFlag) value2_obj = self.children[1].Evaluate(SymbolTable, whileFlag) self.generateAsm(SymbolTable, "pop", whileFlag) value1 = value1_obj.getValue() value2 = value2_obj.getValue() if (self.value == "+"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_sum = value1 + value2 self.generateAsm(SymbolTable, "ADD", whileFlag) result = Value("int") result.setValue(value_sum) return result elif (self.value == "-"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_sub = value1 - value2 self.generateAsm(SymbolTable, "SUB", whileFlag) result = Value("int") result.setValue(value_sub) return result elif (self.value == "or"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_or = value1 or value2 self.generateAsm(SymbolTable, "OR", whileFlag) result = Value("boolean") result.setValue(value_or) return result elif (self.value == "*"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_mult = value1 * value2 self.generateAsm(SymbolTable, "IMUL", whileFlag) result = Value("int") result.setValue(value_mult) return result elif (self.value == "/"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_div = value1 // value2 result = Value("int") self.generateAsm(SymbolTable, "DIV", whileFlag) result.setValue(value_div) return result elif (self.value == "and"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_and = value1 and value2 self.generateAsm(SymbolTable, "AND", whileFlag) result = Value("boolean") result.setValue(value_and) return result elif (self.value == ">"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") self.generateAsm(SymbolTable, "jg", whileFlag, nodeId) value_bigger = value1 > value2 result = Value("boolean") result.setValue(value_bigger) return result elif (self.value == "<"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") self.generateAsm(SymbolTable, "jl", whileFlag, nodeId) value_smaller = value1 < value2 result = Value("boolean") result.setValue(value_smaller) return result elif (self.value == "="): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") self.generateAsm(SymbolTable, "je", whileFlag, nodeId) value_equal = value1 == value2 result = Value("boolean") result.setValue(value_equal) return result elif (self.value == "!="): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_diff = value1 != value2 result = Value("boolean") result.setValue(value_diff) return result else: return
def Evaluate(self, SymbolTable, whileFlag=0): result = input() value = Value("int") value.setValue(int(result)) return value
def Evaluate(self, SymbolTable, whileFlag=0): self.generateAsm(SymbolTable, whileFlag) value = Value("boolean") value.setValue(self.value) return value
def Evaluate(self, SymbolTable, whileFlag=0): value = Value("string") value.setValue(self.value) return value
def Evaluate(self, SymbolTable): value1_obj = self.children[0].Evaluate(SymbolTable) value2_obj = self.children[1].Evaluate(SymbolTable) value1 = value1_obj.getValue() value2 = value2_obj.getValue() if (self.value == "+"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_sum = value1 + value2 result = Value("int") result.setValue(value_sum) return result elif (self.value == "-"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_sub = value1 - value2 result = Value("int") result.setValue(value_sub) return result elif (self.value == "or"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_or = value1 or value2 result = Value("boolean") result.setValue(value_or) return result elif (self.value == "*"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_mult = value1 * value2 result = Value("int") result.setValue(value_mult) return result elif (self.value == "/"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_div = value1 // value2 result = Value("int") result.setValue(value_div) return result elif (self.value == "and"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_and = value1 and value2 result = Value("boolean") result.setValue(value_and) return result elif (self.value == ":="): SymbolTable.setSymbol(value1, value2) elif (self.value == ">"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_bigger = value1 > value2 result = Value("boolean") result.setValue(value_bigger) return result elif (self.value == "<"): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_smaller = value1 < value2 result = Value("boolean") result.setValue(value_smaller) return result elif (self.value == "="): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_equal = value1 == value2 result = Value("boolean") result.setValue(value_equal) return result elif (self.value == "!="): if not self.same_type(value1_obj, value2_obj): raise ValueError("Operands must be the same type") value_diff = value1 != value2 result = Value("boolean") result.setValue(value_diff) return result elif (self.value == ":"): SymbolTable.createSymbol(value1, value2) else: return
def Evaluate(self, SymbolTable): value = Value("boolean") value.setValue(self.value) return value
def Evaluate(self, SymbolTable): value = Value("string") value.setValue(self.value) return value