Exemple #1
0
        public static Token ParsingUsingIterator(PeekableEnumerableAdapter <char> iterator)
        {
            string s = "";

            while (iterator.HasNext)
            {
                char lookahead = iterator.Peek();
                if (AlphabetHelper.IsLetter(lookahead))
                {
                    s += lookahead;
                }
                else
                {
                    break;
                }
                iterator.Next();
            }
            if (KeyWords.IsKeyword(s))
            {
                return(new Token(TokenType.KEYWORD, s));
            }
            if (s.Equals("true") || s.Equals("false"))
            {
                return(new Token(TokenType.BOOLEAN, s));
            }
            return(new Token(TokenType.VARIABLE, s));
        }
Exemple #2
0
        public static Token MakeString(PeekableEnumerableAdapter <char> iterator)
        {
            string            s          = "";
            IMakeStringState  startState = new StartMakeStringState();
            MakeStringContent content    = new MakeStringContent(startState);

            while (iterator.HasNext)
            {
                char c = iterator.Next();
                content.C = c;
                Token token = content.State.DoAction(content, s + c);
                if (token != null)
                {
                    return(token);
                }
                else
                {
                    s = content.Concat(s);
                }
            }
            throw new LexicalException("Unexpected error");
        }