def uniqueop(p): ope = p[0] exp = p[1] if ope.gettokentype() == 'SUM': return Sum(ExpressionBase(0, "integer"), exp) else: return Sub(ExpressionBase(0, "integer"), exp)
def expression(p): if p[0].gettokentype() == 'FLOAT': return ExpressionBase(float(p[0].value), "float") elif p[0].gettokentype() == 'STRING': return ExpressionBase(str(p[0].value)[1:-1], "string") elif p[0].gettokentype() == 'BOOLEAN': if p[0].value == "false": return ExpressionBase(False, "boolean") return ExpressionBase(True, "boolean") elif p[0].gettokentype() == 'IDENTIFIER': var = self.var.get(p[0].value) if var is not None: return ExpressionBase(var.value, var.kind, var) else: error(errors.NOTDECLARED, "Variable is not declared.", {"type": "token", "token": p[0]}) sys.exit(1) else: return ExpressionBase(int(p[0].value), "integer")
def expression(self): return ExpressionBase(self.values, self.kind, self)
def eval(self): self.value = self.exp.eval() self.kind = self.exp.kind return ExpressionBase(self.value, self.kind)
def get(self, indice): return ExpressionBase(None, "none")
def __init__(self, exp): self.exp = exp self.kind = FloatType(ExpressionBase(0.0, "float"))
def __init__(self, exp, value): self.value = value self.exp = exp self.kind = BoolType(ExpressionBase(True, "boolean"))
def __init__(self, exp): self.exp = exp self.kind = IntType(ExpressionBase(0, "integer"))
def __init__(self, text=""): self.text = text self.kind = StrType(ExpressionBase("", "string"))
def __init__(self, value=ExpressionBase("", "string")): self.value = value self.kind = StrType(ExpressionBase("", "string"))
def __init__(self, exp): self.exp = exp self.kind = StrType(ExpressionBase("", "string"))
def logicoperator1(p): return ExpressionBase(Not(p[1]).eval(), "boolean")