Exemplo n.º 1
0
    def __init__(self, leftExpression, rightExpression, operation):
        Expression.__init__(self, None)
        self.operation = operation
        self.leftExpression = leftExpression
        self.rightExpression = rightExpression

        # Determine the type of the expression
        # check if types of 2 expressions are the same
        if (self.leftExpression.basetype != self.rightExpression.basetype):
            raise RuntimeError(
                "The two types of the expressions in the logic expression should be the same"
            )

        if (not isinstance(self.leftExpression.basetype, BooleanType)):
            raise RuntimeError(
                "Left side of logic expression should be a bool, now: " +
                str(type(self.leftExpression.basetype)))

        if (not isinstance(self.rightExpression.basetype, BooleanType)):
            raise RuntimeError(
                "Right side of logic expression should be a bool, now: " +
                str(type(self.rightExpression.basetype)))

        # set the type of this expression
        self.basetype = BooleanType()
Exemplo n.º 2
0
    def __init__(self, expression):
        Expression.__init__(self, None)
        self.expression = expression

        if (not isinstance(expression.basetype, AddressType)):
            raise RuntimeError("Tried to dereference non address type: " +
                               str(type(self.expression.basetype)))

        self.basetype = self.expression.basetype.addressee
 def __init__(self, basetype, expression):
     Expression.__init__(self, None)
     self.expression = expression
     if basetype == "int":
         self.basetype = IntegerType()
     elif basetype == "real":
         self.basetype = RealType()
     else:
         pass
Exemplo n.º 4
0
    def __init__(self, symbol):
        """Create variable call with symbol(Symbol)"""
        Expression.__init__(self, None)
        self.basetype = symbol.basetype
        self.symbol = symbol
        self.arraySize = None

        if(type(self.symbol) == type(ArrayType)):
            self.arraySize = self.symbol.basetype.getElementsCount()
Exemplo n.º 5
0
    def __init__(self, symbol, index):
        """Call variable call with symbol(Symbol) and index(int)"""
        Expression.__init__(self, None)
        self.symbol = symbol
        self.index = index
        self.basetype = symbol.basetype

        if(index != None):
            #Call to element in array so change the basetype to the array's basetype
            self.basetype = symbol.basetype.basetype
Exemplo n.º 6
0
 def __init__(self, left_expression, right_expression, operation):
     Expression.__init__(self, None)
     self.operation = operation
     self.left_expression = left_expression
     self.right_expression = right_expression
     # 判断运算符左右的类型是否相同,不支持real和int混合运算,提供强制转换符
     if self.left_expression.basetype != self.right_expression.basetype:
         raise RuntimeError(
             "The two types of the expressions in the arithmetic expression should be the same"
         )
     self.basetype = self.left_expression.basetype
    def __init__(self, leftExpression, rightExpression, operation):
        Expression.__init__(self, None)
        self.operation = operation
        self.leftExpression = leftExpression
        self.rightExpression = rightExpression

        # Determine the type of the expression
        # check if types of 2 expressions are the same
        if(self.leftExpression.basetype != self.rightExpression.basetype):
            raise RuntimeError("The two types of the expressions in the arithmetic expression should be the same")

        # set the type of this expression
        self.basetype = BooleanType()
 def __init__(self, left_expression, right_expression, operation):
     Expression.__init__(self, None)
     self.left_expression = left_expression
     self.right_expression = right_expression
     self.operation = operation
     # print(self.left_expression.basetype, self.right_expression.basetype)
     if self.left_expression.basetype != self.right_expression.basetype:
         raise RuntimeError(
             "left and right expression must be of the same type")
     if not isinstance(self.left_expression.basetype, BooleanType):
         raise RuntimeError(
             "logic expression must be bool op bool, but now is {}".format(
                 self.left_expression.basetype))
     if not isinstance(self.right_expression.basetype, BooleanType):
         raise RuntimeError(
             "logic expression must be bool op bool, but now is {}".format(
                 self.left_expression.basetype))
     self.basetype = BooleanType
Exemplo n.º 9
0
 def __init__(self, value, basetype):
     Expression.__init__(self, None)
     if(basetype == "bool"):
         self.basetype = BooleanType()
         self.value = BooleanData(value)
     elif(basetype == "char"):
         self.basetype = CharacterType()
         self.value = CharacterData(value)
     elif(basetype == "int"):
         self.basetype = IntegerType()
         self.value = IntegerData(value)
     elif(basetype == "float"):
         self.basetype = RealType()
         self.value = RealData(value)
     elif(basetype == "string"):
         self.basetype = AddressType(ArrayType(CharacterType(), len(value)))
         self.value = StringData(value + "\0")
     else:
         raise RuntimeError("Trying to create constantexpession with unkown type")
Exemplo n.º 10
0
 def __init__(self, value, basetype):
     Expression.__init__(self, None)
     self.basetype = basetype
     self.value = value
     self.compiled_codes = None
     if self.basetype == "bool":
         self.basetype = BooleanType()
         if self.value is True:
             self.compiled_codes = "ldc b t\n"
         elif self.value is False:
             self.compiled_codes = "ldc b f\n"
         else:
             raise RuntimeError("Wrong Boolean Value")
     elif self.basetype == "int":
         self.basetype = IntegerType()
         self.compiled_codes = "ldc i {}\n".format(str(self.value))
     elif self.basetype == "real":
         self.basetype = RealType()
         self.compiled_codes = "ldc r {}\n".format(str(self.value))
     else:
         raise RuntimeError("Type {} is not supported".format(self.basetype))
    def __init__(self, leftExpression, rightExpression, operation):
        Expression.__init__(self, None)
        self.operation = operation
        self.leftExpression = leftExpression
        self.rightExpression = rightExpression


        # Determine the type of the expression
        # check if types of 2 expressions are the same
        if(self.leftExpression.basetype != self.rightExpression.basetype):
            raise RuntimeError("The two types of the expressions in the arithmetic expression should be the same")

        if(not isinstance(self.leftExpression.basetype, IntegerType) and not isinstance(self.leftExpression.basetype, RealType)):
            raise RuntimeError("Left side of arithmetic expression should be an integer or real, now: " + str(type(self.leftExpression.basetype)))

        if(not isinstance(self.rightExpression.basetype, IntegerType) and not isinstance(self.rightExpression.basetype, RealType)):
            raise RuntimeError("Right side of arithmetic expression should be an integer or real, now: " + str(type(self.rightExpression.basetype)))


        # set the type of this expression
        self.basetype = self.leftExpression.basetype
 def __init__(self, expression):
     Expression.__init__(self, None)
     self.expression = expression
     self.basetype = self.expression.basetype
Exemplo n.º 13
0
    def __init__(self, variable, expression):
        Expression.__init__(self, None)
        self.variable = variable
        self.expression = expression

        self.basetype = self.expression.basetype
    def __init__(self, function, parameters):
        Expression.__init__(self, None)
        self.function = function
        self.parameters = parameters

        self.basetype = function.returntype
Exemplo n.º 15
0
    def __init__(self, variable):
        Expression.__init__(self, None)
        self.variable = variable

        self.basetype = self.variable.basetype
Exemplo n.º 16
0
 def __init__(self, symbol):
     """Call variable call with symbol(Symbol)"""
     Expression.__init__(self, None)
     self.symbol = symbol
     self.index = None
     self.basetype = symbol.basetype