public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children IdNode.CheckSemantics(scope, report); FromExpression.CheckSemantics(scope, report); ToExpression.CheckSemantics(scope, report); if (!IdNode.IsOK || !FromExpression.IsOK || !ToExpression.IsOK) { return; } //Check loop bounds type if (!TigerType.AreCompatible(FromExpression.TigerType, TigerType.Int) || !TigerType.AreCompatible(ToExpression.TigerType, TigerType.Int)) { report.AddError(!TigerType.AreCompatible(FromExpression.TigerType, TigerType.Int) ? SemanticErrors.InvalidForBoundType(FromExpression, FromExpression.TigerType) : SemanticErrors.InvalidForBoundType(ToExpression, ToExpression.TigerType)); return; } IsOK = true; //Define new scope TigerScope childScope = new TigerScope(scope, "For"); VariableInfo = childScope.DefineVariable(IdNode.Name, TigerType.Int, ContainingScope, false); DoInstruction.CheckSemantics(childScope, report); if (!DoInstruction.IsOK) { return; } if (!TigerType.AreCompatible(DoInstruction.TigerType, TigerType.Void)) { report.AddError(SemanticErrors.InvalidForBodyType(DoInstruction)); IsOK = false; } }