public void CompareExp(CompareExp e) { Label TrueLabel = il.DefineLabel(); Label EndLabel = il.DefineLabel(); e.Left.Visit(this); e.Right.Visit(this); switch(e.Oper){ case Operator.LT: il.Emit(OpCodes.Blt, TrueLabel); break; case Operator.GT: il.Emit(OpCodes.Bgt, TrueLabel); break; case Operator.EQ: il.Emit(OpCodes.Beq, TrueLabel); break; case Operator.LE: il.Emit(OpCodes.Ble, TrueLabel); break; case Operator.GE: il.Emit(OpCodes.Bge, TrueLabel); break; } il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Br, EndLabel); il.MarkLabel(TrueLabel); il.Emit(OpCodes.Ldc_I4_1); il.MarkLabel(EndLabel); }
public void CompareExp(CompareExp e) { e.Left.Visit(this); CheckInt(e.Left); e.Right.Visit(this); CheckInt(e.Right); if (e.Left.ExpType != typeof(int)){ if (e.Left is CarExp){ e.Left = new ToIntExp(e.Left); } else{ Console.WriteLine("Error 101: Cannot Convert expression to Int"); success = false; } } if (e.Right.ExpType != typeof(int)){ if (e.Right is CarExp){ e.Right = new ToIntExp(e.Right); } else{ Console.WriteLine("Error 102: Connot Convert expression to Int"); success = false; } } e.ExpType = typeof(bool); }