public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Hijos. //-------------------------------------------------- this.IfNode.CheckSemantics(scope, errors); this.ThenNode.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) { 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 )); return; } //-------------------------------------------------- // El Cuerpo Del IfThen No Puede Devolver. //-------------------------------------------------- if (this.ThenNode.ExpressionType != PredefinedTypes.VoidType) { errors.Add(SemanticError.ExpectedType(PredefinedTypes.VoidType, this.ThenNode.ExpressionType, this.ThenNode )); } else { this.ExpressionType = PredefinedTypes.VoidType; } }
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) { //-------------------------------------------------- // 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; } }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Hacer 'CheckSemantics' A Los Hijos. //-------------------------------------------------- this.LoNode.CheckSemantics(scope, errors); this.HiNode.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.LoNode.ExpressionType == PredefinedTypes.ErrorType || this.HiNode.ExpressionType == PredefinedTypes.ErrorType) { return; } //-------------------------------------------------- // Ambos Nodos, LoNode & HiNode, Deben Ser De Tipo <int>. //-------------------------------------------------- if (this.LoNode.ExpressionType != PredefinedTypes.IntType || this.HiNode.ExpressionType != PredefinedTypes.IntType) { if (this.LoNode.ExpressionType != PredefinedTypes.IntType) { errors.Add(SemanticError.ExpectedType(PredefinedTypes.IntType, this.LoNode.ExpressionType, this.LoNode)); } if (this.HiNode.ExpressionType != PredefinedTypes.IntType) { errors.Add(SemanticError.ExpectedType(PredefinedTypes.IntType, this.HiNode.ExpressionType, this.HiNode)); } return; } //-------------------------------------------------- // Definir Un Nuevo Scope Con La Variable De Iteración // Incluída. //-------------------------------------------------- this.ID.VariableInfo = new VariableInfo(this.ID.Name, PredefinedTypes.IntType, true); Scope InnerScope = scope.CreateChildScope(); InnerScope.Add(this.ID.VariableInfo); //-------------------------------------------------- // Hacer 'CheckSemantics' En El Cuerpo Del For. //-------------------------------------------------- this.BodyNode.CheckSemantics(InnerScope, errors); //-------------------------------------------------- // Si Hay Errores En El Cuerpo Del For, Parar De // Reportar Errores. //-------------------------------------------------- if (this.BodyNode.ExpressionType == PredefinedTypes.ErrorType) { return; } //-------------------------------------------------- // El Cuerpo Del For No Puede Devolver Valor. //-------------------------------------------------- if (this.BodyNode.ExpressionType != PredefinedTypes.VoidType) { errors.Add(SemanticError.ExpectedType(PredefinedTypes.VoidType, this.BodyNode.ExpressionType, this)); } else { this.ExpressionType = PredefinedTypes.VoidType; } }