Esempio 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));
        }
Esempio 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));
        }
Esempio n. 3
0
        public override TypeValidationResult CheckType()
        {
            var result = Expr.CheckType();

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

            Type = result.Type;
            return(TypeValidationResult.Valid(Type));
        }
Esempio n. 4
0
 public void AddSemanticError(TypeValidationResult result)
 {
     if (result.HasError)
     {
         ErrorType  = ErrorTypeEnum.Semantic;
         Position   = result.Position;
         Message    = result.Message;
         StackTrace = null;
     }
     else
     {
         AddNoError();
     }
 }
Esempio n. 5
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));
        }
Esempio n. 6
0
 public override TypeValidationResult CheckType()
 {
     Type = new BooleanType();
     return(TypeValidationResult.Valid(Type));
 }
Esempio n. 7
0
        public override TypeValidationResult CheckType()
        {
            Type = new IntegerType();

            return(TypeValidationResult.Valid(Type));
        }