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 double Visit(DivideBinaryNode node) { var left = node.Left.Accept(this); var right = node.Right.Accept(this); return(left / right); }