Esempio n. 1
0
 public IConvertable ForEquationItems(EquationItem[] equationItems)
 {
     _equationItems     = equationItems;
     _convertedEquation = new Stack <IReverseNotationItem>();
     _operationsStack   = new Stack <IOperation>();
     return(this);
 }
Esempio n. 2
0
        public EquationItem[] ParseEquationItems(string equation)
        {
            if (string.IsNullOrWhiteSpace(equation))
            {
                throw new ArgumentNullException(nameof(equation), "Equation not provided");
            }

            _equationItemsStack = new Stack <EquationItem>();
            _operandBuilder.Clear();

            foreach (var sign in equation)
            {
                var bracket   = _bracketsFactory.InitializeFromSign(sign);
                var operation = _operationFactory.InitializeFromSign(sign);
                if (bracket != null || operation != null)
                {
                    var equationItem = bracket ?? (EquationItem)operation;
                    AppendOperand();
                    _equationItemsStack.Push(equationItem);
                }
                else
                {
                    _operandBuilder.Append(sign);
                }
            }

            AppendOperand();

            return(_equationItemsStack.Items);
        }