Exemple #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(); }));
 }
Exemple #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);
            }
Exemple #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());
            }
Exemple #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);
            }
Exemple #6
0
 public string Visit(NegationExpr expr, Scope scope)
 {
     return("-" + expr.Right.Accept(this, scope));
 }
            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());
            }