public override bool CheckSemantic(List <Error> errors, SymbolTable symbolTable) { //Check Operands if (LeftOperand.CheckSemantic(errors, symbolTable) & RightOperand.CheckSemantic(errors, symbolTable)) { //Check: ILType Equals if (LeftOperand.ReturnType.IsEquivalent(RightOperand.ReturnType)) { return(true); } string message = string.Format("Could not applied operation '{0}' between operands of types '{1}' and '{2}'", Text, LeftOperand.ReturnType, RightOperand.ReturnType); errors.Add(new Error(message, Line, CharPositionInLine)); } ReturnType = TypeExpression.ErrorType; return(false); }
public override void CheckSemantic(SymbolTable symbolTable, List <CompileError> errors) { ///check semantics al operando izquierdo LeftOperand.CheckSemantic(symbolTable, errors); ///check semantics al operando derecho RightOperand.CheckSemantic(symbolTable, errors); ///si alguno de los operandos evalúa de error este nodo también if (Object.Equals(LeftOperand.NodeInfo, SemanticInfo.SemanticError) || Object.Equals(RightOperand.NodeInfo, SemanticInfo.SemanticError)) { ///el nodo evalúa de error NodeInfo = SemanticInfo.SemanticError; return; } //los operandos tienen que ser compatibles if (!LeftOperand.NodeInfo.Type.IsCompatibleWith(RightOperand.NodeInfo.Type)) { errors.Add(new CompileError { Line = LeftOperand.Line, Column = LeftOperand.CharPositionInLine, ErrorMessage = string.Format("Operand '{0}' cannot be applied to operands of type '{1}' and '{2}'", this.Text, LeftOperand.NodeInfo.Type.Name, RightOperand.NodeInfo.Type.Name), Kind = ErrorKind.Semantic }); ///el nodo evalúa de error NodeInfo = SemanticInfo.SemanticError; } ///seteamos la información del NodeInfo NodeInfo.BuiltInType = BuiltInType.Int; NodeInfo.Type = SemanticInfo.Int; NodeInfo.ILType = typeof(int); }