public Value Visit(LessThanOrEqual node) { Value left = node.Left().Accept(this); Value right = node.Right().Accept(this); return(left.LessEqual(right)); }
static void Main(string[] args) { //var a = new Random().Next(0, 7); //var b = new Random().Next(0, 7); for (int a = 0; a < 8; a++) { for (int b = 0; b < 8; b++) { var results = new Results(); var binaryA = new QArray <long>(Binary.ToBase2(a, NumberOfBits).Select(n => (long)n)); var binaryB = new QArray <long>(Binary.ToBase2(b, NumberOfBits).Select(n => (long)n)); Console.WriteLine($"a={a} b={b}"); Console.WriteLine($"binaryA={binaryA} binaryB={binaryB}"); for (int i = 0; i < TestCount; i++) { using (var qsim = new QuantumSimulator()) { var result = (int)LessThanOrEqual.Run(qsim, binaryA, binaryB).Result; results.Add(result.ToString()); } } Console.WriteLine(results); } } Console.WriteLine("Finished."); Console.ReadLine(); }
public override Value Visit(LessThanOrEqual node) { Value left = node.Left().Accept(this); Value right = node.Right().Accept(this); return(left.LessEqual((dynamic)right)); }
private static IExpression InvertBinaryOperation(IBinaryOperation binOp) { Contract.Requires(binOp != null); Contract.Ensures(Contract.Result<IExpression>() != null); BinaryOperation/*?*/ result = null; if (binOp is IEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) result = new NotEquality(); else if (binOp is INotEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) result = new Equality(); else if (binOp is ILessThan) result = new GreaterThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThan)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is ILessThanOrEqual) result = new GreaterThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is IGreaterThan) result = new LessThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThan)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is IGreaterThanOrEqual) result = new LessThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) }; if (result != null) { result.LeftOperand = binOp.LeftOperand; result.RightOperand = binOp.RightOperand; result.Type = binOp.Type; result.Locations.AddRange(binOp.Locations); return result; } LogicalNot logicalNot = new LogicalNot(); logicalNot.Operand = binOp; logicalNot.Type = binOp.Type; logicalNot.Locations.AddRange(binOp.Locations); return logicalNot; }
public IType Visit(LessThanOrEqual node) { var leftHandSideValue = Visit((dynamic)node.Lhs); var rightHandSideValue = Visit((dynamic)node.Rhs); return(leftHandSideValue.LessThanOrEqual(rightHandSideValue)); }
private ComparisonOperator ComparisonOperator() { if (this.lexer.Token == null || !this.lexer.Token.Is(TokenType.Name)) { this.SyntaxError("comparision operator"); } ComparisonOperator comparisonOperator = null; switch (this.lexer.Token.Value) { case "pr": comparisonOperator = new Present(); break; case "eq": comparisonOperator = new Equal(); break; case "ne": comparisonOperator = new NotEqual(); break; case "co": comparisonOperator = new Contains(); break; case "sw": comparisonOperator = new StartsWith(); break; case "ew": comparisonOperator = new EndsWith(); break; case "gt": comparisonOperator = new GreaterThan(); break; case "lt": comparisonOperator = new LessThan(); break; case "ge": comparisonOperator = new GreaterThanOrEqual(); break; case "le": comparisonOperator = new LessThanOrEqual(); break; default: this.SyntaxError("comparision operator"); break; } this.Match(this.lexer.Token.Name); return(comparisonOperator); }
public void TestLessThanOrEqual() { var lt = new LessThanOrEqual(new Constant("23"), new Constant("12")); Assert.IsFalse((bool) lt.Evaluate(new Reflection(this))); lt = new LessThanOrEqual(new Constant("12"), new Constant("23")); Assert.IsTrue((bool) lt.Evaluate(new Reflection(this))); lt = new LessThanOrEqual(new Constant("12"), new Constant("12")); Assert.IsTrue((bool) lt.Evaluate(new Reflection(this))); }
/// <summary> /// Initializes the <see cref="Ops" /> class. /// </summary> static Ops() { Equal = new Equal(); GreaterThan = new GreaterThan(); GreaterThanOrEqual = new GreaterThanOrEqual(); LessThan = new LessThan(); LessThanOrEqual = new LessThanOrEqual(); NotEqual = new NotEqual(); }
public void LessThanOrEqual_WithDouble2Integer3_ReturnTrue() { var left = new Constant(2.0); var right = new Constant(3); var operation = new LessThanOrEqual(left, right); var actual = (bool)operation.GetExpression(null).Calculate(); Assert.AreEqual(true, actual); }
public void TestLessThanOrEqual() { var lt = new LessThanOrEqual(new Constant("23"), new Constant("12")); Assert.IsFalse((bool)lt.Evaluate(new Reflection(this))); lt = new LessThanOrEqual(new Constant("12"), new Constant("23")); Assert.IsTrue((bool)lt.Evaluate(new Reflection(this))); lt = new LessThanOrEqual(new Constant("12"), new Constant("12")); Assert.IsTrue((bool)lt.Evaluate(new Reflection(this))); }
public void Evaluate_LessOrEqual_Int_False_Test() { Expression left = CreateIntLiteral(2); Expression right = CreateIntLiteral(1); Expression lessOrEqual = new LessThanOrEqual(left, right, pos); Values.Bool value = ((Values.Bool)lessOrEqual.Accept(evaluator)); Assert.IsFalse(value.GetValue()); }
//<expr-rel><--<LessThanorequal>// public string Visit(LessThanOrEqual node) { var sb = new StringBuilder(); var myLabel = GenerateLabel(); sb.Append("\t\tldc.i4 42\n"); sb.Append(Visit((dynamic)node[0]) + "\n"); sb.Append(Visit((dynamic)node[1]) + "\n"); sb.Append("\t\tble '" + myLabel + "'\n"); sb.Append("\t\tpop\n"); sb.Append("\t\tldc.i4.0\n"); sb.Append("\t\t'" + myLabel + "':\n"); return(sb.ToString()); }
//<expr-rel>// public Node ExprRel() { var addOne = ExprAdd(); var xprRel = addOne; while (firstOfExprRel.Contains(CurrentToken)) { switch (CurrentToken) { case TokenCategory.LESS_THAN: xprRel = new LessThan() { AnchorToken = Expect(TokenCategory.LESS_THAN) }; break; case TokenCategory.LESS_THAN_OR_EQUAL_TO: xprRel = new LessThanOrEqual() { AnchorToken = Expect(TokenCategory.LESS_THAN_OR_EQUAL_TO) }; break; case TokenCategory.GREATER_THAN: xprRel = new GreaterThan() { AnchorToken = Expect(TokenCategory.GREATER_THAN) }; break; case TokenCategory.GREATER_THAN_OR_EQUAL_TO: xprRel = new GreaterThanOrEqual() { AnchorToken = Expect(TokenCategory.GREATER_THAN_OR_EQUAL_TO) }; break; default: throw new SyntaxError(firstOfExprRel, tokenStream.Current); } xprRel.Add(addOne); xprRel.Add(ExprAdd()); addOne = xprRel; } return(xprRel); }
protected Equation TranslateStringToEquation(string pattern, int desiredID) { Data.Sign sign = null; double rightPart; string[] arr = pattern.Split(new string[] { "<=", ">=", "=" }, StringSplitOptions.RemoveEmptyEntries); double.TryParse(arr[1], out rightPart); string[] instances = pattern.Split(" ", StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < instances.Length; i++) { if (instances[i] == "<=") { sign = new LessThanOrEqual(); break; } else if (instances[i] == ">=") { sign = new MoreThanOrEqual(); break; } else if (instances[i] == "=") { sign = new EqualSign(); break; } } if (sign == null) { throw new Exception("Знак неравенства не был найден"); } return(new Equation(desiredID) { Coefficients = arr[0].Trim(), SelectedSign = sign, RightPart = rightPart }); }
public virtual void Visit(LessThanOrEqual expression) { VisitBinaryChildren(expression); }
private static Activity HandleBinaryExpression <TLeft, TRight, TResult>(BinaryOperator op, TestExpression left, TestExpression right) { Activity we = null; InArgument <TLeft> leftArgument = (InArgument <TLeft>)TestExpression.GetInArgumentFromExpectedNode <TLeft>(left); leftArgument.EvaluationOrder = 0; InArgument <TRight> rightArgument = (InArgument <TRight>)TestExpression.GetInArgumentFromExpectedNode <TRight>(right); rightArgument.EvaluationOrder = 1; switch (op) { case BinaryOperator.Add: we = new Add <TLeft, TRight, TResult>() { Checked = false, Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.And: we = new And <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.AndAlso: we = new AndAlso() { Left = TestExpression.GetWorkflowElementFromExpectedNode <bool>(left), Right = TestExpression.GetWorkflowElementFromExpectedNode <bool>(right) }; break; case BinaryOperator.CheckedAdd: we = new Add <TLeft, TRight, TResult>() { Checked = true, Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.CheckedMultiply: we = new Multiply <TLeft, TRight, TResult>() { Checked = true, Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.CheckedSubtract: we = new Subtract <TLeft, TRight, TResult>() { Checked = true, Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.Divide: we = new Divide <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.Equal: we = new Equal <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.GreaterThan: we = new GreaterThan <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.GreaterThanOrEqual: we = new GreaterThanOrEqual <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.LessThan: we = new LessThan <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.LessThanOrEqual: we = new LessThanOrEqual <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.Or: we = new Or <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.Multiply: we = new Multiply <TLeft, TRight, TResult>() { Checked = false, Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.NotEqual: we = new NotEqual <TLeft, TRight, TResult>() { Left = leftArgument, Right = rightArgument }; break; case BinaryOperator.OrElse: we = new OrElse() { Left = TestExpression.GetWorkflowElementFromExpectedNode <bool>(left), Right = TestExpression.GetWorkflowElementFromExpectedNode <bool>(right) }; break; case BinaryOperator.Subtract: we = new Subtract <TLeft, TRight, TResult>() { Checked = false, Left = leftArgument, Right = rightArgument }; break; default: throw new NotSupportedException(string.Format("Operator: {0} is unsupported", op.ToString())); } return(we); }
void Comparison(out Expression exp) { Expression second; BitOr(out exp); if (StartOf(3)) { switch (la.kind) { case 29: { Get(); break; } case 30: { Get(); break; } case 31: { Get(); break; } case 32: { Get(); break; } case 33: { Get(); break; } case 34: { Get(); break; } } Token tok = t; Comparison(out second); if (!ExpectInt(exp, tok, false)) { return; } ; if (!ExpectInt(second, tok, true)) { return; } ; if (tok.val == "<") { exp = new LessThan((TypedExpression <int>)exp, (TypedExpression <int>)second); } else if (tok.val == ">") { exp = new GreaterThan((TypedExpression <int>)exp, (TypedExpression <int>)second); } else if (tok.val == "<=") { exp = new LessThanOrEqual((TypedExpression <int>)exp, (TypedExpression <int>)second); } else if (tok.val == ">=") { exp = new GreaterThanOrEqual((TypedExpression <int>)exp, (TypedExpression <int>)second); } else if (tok.val == "==") { exp = new Equal((TypedExpression <int>)exp, (TypedExpression <int>)second); } else if (tok.val == "!=") { exp = new NotEqual((TypedExpression <int>)exp, (TypedExpression <int>)second); } } }
public override BaseType Visit(LessThanOrEqual node) { StoreExpr(node); EnsureOfType <NumType>(node.Left.Accept(this), node.Right.Accept(this)); return(new BoolType()); }
public void Visit(LessThanOrEqual expression) { _result = VisitConditional(expression, (a, b) => LessThanOrEqual(a, b)); }
void Comparison(out Expression exp) { Expression second; BitOr(out exp); if (StartOf(3)) { switch (la.kind) { case 29: { Get(); break; } case 30: { Get(); break; } case 31: { Get(); break; } case 32: { Get(); break; } case 33: { Get(); break; } case 34: { Get(); break; } } Token tok = t; Comparison(out second); if (!ExpectInt(exp, tok, false)) { return; }; if (!ExpectInt(second, tok, true)) { return; }; if (tok.val == "<") { exp = new LessThan((TypedExpression<int>)exp, (TypedExpression<int>)second); } else if (tok.val == ">") { exp = new GreaterThan((TypedExpression<int>)exp, (TypedExpression<int>)second); } else if (tok.val == "<=") { exp = new LessThanOrEqual((TypedExpression<int>)exp, (TypedExpression<int>)second); } else if (tok.val == ">=") { exp = new GreaterThanOrEqual((TypedExpression<int>)exp, (TypedExpression<int>)second); } else if (tok.val == "==") { exp = new Equal((TypedExpression<int>)exp, (TypedExpression<int>)second); } else if (tok.val == "!=") { exp = new NotEqual((TypedExpression<int>)exp, (TypedExpression<int>)second); } } }
public virtual T Visit(LessThanOrEqual node) { return(VisitBinary(node)); }
public override string Visit(LessThanOrEqual node) { return(VisitBinary("<=", node)); }
public virtual void Visit(LessThanOrEqual node) { }
public IEnumerable <Id> Visit(LessThanOrEqual node) { return(VisitBinary(node)); }
public void Evaluate_LessOrEqual_Int_True_Test() { Expression left = CreateIntLiteral(1); Expression right = CreateIntLiteral(2); Expression lessOrEqual = new LessThanOrEqual(left, right, pos); Values.Bool value = ((Values.Bool)lessOrEqual.Accept(evaluator)); Assert.IsTrue(value.GetValue()); }
public override IExpression VisitBinaryExpression(BinaryExpressionSyntax node) { var o = this.semanticModel.GetTypeInfo(node); var t = this.mapper.Map(o.Type); if (node.Kind == SyntaxKind.AssignExpression) { this.lhs = true; } var left = this.Visit(node.Left); this.lhs = false; var right = this.Visit(node.Right); BinaryOperation op = null; var locs = Helper.SourceLocation(this.tree, node); switch (node.Kind) { case SyntaxKind.AddAssignExpression: { var a = new Assignment() { Locations = locs, Source = new Addition() { LeftOperand = left, RightOperand = right, }, Target = Helper.MakeTargetExpression(left), Type = t, }; return(a); } case SyntaxKind.AddExpression: op = new Addition(); break; case SyntaxKind.AssignExpression: { var mc = left as MethodCall; if (mc != null) { // then this is really o.P = e for some property P // and the property access has been translated into a call // to set_P. mc.Arguments = new List <IExpression> { right, }; return(mc); } var be = left as BoundExpression; if (be != null) { var a = new Assignment() { Locations = locs, Source = right, Target = new TargetExpression() { Definition = be.Definition, Instance = be.Instance, Type = be.Type, }, Type = t, }; return(a); } var arrayIndexer = left as ArrayIndexer; if (arrayIndexer != null) { var a = new Assignment() { Locations = locs, Source = right, Target = new TargetExpression() { Definition = arrayIndexer, Instance = arrayIndexer.IndexedObject, Type = right.Type, }, Type = t, }; return(a); } var addressDereference = left as AddressDereference; if (addressDereference != null) { var a = new Assignment() { Locations = locs, Source = right, Target = new TargetExpression() { Definition = addressDereference, Instance = null, Type = t, }, Type = t, }; return(a); } throw new InvalidDataException("VisitBinaryExpression: Can't figure out lhs in assignment" + left.Type.ToString()); } case SyntaxKind.BitwiseAndExpression: op = new BitwiseAnd(); break; case SyntaxKind.BitwiseOrExpression: op = new BitwiseOr(); break; case SyntaxKind.DivideExpression: op = new Division(); break; case SyntaxKind.EqualsExpression: op = new Equality(); break; case SyntaxKind.ExclusiveOrExpression: op = new ExclusiveOr(); break; case SyntaxKind.GreaterThanExpression: op = new GreaterThan(); break; case SyntaxKind.GreaterThanOrEqualExpression: op = new GreaterThanOrEqual(); break; case SyntaxKind.LeftShiftExpression: op = new LeftShift(); break; case SyntaxKind.LessThanExpression: op = new LessThan(); break; case SyntaxKind.LessThanOrEqualExpression: op = new LessThanOrEqual(); break; case SyntaxKind.LogicalAndExpression: return(new Conditional() { Condition = left, Locations = locs, ResultIfTrue = right, ResultIfFalse = new CompileTimeConstant() { Type = t, Value = false }, Type = t, }); case SyntaxKind.LogicalOrExpression: return(new Conditional() { Condition = left, Locations = Helper.SourceLocation(this.tree, node), ResultIfTrue = new CompileTimeConstant() { Type = t, Value = true }, ResultIfFalse = right, Type = t, }); case SyntaxKind.ModuloExpression: op = new Modulus(); break; case SyntaxKind.MultiplyExpression: op = new Multiplication(); break; case SyntaxKind.NotEqualsExpression: op = new NotEquality(); break; case SyntaxKind.RightShiftExpression: op = new RightShift(); break; case SyntaxKind.SubtractAssignExpression: { var a = new Assignment() { Locations = locs, Source = new Subtraction() { LeftOperand = left, RightOperand = right, }, Target = Helper.MakeTargetExpression(left), Type = t, }; return(a); } case SyntaxKind.MultiplyAssignExpression: { var a = new Assignment() { Locations = locs, Source = new Multiplication() { LeftOperand = left, RightOperand = right, }, Target = Helper.MakeTargetExpression(left), Type = t, }; return(a); } case SyntaxKind.DivideAssignExpression: { var a = new Assignment() { Locations = locs, Source = new Division() { LeftOperand = left, RightOperand = right, }, Target = Helper.MakeTargetExpression(left), Type = t, }; return(a); } case SyntaxKind.ModuloAssignExpression: { var a = new Assignment() { Locations = locs, Source = new Modulus() { LeftOperand = left, RightOperand = right, }, Target = Helper.MakeTargetExpression(left), Type = t, }; return(a); } case SyntaxKind.SubtractExpression: op = new Subtraction(); break; default: throw new InvalidDataException("VisitBinaryExpression: unknown node = " + node.Kind); } op.Locations = locs; op.LeftOperand = left; op.RightOperand = right; op.Type = t; return(op); }
public Types.Type Visit(LessThanOrEqual node) { return(VisitBinaryExpectedType(node, new Types.IntType(), new Types.BoolType())); }
public void SetUp() { testee = new LessThanOrEqual <CustomEntity>("<="); }
private Expression ParseRelationalExpression(TokenSet followers) { TokenSet followerOrRelational = followers|Parser.RelationalOperators; Expression result = this.ParseAdditiveExpression(followerOrRelational); while (Parser.RelationalOperators[this.currentToken]) { SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation); Token operatorToken = this.currentToken; this.GetNextToken(); Expression operand2 = this.ParseAdditiveExpression(followerOrRelational); slb.UpdateToSpan(operand2.SourceLocation); switch (operatorToken){ case Token.Equals: result = new Equality(result, operand2, slb); break; case Token.GreaterThan: result = new GreaterThan(result, operand2, slb); break; case Token.GreaterThanEqualTo: result = new GreaterThanOrEqual(result, operand2, slb); break; case Token.LessThan: result = new LessThan(result, operand2, slb); break; case Token.LessThanEqualTo: result = new LessThanOrEqual(result, operand2, slb); break; case Token.NotEqualTo: result = new NotEquality(result, operand2, slb); break; } } //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; return result; }
public void SetUp() { testee = new LessThanOrEqual<CustomEntity>("<="); }
public INotificationManager Visit(LessThanOrEqual node) { return(VisitBinaryExpectedType(node, new Types.IntType())); }
public static IExpression Normalize(IExpression expression) { LogicalNot /*?*/ logicalNot = expression as LogicalNot; if (logicalNot != null) { IExpression operand = logicalNot.Operand; #region LogicalNot: ! LogicalNot /*?*/ operandAsLogicalNot = operand as LogicalNot; if (operandAsLogicalNot != null) { return(Normalize(operandAsLogicalNot.Operand)); } #endregion #region BinaryOperations: ==, !=, <, <=, >, >= BinaryOperation /*?*/ binOp = operand as BinaryOperation; if (binOp != null) { BinaryOperation /*?*/ result = null; if (binOp is IEquality) { result = new NotEquality(); } else if (binOp is INotEquality) { result = new Equality(); } else if (binOp is ILessThan) { result = new GreaterThanOrEqual(); } else if (binOp is ILessThanOrEqual) { result = new GreaterThan(); } else if (binOp is IGreaterThan) { result = new LessThanOrEqual(); } else if (binOp is IGreaterThanOrEqual) { result = new LessThan(); } if (result != null) { result.LeftOperand = Normalize(binOp.LeftOperand); result.RightOperand = Normalize(binOp.RightOperand); return(result); } } #endregion #region Conditionals: &&, || Conditional /*?*/ conditional = operand as Conditional; if (conditional != null) { if (ExpressionHelper.IsIntegralNonzero(conditional.ResultIfTrue) || ExpressionHelper.IsIntegralZero(conditional.ResultIfFalse)) { Conditional result = new Conditional(); LogicalNot not; //invert condition not = new LogicalNot(); not.Operand = conditional.Condition; result.Condition = Normalize(not); //invert false branch and switch with true branch not = new LogicalNot(); not.Operand = conditional.ResultIfFalse; result.ResultIfTrue = Normalize(not); //invert true branch and switch with false branch not = new LogicalNot(); not.Operand = conditional.ResultIfTrue; result.ResultIfFalse = Normalize(not); //return result.Type = conditional.Type; return(result); } } #endregion #region Constants: true, false CompileTimeConstant /*?*/ ctc = operand as CompileTimeConstant; if (ctc != null) { if (ExpressionHelper.IsIntegralNonzero(ctc)) //Is true { var val = SetBooleanFalse(ctc); if (val != null) { return(val); } else { return(expression); } } else if (ExpressionHelper.IsIntegralZero(ctc)) //Is false { var val = SetBooleanTrue(ctc); if (val != null) { return(val); } else { return(expression); } } } #endregion } return(expression); }
//----------------------------------------------------------- //<expr-rel><--<LessThanorequal>// public void Visit(LessThanOrEqual node, char i) { VisitChildren(node, i); }