Пример #1
0
 public Value Visit(NegationExpr expr, Scope scope)
 {
     return(PerformOperation(new Value(0),
                             expr.Right.Accept(this, scope),
                             (a, b) => - b,
                             (a, b) => - b,
                             (a, b) => { throw new InvalidOperationException(); },
                             (a, b) => { throw new InvalidOperationException(); }));
 }
Пример #2
0
            public void NegationExpressionTest(object value, object expected)
            {
                var target = new TypeCheckingVisitor();

                var expr = new NegationExpr(new ConstantExpr(value));

                var actual = target.Visit(expr, scope);

                Assert.AreEqual(expected, actual);
            }
Пример #3
0
            public void NegationExpressionTest(object value, object expected)
            {
                var target = new EvaluateVisitor();

                var expr = new NegationExpr(new ConstantExpr(value));

                var actual = target.Visit(expr, _scope);

                Assert.AreEqual(expected, actual.ToObject());
            }
Пример #4
0
        public ValueType Visit(NegationExpr expr, Scope scope)
        {
            var type = expr.Right.Accept(this, scope);

            if (!type.IsNumericType())
            {
                throw new TypeCheckException("Negation only defined for numeric types.");
            }

            return(type);
        }
            public void NegationExpressionTest(object value, object expected)
            {
                var target = new TypeCheckingVisitor();

                var expr = new NegationExpr(new ConstantExpr(value));

                var actual = target.Visit(expr, scope);

                Assert.AreEqual(expected, actual);
            }
Пример #6
0
 public string Visit(NegationExpr expr, Scope scope)
 {
     return("-" + expr.Right.Accept(this, scope));
 }
Пример #7
0
            public void NegationExpressionTest(object value, object expected)
            {
                var target = new EvaluateVisitor();

                var expr = new NegationExpr(new ConstantExpr(value));

                var actual = target.Visit(expr, _scope);

                Assert.AreEqual(expected, actual.ToObject());
            }