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