Beispiel #1
0
    def division_type(cls, other_type, pos):
        if other_type == float_:
            return float_
        if other_type == int_:
            return float_

        ErrorHandler.error(IncompatibleTypesError(
            f"Types {cls} and {other_type} are not compatible for division", pos))
Beispiel #2
0
    def and_type(cls, other_type, pos):
        """Return the resulting type from a and operation with 
        this type and other variable's type or raise and error if it
        is not supported.

        Args:
            other_type (type_): Type of the other variable.
            pos (int): Position of the statement to use in errors.
        """

        ErrorHandler.error(IncompatibleTypesError(
            f"{cls} type doesn't support and operation", pos))
Beispiel #3
0
    def compare_type(cls, other_type, pos):
        """Return the resulting type from a compare operation with 
        this type and other variable's type or raise and error if it
        is not supported.

        Args:
            other_type (type_): Type of the other variable.
            pos (int): Position of the statement to use in errors.
        """
        
        if cls != other_type:
            ErrorHandler.error(IncompatibleTypesError(
                f"Types {cls} and {other_type} are not compatible for comparison", pos))
            return
        return bool_
Beispiel #4
0
 def or_type(cls, other_type, pos):
     if other_type == bool_:
         return bool_
     ErrorHandler.error(IncompatibleTypesError(
         f"Types {cls} and {other_type} are not compatible for or operation", pos))