/// <summary> /// Perform semantic transform of the introduced expression. Check if the expression is valid and build BinaryTree needed for polish postfix expression. /// </summary> /// <exception cref="MathParserException">MathParserException</exception> protected virtual void SemanticTransform() { _continueParsing = true; _binaryTree = new MathParserBinaryTree(new MathParserTreeNode(Nonterminal.End)); this._sizeOfPolishPostfixExpression = 0; //initializing _indexOfChar = 0; if (_listOfDoubleInputs.Count != 0) { _listOfDoubleInputs.Clear(); } if (_listOfVariableInputs.Count != 0) { _listOfVariableInputs.Clear(); } //this._mathInput = this._mathInput.Trim() + "$"; //appeding the end-character this._binaryTree.Root.AddLeftChild(new MathParserTreeNode(Nonterminal.Expression)); //Expression$ Stack <MathParserTreeNode> stack = new Stack <MathParserTreeNode>(); stack.Push(this._binaryTree.Root); //$ _traverseNode = this._binaryTree.Root.Left; stack.Push(_traverseNode); //starting from Nonterminal.Expression while (_continueParsing) //main cycle of parsing { _traverseNode = stack.Pop(); switch (_traverseNode.Name) { case Nonterminal.Expression: this.ExpressionToTermW(stack); break; case Nonterminal.W: this.WtoXWorEps(stack); break; case Nonterminal.X: this.XtoMinusTermOrXtoPlusTerm(stack); break; case Nonterminal.Term: this.TermToPowerK(stack); break; case Nonterminal.K: this.KtoYKorKtoEps(stack); break; case Nonterminal.Y: this.YtoMultiplyPowerOrYtoDividePower(stack); break; case Nonterminal.Power: this.PowerToFactoV(stack); break; case Nonterminal.V: this.VtoZVorVtoEps(stack); break; case Nonterminal.Z: this.ZtoPowerFactor(stack); break; case Nonterminal.Factor: this.Factor(stack); break; case Nonterminal.ParenthesisClose: this.ParanthesisClose(stack); break; case Nonterminal.End: this.End(stack); break; case Nonterminal.AnyValue: break; } } }
/// <summary> /// Perform semantic transform of the introduced expression. Check if the expression is valid and build BinaryTree needed for polish postfix expression. /// </summary> /// <exception cref="MathParserException">MathParserException</exception> protected virtual void SemanticTransform() { _continueParsing = true; _binaryTree = new MathParserBinaryTree(new MathParserTreeNode(Nonterminal.End)); this._sizeOfPolishPostfixExpression = 0; //initializing _indexOfChar = 0; if (_listOfDoubleInputs.Count != 0) _listOfDoubleInputs.Clear(); if (_listOfVariableInputs.Count != 0) _listOfVariableInputs.Clear(); //this._mathInput = this._mathInput.Trim() + "$"; //appeding the end-character this._binaryTree.Root.AddLeftChild(new MathParserTreeNode(Nonterminal.Expression)); //Expression$ Stack<MathParserTreeNode> stack = new Stack<MathParserTreeNode>(); stack.Push(this._binaryTree.Root); //$ _traverseNode = this._binaryTree.Root.Left; stack.Push(_traverseNode); //starting from Nonterminal.Expression while (_continueParsing) //main cycle of parsing { _traverseNode = stack.Pop(); switch (_traverseNode.Name) { case Nonterminal.Expression: this.ExpressionToTermW(stack); break; case Nonterminal.W: this.WtoXWorEps(stack); break; case Nonterminal.X: this.XtoMinusTermOrXtoPlusTerm(stack); break; case Nonterminal.Term: this.TermToPowerK(stack); break; case Nonterminal.K: this.KtoYKorKtoEps(stack); break; case Nonterminal.Y: this.YtoMultiplyPowerOrYtoDividePower(stack); break; case Nonterminal.Power: this.PowerToFactoV(stack); break; case Nonterminal.V: this.VtoZVorVtoEps(stack); break; case Nonterminal.Z: this.ZtoPowerFactor(stack); break; case Nonterminal.Factor: this.Factor(stack); break; case Nonterminal.ParenthesisClose: this.ParanthesisClose(stack); break; case Nonterminal.End: this.End(stack); break; case Nonterminal.AnyValue: break; } } }