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)); }
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)); }
public override TypeValidationResult CheckType() { var result = Expr.CheckType(); if (result.HasError) { return(result); } Type = result.Type; return(TypeValidationResult.Valid(Type)); }
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)); }
public override TypeValidationResult CheckType() { Type = new BooleanType(); return(TypeValidationResult.Valid(Type)); }
public override TypeValidationResult CheckType() { Type = new IntegerType(); return(TypeValidationResult.Valid(Type)); }