private TreeNode GetMultiplyDevideNode(IList <Symbol> symbols, int index, out int currentIndex) { var leftSideNode = GetUnaryNode(symbols, index, out index); while (index < symbols.Count) { if (!(symbols[index] is OperationSymbol currentSymbol) || currentSymbol.OperationType == OperationTypes.Add || currentSymbol.OperationType == OperationTypes.Subtract) { currentIndex = index; return(leftSideNode); } index += 1; var rightSideNode = GetUnaryNode(symbols, index, out index); switch (currentSymbol.OperationType) { case OperationTypes.Multiply: leftSideNode = new MultiplyBinaryNode(leftSideNode, rightSideNode); break; case OperationTypes.Divide: leftSideNode = new DivideBinaryNode(leftSideNode, rightSideNode); break; } } currentIndex = index; return(leftSideNode); }
public void SyntaxTokenParser_ShouldParse_UnaryOperators_AccordingToPrecedence2() { var res = Parse("2*3++4"); res.IsSuccessful.Should().BeTrue(); var plusBinaryNode = new MultiplyBinaryNode(new MultiplyBinaryNode(new NumberNode(2), new NumberNode(3)), new PlusUnaryNode(new NumberNode(4))); res.Root.ShouldDeepEqual(plusBinaryNode); }
public double Visit(MultiplyBinaryNode node) { return(node.Left.Accept(this) * node.Right.Accept(this)); }