Exemplo n.º 1
0
        protected TypeValidationResult CheckType(PrimitiveType leftType, PrimitiveType rightType, PrimitiveType returnType, string operatorName)
        {
            var leftResult = Left.CheckType();

            if (leftResult.HasError)
            {
                return(leftResult);
            }

            if (leftResult.Type.Equals(leftType) == false)
            {
                return(TypeValidationResult.Invalid(Position, $"{operatorName} left expression is not {leftType}"));
            }

            var rightResult = Right.CheckType();

            if (rightResult.HasError)
            {
                return(rightResult);
            }

            if (rightResult.Type.Equals(rightType) == false)
            {
                return(TypeValidationResult.Invalid(Position, $"{operatorName} right expression is not {rightType}"));
            }

            Type = returnType;
            return(TypeValidationResult.Valid(Type));
        }
Exemplo n.º 2
0
        public override TypeValidationResult CheckType()
        {
            if (SymbolTable.FormalExists(Value) == false)
            {
                return(TypeValidationResult.Invalid(Position, $"Use of undeclared identifier {Value} in function {SymbolTable.CurrentFunction}"));
            }

            Type = SymbolTable.FormalType(Value);
            return(TypeValidationResult.Valid(Type));
        }
Exemplo n.º 3
0
        public override TypeValidationResult CheckType()
        {
            Type = new IntegerType();

            var result = Right.CheckType();

            if (result.HasError)
            {
                return(result);
            }

            if (Type.Equals(result.Type) == false)
            {
                return(TypeValidationResult.Invalid(Position, $"Negate operator called with expression which is not integer"));
            }

            return(TypeValidationResult.Valid(Type));
        }