Ejemplo n.º 1
0
        private bool TryOperator()
        {
            if (!OperatorExpression.IsSymbol(_currentChar))
            {
                return(false);
            }

            bool   repeat;
            string s = _currentChar.ToString();

            do
            {
                string p = _symbolStack.Count == 0 ? string.Empty : _symbolStack.Peek();
                repeat = false;
                if (_symbolStack.Count == 0)
                {
                    _symbolStack.Push(s);
                }
                else if (p == "(")
                {
                    _symbolStack.Push(s);
                }
                else if (Precedence(s) > Precedence(p))
                {
                    _symbolStack.Push(s);
                }
                else
                {
                    IExpression e = GetExpressionFromSymbol(_symbolStack.Pop());
                    _expressionQueue.Enqueue(e);
                    repeat = true;
                }
            } while (repeat);

            return(true);
        }