示例#1
0
        public Token nextToken()
        {
            while (input[pos] == ' ')
                pos++;

            int startPos = pos;

            if (isAChar(input[pos]))
            {
                pos++;

                while (isAChar(input[pos]) || isANumber(input[pos]))
                    pos++;

                string tk = input.Substring(startPos, pos - startPos);

                WordToken w = (WordToken)words[tk];
                if (w != null)
                    return w;
                else
                {
                    WordToken t = new WordToken(TokenType.IDE, tk);
                    words.Add(tk, t);
                    return t;
                }

            }
            else switch (input[pos])
                {
                    case '(':
                        pos++;
                        return Token.openb;
                    case ')':
                        pos++;
                        return Token.closeb;
                    case ',':
                        pos++;
                        return Token.comma;
                    case '=':
                        pos++;
                        return Token.equals;
                    case '\0':
                        return Token.eof;
                    default:
                        Error("Parsing error: " + input[pos] + " is a invalid char");
                        return null;
                }
        }
示例#2
0
 void reserve(WordToken w)
 {
     words.Add(w.Lexeme, w);
 }