Ejemplo n.º 1
0
        private bool ParseFunctions(Stack<Token> operands, List<Token> rpnOutput, Token token)
        {
            if (token?.action == null) //token == null || token.action == null
                return false;

            if (operands.Count == 0 || token.Precedence > operands.Peek().Precedence)
            {
                operands.Push(token);
            }else
            {
                Token e = operands.Pop();
                operands.Push(token);
                rpnOutput.Add(e);
            }

            return true;
        }
Ejemplo n.º 2
0
        private bool ParseParentheses(Stack<Token> operands, List<Token> rpnOutput, Token token)
        {
            if (token == null || token.action != null)
                return false;

            if (token.Symbol == "(")
            {
                operands.Push(token);
            }
            else
            {
                Token t = operands.Pop();
                while (t.Symbol != "(")
                {
                    rpnOutput.Add(t);
                    t = operands.Pop();
                }
            }
            return true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method adding tokens from outside - for example other class
        /// </summary>
        /// <param name="func">Token to add</param>
        /// <returns>Success</returns>
        public bool AddFunction(Token func)
        {
            if (tokens.Any(n => n.Symbol == func.Symbol))
                return false;

            tokens.Add(func);

            return true;
        }