public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Dos Hijos. //-------------------------------------------------- this.LeftOperandNode.CheckSemantics(scope, errors); this.RightOperandNode.CheckSemantics(scope, errors); //-------------------------------------------------- // Poner El Valor De Retorno De La Expresión A 'Error' // Por Default. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Si Ha Ocurrido Un Error En Alguno De Los Hijos, // Parar De Reportar Errores. //-------------------------------------------------- if (this.LeftOperandNode.ExpressionType == PredefinedTypes.ErrorType || this.RightOperandNode.ExpressionType == PredefinedTypes.ErrorType) { return; } //-------------------------------------------------- // Se Pueden Comparar Solamente Expresiones Del // Mismo Tipo. Tener Cuidado De: // // <void> ( = , != ) <void> // <null> ( = , != ) <null> //-------------------------------------------------- if (this.LeftOperandNode.ExpressionType == this.RightOperandNode.ExpressionType) { if (this.LeftOperandNode.ExpressionType == PredefinedTypes.VoidType || this.LeftOperandNode.ExpressionType == PredefinedTypes.NilType) { errors.Add(SemanticError.InvalidCompareOperation(this.LeftOperandNode.ExpressionType, this.RightOperandNode.ExpressionType, this)); return; } } if (SemanticError.CompatibleTypes(this.LeftOperandNode.ExpressionType, this.RightOperandNode.ExpressionType) || SemanticError.CompatibleTypes(this.RightOperandNode.ExpressionType, this.LeftOperandNode.ExpressionType)) { this.ExpressionType = PredefinedTypes.IntType; } else { errors.Add(SemanticError.InvalidCompareOperation(this.LeftOperandNode.ExpressionType, this.RightOperandNode.ExpressionType, this)); } //-------------------------------------------------- // //-------------------------------------------------- }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Hijos. //-------------------------------------------------- this.IfNode.CheckSemantics(scope, errors); this.ThenNode.CheckSemantics(scope, errors); this.ElseNode.CheckSemantics(scope, errors); //-------------------------------------------------- // Poner El Valor De Retorno De La Expresión A 'Error' // Por Default. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Si Ha Ocurrido Un Error En Alguno De Los Hijos, // Parar De Reportar Errores. //-------------------------------------------------- if (this.IfNode.ExpressionType == PredefinedTypes.ErrorType || this.ThenNode.ExpressionType == PredefinedTypes.ErrorType || this.ElseNode.ExpressionType == PredefinedTypes.ErrorType) { return; } //-------------------------------------------------- // La Condición Debe Ser De Tipo <int>. //-------------------------------------------------- if (this.IfNode.ExpressionType != PredefinedTypes.IntType) { errors.Add(SemanticError.InvalidTypeConvertion(PredefinedTypes.IntType, this.IfNode.ExpressionType, this.IfNode)); } else { //-------------------------------------------------- // Debe Haber Conversión Entre El Tipo Del 'Then' Y // Del 'Else'. //-------------------------------------------------- if (SemanticError.CompatibleTypes(this.ThenNode.ExpressionType, this.ElseNode.ExpressionType)) { this.ExpressionType = this.ThenNode.ExpressionType; } else if (SemanticError.CompatibleTypes(this.ElseNode.ExpressionType, this.ThenNode.ExpressionType)) { this.ExpressionType = this.ElseNode.ExpressionType; } else { errors.Add(SemanticError.IncompatibleTypesInIfThenElse(this)); } } }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Hijos. //-------------------------------------------------- this.LeftVariable.CheckSemantics(scope, errors); this.Value.CheckSemantics(scope, errors); //-------------------------------------------------- // Poner Por Defecto Que Hay Errores. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Si Ha Ocurrido Un Error En Alguno De Los Hijos, // Parar De Reportar Errores. //-------------------------------------------------- if (this.LeftVariable.ExpressionType == PredefinedTypes.ErrorType || this.Value.ExpressionType == PredefinedTypes.ErrorType) { return; } if (this.LeftVariable.ReadOnly) { errors.Add(SemanticError.InvalidUseOfAssignmentToAReadonlyVariable(this.LeftVariable)); return; } if (!SemanticError.CompatibleTypes(this.LeftVariable.ExpressionType, this.Value.ExpressionType)) { errors.Add(SemanticError.ExpectedType(this.LeftVariable.ExpressionType, this.Value.ExpressionType, this)); } else { this.ExpressionType = PredefinedTypes.VoidType; } }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Hijos. //-------------------------------------------------- this.Size.CheckSemantics(scope, errors); this.Value.CheckSemantics(scope, errors); //-------------------------------------------------- // Poner El Valor De Retorno De La Expresión A 'Error' // Por Default. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Si Ha Ocurrido Un Error En Alguno De Los Hijos, // Parar De Reportar Errores. //-------------------------------------------------- if (this.Size.ExpressionType == PredefinedTypes.ErrorType || this.Value.ExpressionType == PredefinedTypes.ErrorType) { return; } //-------------------------------------------------- // Buscar Por El Tipo Del Array //-------------------------------------------------- var TI = scope.FindTypeInfo(this.TypeID.Name); //-------------------------------------------------- // Si El Tipo No Está Definido, Reportar Error. //-------------------------------------------------- if (TI == null) { errors.Add(SemanticError.TypeDoesNotExist(this.TypeID.Name, this.TypeID)); return; } var ArrayType = TI.TypeNode as ArrayTypeNode; //-------------------------------------------------- // Si El Tipo No Es Un Array. //-------------------------------------------------- if (ArrayType == null) { errors.Add(SemanticError.ArrayTypeExpected(TI.TypeNode, this.TypeID)); return; } //-------------------------------------------------- // 'Size' Debe Ser De Tipo <int>. //-------------------------------------------------- if (this.Size.ExpressionType != PredefinedTypes.IntType) { errors.Add(SemanticError.ExpectedType(PredefinedTypes.IntType, this.Size.ExpressionType, this.Size)); return; } //-------------------------------------------------- // 'Value' Debe Ser Del Mismo Tipo Que El Array. //-------------------------------------------------- if (!SemanticError.CompatibleTypes(ArrayType.ArrayOf, this.Value.ExpressionType)) { errors.Add(SemanticError.ExpectedType(ArrayType.ArrayOf, this.Value.ExpressionType, this.Value)); return; } this.ExpressionType = ArrayType; }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Buscar El FunctionInfo Correspondiente. //-------------------------------------------------- this.FunctionInfo = scope.FindFunctionInfo(ID.Name); //-------------------------------------------------- // Poner Por Defecto Que Hay Errores. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Si La Función No Existe, Reportar Error. //-------------------------------------------------- if (this.FunctionInfo == null) { errors.Add(SemanticError.FunctionDoesNotExist(this.ID.Name, this)); return; } //-------------------------------------------------- // Si La Cantidad De Argumentos Es Diferente A La // Cantidad De Parámetros, Reportar Error. //-------------------------------------------------- var parameters = this.FunctionInfo.Parameters; if (this.Arguments.Count() != parameters.Length) { errors.Add(SemanticError.WrongParameterNumber(this.ID.Name, parameters.Length, this.Arguments.Count(), this)); return; } //-------------------------------------------------- // Hacer 'CheckSemantics' A Cada Argumento. //-------------------------------------------------- bool IsOk = true; foreach (var argument in this.Arguments) { argument.CheckSemantics(scope, errors); if (argument.ExpressionType == PredefinedTypes.ErrorType) { IsOk = false; } } //-------------------------------------------------- // Si Hay Errores En Los Argumentos, Parar De // Reportar Errores. //-------------------------------------------------- if (!IsOk) { return; } //-------------------------------------------------- // Comprobar Que Los Tipos De Los Argumentos Son Iguales // A Los Tipos De Los Parámetros Correspondientes. //-------------------------------------------------- for (int i = 0; i < parameters.Length; i++) { var arg = this.Arguments.ElementAt(i); if (!SemanticError.CompatibleTypes(parameters[i].TypeNode, arg.ExpressionType)) { errors.Add(SemanticError.InvalidTypeConvertion(parameters[i].TypeNode, arg.ExpressionType, arg)); IsOk = false; } } if (IsOk) { this.ExpressionType = this.FunctionInfo.ReturnType; } }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Poner El Valor De Retorno De La Expresión A 'Error' // Por Default. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Buscar Por El Tipo Del Record. //-------------------------------------------------- var TI = scope.FindTypeInfo(this.TypeID.Name); //-------------------------------------------------- // Si El Tipo No Está Definido, Reportar Error. //-------------------------------------------------- if (TI == null) { errors.Add(SemanticError.TypeDoesNotExist(this.TypeID.Name, this.TypeID)); return; } var RecordType = TI.TypeNode as RecordTypeNode; //-------------------------------------------------- // Si El Tipo No Es Un Record. //-------------------------------------------------- if (RecordType == null) { errors.Add(SemanticError.RecordTypeExpected(TI.TypeNode, this.TypeID)); return; } //-------------------------------------------------- // La Cantidad De Campos Debe Ser La Misma. //-------------------------------------------------- if (this.Fields.Length != RecordType.Fields.Length) { errors.Add(SemanticError.WrongFieldNumberInRecord(RecordType.Name, RecordType.Fields.Length, this.Fields.Length, this)); return; } //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Campos Del Record. //-------------------------------------------------- bool IsOk = true; foreach (var field in this.Fields) { field.CheckSemantics(scope, errors); if (field.ExpressionType == PredefinedTypes.ErrorType) { IsOk = false; } } if (!IsOk) { return; } //-------------------------------------------------- // Comprobar El Orden De Los Campos Y Los Tipos. //-------------------------------------------------- for (int i = 0; i < this.Fields.Length; i++) { if (this.Fields[i].ID.Name != RecordType.Fields[i].ID.Name) { IsOk = false; errors.Add(SemanticError.WrongFieldNameInRecord( this.Fields[i].ID.Name, RecordType.Fields[i].ID.Name, this.Fields[i] )); } if (!SemanticError.CompatibleTypes(RecordType.Fields[i].VariableInfo.TypeNode, this.Fields[i].ExpressionType)) { IsOk = false; errors.Add(SemanticError.ExpectedType( RecordType.Fields[i].VariableInfo.TypeNode, this.Fields[i].ExpressionType, this.Fields[i] )); } } if (IsOk) { this.ExpressionType = RecordType; } }