Exemple #1
0
 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)
Exemple #2
0
 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")
Exemple #3
0
 def expression(self):
     return ExpressionBase(self.values, self.kind, self)
Exemple #4
0
 def eval(self):
     self.value = self.exp.eval()
     self.kind = self.exp.kind
     return ExpressionBase(self.value, self.kind)
Exemple #5
0
 def get(self, indice):
     return ExpressionBase(None, "none")
Exemple #6
0
 def __init__(self, exp):
     self.exp = exp
     self.kind = FloatType(ExpressionBase(0.0, "float"))
Exemple #7
0
 def __init__(self, exp, value):
     self.value = value
     self.exp = exp
     self.kind = BoolType(ExpressionBase(True, "boolean"))
Exemple #8
0
 def __init__(self, exp):
     self.exp = exp
     self.kind = IntType(ExpressionBase(0, "integer"))
Exemple #9
0
 def __init__(self, text=""):
     self.text = text
     self.kind = StrType(ExpressionBase("", "string"))
Exemple #10
0
 def __init__(self, value=ExpressionBase("", "string")):
     self.value = value
     self.kind = StrType(ExpressionBase("", "string"))
Exemple #11
0
 def __init__(self, exp):
     self.exp = exp
     self.kind = StrType(ExpressionBase("", "string"))
Exemple #12
0
 def logicoperator1(p):
     return ExpressionBase(Not(p[1]).eval(), "boolean")