public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children LValueNode.CheckSemantics(scope, report); IndexExpressionNode.CheckSemantics(scope, report); if (!LValueNode.IsOK || !IndexExpressionNode.IsOK) { return; } //Check children types if (!(LValueNode.TigerType is ArrayType)) { report.AddError(SemanticErrors.NonArrayType(LValueNode, LValueNode.TigerType)); return; } if (!TigerType.Int.Assignable(IndexExpressionNode.TigerType)) { report.AddError(SemanticErrors.ArrayIndexerInvalidType(IndexExpressionNode, IndexExpressionNode.TigerType)); return; } TigerType = ((ArrayType)LValueNode.TigerType).ContentType; }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Checking Children TypeNode.CheckSemantics(scope, report); LengthExpressionNode.CheckSemantics(scope, report); InitialValueExpressionNode.CheckSemantics(scope, report); if (!TypeNode.IsOK || !LengthExpressionNode.IsOK || !InitialValueExpressionNode.IsOK) { return; } var type = TypeNode.TigerType as ArrayType; if (type == null) { report.AddError(SemanticErrors.NonArrayType(TypeNode, TypeNode.TigerType)); return; } TigerType = TypeNode.TigerType; //Checking LengthExpression type if (!TigerType.AreCompatible(LengthExpressionNode.TigerType, TigerType.Int)) { report.AddError(SemanticErrors.NonIntegerArrayLength(LengthExpressionNode, LengthExpressionNode.TigerType)); } //Checking InitialValueExpression if (!type.ContentType.Assignable(InitialValueExpressionNode.TigerType)) { report.AddError(SemanticErrors.ArrayInitialValueInvalidType(InitialValueExpressionNode, InitialValueExpressionNode.TigerType, TypeNode.TigerType)); } }