Ejemplo n.º 1
0
        /// <summary>
        /// Changes the state.
        /// </summary>
        /// <param name="tokenizer">The tokenizer.</param>
        private void ChangeState(ITokenizer tokenizer)
        {
            //if (new StackTrace().FrameCount > 1700)
            //    throw new Exception("sdfgdfgdgdfgdfgdfgdfg");
            StreamReader streamReader = tokenizer.StrmReader;

            IState nextState = null;

            while (!streamReader.EndOfStream)
            {
                char peekedChar = (char)streamReader.Peek();

                //  the order of these ifs matters -
                //  IsIntegerConstant must be checked before Identifier.
                if (this.IsPossibleKeyword(peekedChar))
                {
                    nextState = Keyword.Instance();
                }
                else if (this.IsWhiteSpace(peekedChar))
                {
                    tokenizer.StrmReader.Read();
                    nextState = NewToken.Instance();
                }
                else if (this.IsSymbol(peekedChar))
                {
                    nextState = Symbol.Instance();
                }
                else if (this.IsIntegerConstant(peekedChar))
                {
                    nextState = IntegerConstant.Instance();
                }
                else if (this.IsPossibleIdentifierCharacter(peekedChar))
                {
                    nextState = Identifier.Instance();
                }

                // nasty hack to get over stackoverflow - don't call recusive on each new token
                if (nextState != null && nextState.GetType() != typeof(NewToken))
                {
                    nextState.Read(tokenizer);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the state.
        /// </summary>
        /// <param name="tokenizer">The tokenizer.</param>
        private void ChangeState(ITokenizer tokenizer)
        {
            StreamReader streamReader = tokenizer.StrmReader;

            IState nextState = null;

            if (!streamReader.EndOfStream)
            {
                char peekedChar = (char)streamReader.Peek();

                //  the order of these ifs matters -
                //  IsIntegerConstant must be checked before Identifier.
                if (this.IsPossibleKeyword(peekedChar))
                {
                    nextState = Keyword.Instance();
                }
                else if (this.IsWhiteSpace(peekedChar))
                {
                    tokenizer.StrmReader.Read();
                    nextState = NewToken.Instance();
                }
                else if (this.IsSymbol(peekedChar))
                {
                    nextState = Symbol.Instance();
                }
                else if (this.IsIntegerConstant(peekedChar))
                {
                    nextState = IntegerConstant.Instance();
                }
                else if (this.IsPossibleIdentifierCharacter(peekedChar))
                {
                    nextState = Identifier.Instance();
                }

                if (nextState != null)
                {
                    nextState.Read(tokenizer);
                }
            }
        }