def __init__(self, test, block): super().__init__(None) self.test = test self.block = block if not Type.is_bool(test.type): raise_error( TypeError( self.lineno, "Expression inside (...) must return bool! (It returns {} instead)" .format(test.type)))
def __init__(self, ident, expr): super().__init__(None) self.ident = ident self.expr = expr if not Type.check_match(ident.type, expr.type): raise_error( TypeError( self.lineno, "Types does not match! (ident type:{}, expr type:{})". format(ident.type, expr.type)))
def __init__(self, op, operand): super().__init__(None) self.op = op self.operand = operand if not Type.is_type_ok(operand.type, op, is_unary=True): raise_error( TypeError( "Incompatible types for an operator! (operand type:{}, operator:{})" .format(operand.type, op))) self.type = Type.combine(operand.type, op)
def __init__(self, test, block, brs): super().__init__(None) self.test = test self.block = block # empty for simple if stmt, contains a element (else branch) for if-else stmt, # >1 elements means elif branch (s) preceding the else branch self.brs = brs if not Type.is_bool(test.type): raise_error( TypeError( self.lineno, "Expression inside (...) must return bool! (It returns {} instead)" .format(test.type)))
def __init__(self, ident, expr): super().__init__(None) self.ident = ident self.expr = expr if not Type.check_match(ident.type, expr.type): raise_error( TypeError( self.lineno, "Types does not match! (ident type:{}, expr type:{})". format(ident.type, expr.type))) if not Type.is_type_ok(ident.type, '%='): raise_error( TypeError( self.lineno, "Incompatible types for an operator (type:{}, operator:{})" .format(ident.type, '%=')))
def __init__(self, left, right, op): super().__init__(None) self.left = left self.right = right self.op = op if not Type.check_match(left.type, right.type): raise_error( TypeError( self.lineno, "Types does not match! (left operand type:{}, right operand type:{})" .format(left.type, right.type))) if not Type.is_type_ok(left.type, op): raise_error( TypeError( self.lineno, "Incompatible types for an operator (operand type:{}, operator:{})" .format(left.type, op))) self.type = Type.combine(left.type, op)