Exemple #1
0
        public override bool Get(TextBuffer text_buffer)
        {
            int start_index = text_buffer.CurrentIndex;
            int length      = 1;

            while (true)
            {
                char ch   = text_buffer.NextChar();
                char code = Tokenizer.GetCode(ch);
                if (code == Tokenizer.Letter || code == Tokenizer.Digit)
                {
                    ++length;
                }
                else
                {
                    break;
                }
            }
            string str = text_buffer.SubString(start_index, length);

            if (!ms_reserved_words.TryGetValue(str, out m_type))
            {
                m_type       = TokenType.IDENTIFIER;
                m_raw_string = str;
            }
            return(true);
        }
Exemple #2
0
        public override bool Get(TextBuffer text_buffer)
        {
            int start_index = text_buffer.CurrentIndex + 1;
            int length      = 0;

            while (true)
            {
                char ch = text_buffer.NextChar();
                if (text_buffer.Eof())
                {
                    break;
                }
                if (Tokenizer.GetCode(ch) == Tokenizer.Quote)
                {
                    break;
                }
                ++length;
            }
            m_raw_string = text_buffer.SubString(start_index, length);
            return(true);
        }
Exemple #3
0
        public override bool Get(TextBuffer text_buffer)
        {
            int start_index = text_buffer.CurrentIndex;
            int length      = 1;

            while (true)
            {
                char ch = text_buffer.NextChar();
                if (ch == '.' || Tokenizer.GetCode(ch) == Tokenizer.Digit)
                {
                    ++length;
                }
                else
                {
                    break;
                }
            }
            string str = text_buffer.SubString(start_index, length);

            m_value = FixPoint.Parse(str);
            return(true);
        }
Exemple #4
0
        char SkipWhiteSpace()
        {
            while (!m_text_buffer.Eof())
            {
                char code = Tokenizer.GetCode(m_text_buffer.Char());
                switch (code)
                {
                case WhiteSpace:
                    break;

                case Error:
                    m_error = true;
                    LogWrapper.LogError("Expression: Tokenizer.SkipWhiteSpace(), illegal character in the buffer, index = ", m_text_buffer.CurrentIndex, ", char = ", m_text_buffer.Char());
                    return(code);

                default:
                    return(code);
                }
                m_text_buffer.NextChar();
            }
            RecyclableObject.Recycle(m_text_buffer);
            m_text_buffer = null;
            return(Eof);
        }
Exemple #5
0
        public override bool Get(TextBuffer text_buffer)
        {
            char ch = text_buffer.Char();

            switch (ch)
            {
            case '+':
                m_type = TokenType.PLUS;
                text_buffer.NextChar();
                break;

            case '-':
                m_type = TokenType.MINUS;
                text_buffer.NextChar();
                break;

            case '*':
                m_type = TokenType.STAR;
                text_buffer.NextChar();
                break;

            case '/':
                m_type = TokenType.SLASH;
                text_buffer.NextChar();
                break;

            case '(':
                m_type = TokenType.LEFT_PAREN;
                text_buffer.NextChar();
                break;

            case ')':
                m_type = TokenType.RIGHT_PAREN;
                text_buffer.NextChar();
                break;

            case '[':
                m_type = TokenType.LEFT_BRACKET;
                text_buffer.NextChar();
                break;

            case ']':
                m_type = TokenType.RIGHT_BRACKET;
                text_buffer.NextChar();
                break;

            case '.':
                m_type = TokenType.PERIOD;
                text_buffer.NextChar();
                break;

            case ',':
                m_type = TokenType.COMMA;
                text_buffer.NextChar();
                break;

            case '?':
                m_type = TokenType.QUESTION;
                text_buffer.NextChar();
                break;

            case ':':
                m_type = TokenType.SEMICOLON;
                text_buffer.NextChar();
                break;

            case '=':
                m_type = TokenType.EQUAL;
                ch     = text_buffer.NextChar();
                if (ch == '=')
                {
                    m_type = TokenType.EQUAL_EQUAL;
                    text_buffer.NextChar();
                }
                break;

            case '!':
                m_type = TokenType.NOT;
                ch     = text_buffer.NextChar();
                if (ch == '=')
                {
                    m_type = TokenType.NOT_EQUAL;
                    text_buffer.NextChar();
                }
                break;

            case '>':
                m_type = TokenType.GREATER;
                ch     = text_buffer.NextChar();
                if (ch == '=')
                {
                    m_type = TokenType.GREATER_EQUAL;
                    text_buffer.NextChar();
                }
                break;

            case '<':
                m_type = TokenType.LESS;
                ch     = text_buffer.NextChar();
                if (ch == '=')
                {
                    m_type = TokenType.LESS_EQUAL;
                    text_buffer.NextChar();
                }
                break;

            case '&':
                m_type = TokenType.AND_BITWISE;
                ch     = text_buffer.NextChar();
                if (ch == '&')
                {
                    m_type = TokenType.AND;
                    text_buffer.NextChar();
                }
                break;

            case '|':
                m_type = TokenType.OR_BITWISE;
                ch     = text_buffer.NextChar();
                if (ch == '|')
                {
                    m_type = TokenType.OR;
                    text_buffer.NextChar();
                }
                break;

            default:
                LogWrapper.LogError("Expression: SymbolToken.Get(), illegal symbol, index = ", text_buffer.CurrentIndex, ", char = ", text_buffer.Char());
                m_type = TokenType.ERROR;
                return(false);
            }
            return(true);
        }