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