public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Checking children Condition.CheckSemantics(scope, report); IfBlock.CheckSemantics(scope, report); ElseBlock.CheckSemantics(scope, report); if (!Condition.IsOK || !IfBlock.IsOK || !ElseBlock.IsOK) { return; } TigerType = IfBlock.TigerType; //Checking children types if (!TigerType.AreCompatible(Condition.TigerType, TigerType.Int)) { report.AddError(SemanticErrors.InvalidConditionType(Condition, Condition.TigerType)); } if (!TigerType.AreCompatible(IfBlock.TigerType, ElseBlock.TigerType)) { report.AddError(SemanticErrors.IncompatibleIfElseReturnType(ElseBlock, IfBlock.TigerType, ElseBlock.TigerType)); } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children LeftOperandNode.CheckSemantics(scope, report); RightOperandNode.CheckSemantics(scope, report); if (!LeftOperandNode.IsOK || !RightOperandNode.IsOK) { return; } //Check children types if (TigerType.AreCompatible(LeftOperandNode.TigerType, TigerType.Int) && TigerType.AreCompatible(RightOperandNode.TigerType, TigerType.Int)) { TigerType = TigerType.Int; } else if (!TigerType.AreCompatible(LeftOperandNode.TigerType, TigerType.Int)) { report.AddError(SemanticErrors.LogicalOperandInvalidType(LeftOperandNode, LeftOperandNode.TigerType)); } else { report.AddError(SemanticErrors.LogicalOperandInvalidType(RightOperandNode, RightOperandNode.TigerType)); } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children Condition.CheckSemantics(scope, report); IfBlock.CheckSemantics(scope, report); if (!Condition.IsOK && !IfBlock.IsOK) { return; } TigerType = TigerType.Void; //Check condition type if (!TigerType.AreCompatible(TigerType.Int, Condition.TigerType)) { report.AddError(SemanticErrors.InvalidConditionType(Condition, Condition.TigerType)); TigerType = TigerType.Error; } if (!TigerType.AreCompatible(TigerType.Void, IfBlock.TigerType)) { report.AddError(SemanticErrors.InvalidIfBodyType(IfBlock)); TigerType = TigerType.Error; } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children Condition.CheckSemantics(scope, report); InstructionNode.CheckSemantics(scope, report); if (!Condition.IsOK || !InstructionNode.IsOK) { return; } IsOK = true; //Check children types if (!TigerType.AreCompatible(Condition.TigerType, TigerType.Int)) { report.AddError(SemanticErrors.InvalidConditionType(Condition, Condition.TigerType)); IsOK = false; } if (!TigerType.AreCompatible(InstructionNode.TigerType, TigerType.Void)) { report.AddError(SemanticErrors.InvalidWhileBodyType(InstructionNode)); IsOK = false; } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children InstructionNodes.ToList().ForEach(i => i.CheckSemantics(scope, report)); if (InstructionNodes.Any(e => !e.IsOK)) { return; } //If type is not void (no break found inside) assign last instruction type if (!TigerType.AreCompatible(TigerType, TigerType.Void)) { TigerType = InstructionNodes.Length == 0 ? TigerType.Void : InstructionNodes.Last().TigerType; } }
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; } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check child ExpressionNode.CheckSemantics(scope, report); if (!ExpressionNode.IsOK) { return; } //Check child type if (TigerType.AreCompatible(TigerType.Int, ExpressionNode.TigerType)) { TigerType = TigerType.Int; } else { report.AddError(SemanticErrors.ArithmeticOperandInvalidType(ExpressionNode, ExpressionNode.TigerType)); } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children LeftOperandNode.CheckSemantics(scope, report); RightOperandNode.CheckSemantics(scope, report); if (!LeftOperandNode.IsOK || !RightOperandNode.IsOK) { return; } TigerType = TigerType.Int; //Check children types if (!TigerType.AreCompatible(LeftOperandNode.TigerType, RightOperandNode.TigerType) || (TigerType.AreOfSameType(LeftOperandNode.TigerType, TigerType.Nil) && TigerType.AreOfSameType(RightOperandNode.TigerType, TigerType.Nil))) { report.AddError(SemanticErrors.InvalidIdentityComparison(this, LeftOperandNode.TigerType, RightOperandNode.TigerType)); } }
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)); } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; //Check children LeftOperandNode.CheckSemantics(scope, report); RightOperandNode.CheckSemantics(scope, report); if (!LeftOperandNode.IsOK || !RightOperandNode.IsOK) { return; } //Check children types if ((TigerType.AreCompatible(LeftOperandNode.TigerType, TigerType.Int) && TigerType.AreCompatible(RightOperandNode.TigerType, TigerType.Int)) || (TigerType.AreCompatible(LeftOperandNode.TigerType, TigerType.String) && TigerType.AreCompatible(RightOperandNode.TigerType, TigerType.String))) { TigerType = TigerType.Int; } else { report.AddError(SemanticErrors.InvalidOrderComparison(this, LeftOperandNode.TigerType, RightOperandNode.TigerType)); } }