コード例 #1
0
        /// <summary>
        /// Gets the next token while within a variable token parse state.
        /// </summary>
        /// <param name="internalLine"></param>
        /// <param name="token"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public override bool GetNextToken(string internalLine, out Token token, out TokenParseState state)
        {
            bool result = false;

            if ((result = PerenthesisToken.TryParse(internalLine, out token) && ((PerenthesisToken)token).PerenthesisType == PerenthesisTokenType.Closed))
            {
                state = new PerenthesisTokenParseState();
            }
            else if ((result = InfixFunctionToken.TryParse(internalLine, out token) || ArithmeticOperatorToken.TryParse(internalLine, out token) || BinaryOperatorToken.TryParse(internalLine, out token) || BooleanOperatorToken.TryParse(internalLine, out token) || AssignmentOperatorToken.TryParse(internalLine, out token)))
            {
                state = new InfixOperationParseState();
            }
            else if ((result = PostfixFunctionToken.TryParse(internalLine, out token)))
            {
                state = new PostfixFunctionParseState();
            }
            else if ((result = CommentToken.TryParse(internalLine, out token)))
            {
                state = new NullTokenParseState();
            }
            else
            {
                state = new InvalidTokenParseState();
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Gets the next token while in the set container token parse state.
        /// </summary>
        /// <param name="internalLine"></param>
        /// <param name="token"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public override bool GetNextToken(string internalLine, out Token token, out TokenParseState state)
        {
            bool  result    = false;
            Token lastToken = CalculatorContext.GetInstance()[CalculatorContext.LastToken];

            if ((result = SetContainerToken.TryParse(internalLine, out token) && ((SetContainerToken)token).SetContainerType == ((SetContainerToken)lastToken).SetContainerType))
            {
                state = new SetContainerTokenParseState();
            }
            else if ((result = CommentToken.TryParse(internalLine, out token)))
            {
                state = new NullTokenParseState();
            }
            else if (((SetContainerToken)lastToken).SetContainerType == SetContainerTokenType.Open)
            {
                if ((result = PrefixFunctionToken.TryParse(internalLine, out token)))
                {
                    state = new PrefixFunctionTokenParseState();
                }
                else if ((result = BooleanToken.TryParse(internalLine, out token) || ConstantToken.TryParse(internalLine, out token) || NumberToken.TryParse(internalLine, out token) || LastResultToken.TryParse(internalLine, out token)))
                {
                    state = new ValueTokenParseState();
                }
                else if ((result = VariableToken.TryParse(internalLine, out token)))
                {
                    state = new VariableTokenParseState();
                }
                else
                {
                    state = new InvalidTokenParseState();
                }
            }
            else if ((result = InfixFunctionToken.TryParse(internalLine, out token) || ArithmeticOperatorToken.TryParse(internalLine, out token) || BinaryOperatorToken.TryParse(internalLine, out token) || BooleanOperatorToken.TryParse(internalLine, out token)))
            {
                state = new InfixOperationParseState();
            }
            else if ((result = PostfixFunctionToken.TryParse(internalLine, out token)))
            {
                state = new PostfixFunctionParseState();
            }
            else
            {
                state = new InvalidTokenParseState();
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Gets the next Token if the last token was a NullToken. It first tries to get a normal,
        /// valid first token. If that fails, then it checks for a normal secondary token, and if
        /// that passes then the context LastResultIsImplied is set to true.
        /// </summary>
        /// <param name="internalLine"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public override bool GetNextToken(string internalLine, out Token token, out TokenParseState state)
        {
            bool result = false;

            if ((result = PerenthesisToken.TryParse(internalLine, out token)))
            {
                state = new PerenthesisTokenParseState();
            }
            else if ((result = PrefixFunctionToken.TryParse(internalLine, out token)))
            {
                state = new PrefixFunctionTokenParseState();
            }
            else if ((result = BooleanToken.TryParse(internalLine, out token) || ConstantToken.TryParse(internalLine, out token) || NumberToken.TryParse(internalLine, out token) || LastResultToken.TryParse(internalLine, out token)))
            {
                state = new ValueTokenParseState();
            }
            else if ((result = VariableToken.TryParse(internalLine, out token)))
            {
                state = new VariableTokenParseState();
            }
            else if ((result = InfixFunctionToken.TryParse(internalLine, out token) || ArithmeticOperatorToken.TryParse(internalLine, out token) || BinaryOperatorToken.TryParse(internalLine, out token) || BooleanOperatorToken.TryParse(internalLine, out token)))
            {
                state = new InfixOperationParseState();
                CalculatorContext.GetInstance().LastResultIsImplied = true;
            }
            else if ((result = PostfixFunctionToken.TryParse(internalLine, out token)))
            {
                state = new PostfixFunctionParseState();
                CalculatorContext.GetInstance().LastResultIsImplied = true;
            }
            else
            {
                state = new InvalidTokenParseState();
            }

            return(result);
        }