public void TestGetBySymbol() { var o = BinaryOperator.BySymbol("+"); Assert.AreEqual("+", o.Symbol); Assert.AreEqual(2.0, o.Evaluate(1, 1)); }
public override Node Visit(BinaryOperatorNode node) { BinaryOperator newBinaryOperator = node.BinaryOperator; switch (node.BinaryOperator.Symbol) { case "+": newBinaryOperator = BinaryOperator.BySymbol("-"); break; case "-": newBinaryOperator = BinaryOperator.BySymbol("+"); break; } return(new BinaryOperatorNode(newBinaryOperator, node.LeftNode.Visit(this), node.RightNode.Visit(this))); }
public override Node VisitExpression([NotNull] FormulaGrammerParser.ExpressionContext context) { int idxMultiplyExpression = 0; int idxOp = 1; var multiplyExpression = context.multiplyingExpression(idxMultiplyExpression++); var node = this.VisitMultiplyingExpression(multiplyExpression); while ((multiplyExpression = context.multiplyingExpression(idxMultiplyExpression++)) != null) { var op = BinaryOperator.BySymbol(context.GetChild(idxOp).GetText()); var right = this.VisitMultiplyingExpression(multiplyExpression); node = new BinaryOperatorNode(op, node, right); idxOp += 2; } return(node); }
public void TestGetBySymbol_NotExisting() { var o = BinaryOperator.BySymbol("abv"); }