コード例 #1
0
        internal virtual Token next_Token()
        {
            Token   t      = new Token();
            Symbols symbol = new Symbols();

            t.token = -1;
            peek    = next_char();

            do
            {
                if (peek == ' ' || peek == '\t')
                {
                    continue;
                }
                else if (peek == '\n')
                {
                    line++;
                    char_pos = -1;
                }
                else
                {
                    break;
                }
            }while (peek == next_char());

            if (peek == '$')
            {
                string @var = "$";
                peek = next_char();
                while (isLetter(peek))
                {
                    @var += peek;
                    peek  = next_char();
                }
                input_pos--;
                t.token = Tokens.Covert("VAR");
                Token s = new Token();
                s.token = Tokens.Covert("VAR");
                s.value = 0;
                s.lexem = @var;
                t.value = symbol.add_symbol(s);
                return(t);
            }
            else if (isDigit(peek))
            {
                int x = 0;
                do
                {
                    x    = 10 * x + System.identityHashCode(peek);
                    peek = next_char();
                }while (isDigit(peek));
                input_pos--;
                t.token = Tokens.Covert("NUM");
                t.value = x;
                return(t);
            }
            else if (peek == 'p')
            {
                string print = "print";
                for (int i = 0; i < print.Length; i++)
                {
                    if (print[i] == peek)
                    {
                        peek = next_char();
                    }
                    else
                    {
                        t.token = Tokens.Covert("ERR");
                        return(t);
                    }
                }
                t.token = Tokens.Covert("PRINT");
                return(t);
            }
            else if (peek == ';')
            {
                t.token = Tokens.Covert("EOL");
                t.value = 0;
            }
            else if (peek == '+')
            {
                t.token = Tokens.Covert("PLUS");
                t.value = 0;
            }
            else if (peek == '=')
            {
                t.token = Tokens.Covert("EQUALS");
                t.value = 0;
            }
            return(t);
        }