예제 #1
0
파일: Lexer.cs 프로젝트: fantasydr/krkr-cs
        /// <exception cref="Kirikiri.Tjs2.CompileException"></exception>
        private int GetToken()
        {
            if (mStream.IsEOF() == true)
            {
                return 0;
            }
            if (mRegularExpression == true)
            {
                mRegularExpression = false;
                mStream.SetOffset(mPrevPos);
                mStream.SkipSpace();
                mStream.Next();
                // 最初の'/'を读み飞ばし
                string pattern = ParseRegExp();
                mValue = PutValue(pattern);
                return Token.T_REGEXP;
            }
            int c;
            bool retry;
            do
            {
                retry = false;
                mStream.SkipSpace();
                mPrevPos = mStream.GetOffset();
                c = mStream.GetC();
                switch (c)
                {
                    case 0:
                    case -1:
                    {
                        return 0;
                    }

                    case '>':
                    {
                        c = mStream.GetC();
                        if (c == '>')
                        {
                            // >>
                            c = mStream.GetC();
                            if (c == '>')
                            {
                                // >>>
                                c = mStream.GetC();
                                if (c == '=')
                                {
                                    // >>>=
                                    return Token.T_RBITSHIFTEQUAL;
                                }
                                else
                                {
                                    mStream.UngetC();
                                    return Token.T_RBITSHIFT;
                                }
                            }
                            else
                            {
                                if (c == '=')
                                {
                                    // >>=
                                    return Token.T_RARITHSHIFTEQUAL;
                                }
                                else
                                {
                                    // >>
                                    mStream.UngetC();
                                    return Token.T_RARITHSHIFT;
                                }
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // >=
                                return Token.T_GTOREQUAL;
                            }
                            else
                            {
                                mStream.UngetC();
                                return Token.T_GT;
                            }
                        }
                        goto case '<';
                    }

                    case '<':
                    {
                        c = mStream.GetC();
                        if (c == '<')
                        {
                            // <<
                            c = mStream.GetC();
                            if (c == '=')
                            {
                                // <<=
                                return Token.T_LARITHSHIFTEQUAL;
                            }
                            else
                            {
                                // <<
                                mStream.UngetC();
                                return Token.T_LARITHSHIFT;
                            }
                        }
                        else
                        {
                            if (c == '-')
                            {
                                // <-
                                c = mStream.GetC();
                                if (c == '>')
                                {
                                    // <->
                                    return Token.T_SWAP;
                                }
                                else
                                {
                                    // <
                                    mStream.UngetC();
                                    mStream.UngetC();
                                    return Token.T_LT;
                                }
                            }
                            else
                            {
                                if (c == '=')
                                {
                                    // <=
                                    return Token.T_LTOREQUAL;
                                }
                                else
                                {
                                    if (c == '%')
                                    {
                                        // '<%'   octet literal
                                        ByteBuffer buffer = ParseOctet();
                                        mValue = PutValue(buffer);
                                        return Token.T_CONSTVAL;
                                    }
                                    else
                                    {
                                        // <
                                        mStream.UngetC();
                                        return Token.T_LT;
                                    }
                                }
                            }
                        }
                        goto case '=';
                    }

                    case '=':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            // ===
                            c = mStream.GetC();
                            if (c == '=')
                            {
                                return Token.T_DISCEQUAL;
                            }
                            else
                            {
                                // ==
                                mStream.UngetC();
                                return Token.T_EQUALEQUAL;
                            }
                        }
                        else
                        {
                            if (c == '>')
                            {
                                // =>
                                return Token.T_COMMA;
                            }
                            else
                            {
                                // =
                                mStream.UngetC();
                                return Token.T_EQUAL;
                            }
                        }
                        goto case '!';
                    }

                    case '!':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            c = mStream.GetC();
                            if (c == '=')
                            {
                                // !==
                                return Token.T_DISCNOTEQUAL;
                            }
                            else
                            {
                                // !=
                                mStream.UngetC();
                                return Token.T_NOTEQUAL;
                            }
                        }
                        else
                        {
                            // !
                            mStream.UngetC();
                            return Token.T_EXCRAMATION;
                        }
                        goto case '&';
                    }

                    case '&':
                    {
                        c = mStream.GetC();
                        if (c == '&')
                        {
                            c = mStream.GetC();
                            if (c == '=')
                            {
                                // &&=
                                return Token.T_LOGICALANDEQUAL;
                            }
                            else
                            {
                                // &&
                                mStream.UngetC();
                                return Token.T_LOGICALAND;
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // &=
                                return Token.T_AMPERSANDEQUAL;
                            }
                            else
                            {
                                // &
                                mStream.UngetC();
                                return Token.T_AMPERSAND;
                            }
                        }
                        goto case '|';
                    }

                    case '|':
                    {
                        c = mStream.GetC();
                        if (c == '|')
                        {
                            c = mStream.GetC();
                            if (c == '=')
                            {
                                // ||=
                                return Token.T_LOGICALOREQUAL;
                            }
                            else
                            {
                                // ||
                                mStream.UngetC();
                                return Token.T_LOGICALOR;
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // |=
                                return Token.T_VERTLINEEQUAL;
                            }
                            else
                            {
                                // |
                                mStream.UngetC();
                                return Token.T_VERTLINE;
                            }
                        }
                        goto case '.';
                    }

                    case '.':
                    {
                        c = mStream.GetC();
                        if (c >= '0' && c <= '9')
                        {
                            // number
                            mStream.UngetC();
                            mStream.UngetC();
                            object o = ParseNumber();
                            if (o != null)
                            {
                                if (o is int)
                                {
                                    mValue = PutValue((int)o);
                                }
                                else
                                {
                                    if (o is double)
                                    {
                                        mValue = PutValue((double)o);
                                    }
                                    else
                                    {
                                        mValue = PutValue(null);
                                    }
                                }
                            }
                            else
                            {
                                mValue = PutValue(null);
                            }
                            return Token.T_CONSTVAL;
                        }
                        else
                        {
                            if (c == '.')
                            {
                                c = mStream.GetC();
                                if (c == '.')
                                {
                                    // ...
                                    return Token.T_OMIT;
                                }
                                else
                                {
                                    // .
                                    mStream.UngetC();
                                    mStream.UngetC();
                                    return Token.T_DOT;
                                }
                            }
                            else
                            {
                                // .
                                mStream.UngetC();
                                return Token.T_DOT;
                            }
                        }
                        goto case '+';
                    }

                    case '+':
                    {
                        c = mStream.GetC();
                        if (c == '+')
                        {
                            // ++
                            return Token.T_INCREMENT;
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // +=
                                return Token.T_PLUSEQUAL;
                            }
                            else
                            {
                                // +
                                mStream.UngetC();
                                return Token.T_PLUS;
                            }
                        }
                        goto case '-';
                    }

                    case '-':
                    {
                        c = mStream.GetC();
                        if (c == '-')
                        {
                            // --
                            return Token.T_DECREMENT;
                        }
                        else
                        {
                            if (c == '=')
                            {
                                return Token.T_MINUSEQUAL;
                            }
                            else
                            {
                                // -=
                                // -
                                mStream.UngetC();
                                return Token.T_MINUS;
                            }
                        }
                        goto case '*';
                    }

                    case '*':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            // *=
                            return Token.T_ASTERISKEQUAL;
                        }
                        else
                        {
                            // *
                            mStream.UngetC();
                            return Token.T_ASTERISK;
                        }
                        goto case '/';
                    }

                    case '/':
                    {
                        c = mStream.GetC();
                        if (c == '/' || c == '*')
                        {
                            mStream.UngetC();
                            mStream.UngetC();
                            int comment = mStream.SkipComment();
                            if (comment == StringStream.CONTINUE)
                            {
                                retry = true;
                                break;
                            }
                            else
                            {
                                if (comment == StringStream.ENDED)
                                {
                                    return 0;
                                }
                            }
                        }
                        if (c == '=')
                        {
                            // /=
                            return Token.T_SLASHEQUAL;
                        }
                        else
                        {
                            // /
                            mStream.UngetC();
                            return Token.T_SLASH;
                        }
                        goto case '\\';
                    }

                    case '\\':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            // \=
                            return Token.T_BACKSLASHEQUAL;
                        }
                        else
                        {
                            // \
                            mStream.UngetC();
                            return Token.T_BACKSLASH;
                        }
                        goto case '%';
                    }

                    case '%':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            // %=
                            return Token.T_PERCENTEQUAL;
                        }
                        else
                        {
                            // %
                            mStream.UngetC();
                            return Token.T_PERCENT;
                        }
                        goto case '^';
                    }

                    case '^':
                    {
                        c = mStream.GetC();
                        if (c == '=')
                        {
                            // ^=
                            return Token.T_CHEVRONEQUAL;
                        }
                        else
                        {
                            // ^
                            mStream.UngetC();
                            return Token.T_CHEVRON;
                        }
                        goto case '[';
                    }

                    case '[':
                    {
                        mNestLevel++;
                        return Token.T_LBRACKET;
                    }

                    case ']':
                    {
                        mNestLevel--;
                        return Token.T_RBRACKET;
                    }

                    case '(':
                    {
                        mNestLevel++;
                        return Token.T_LPARENTHESIS;
                    }

                    case ')':
                    {
                        mNestLevel--;
                        return Token.T_RPARENTHESIS;
                    }

                    case '~':
                    {
                        return Token.T_TILDE;
                    }

                    case '?':
                    {
                        return Token.T_QUESTION;
                    }

                    case ':':
                    {
                        return Token.T_COLON;
                    }

                    case ',':
                    {
                        return Token.T_COMMA;
                    }

                    case ';':
                    {
                        return Token.T_SEMICOLON;
                    }

                    case '{':
                    {
                        mNestLevel++;
                        return Token.T_LBRACE;
                    }

                    case '}':
                    {
                        mNestLevel--;
                        return Token.T_RBRACE;
                    }

                    case '#':
                    {
                        return Token.T_SHARP;
                    }

                    case '$':
                    {
                        return Token.T_DOLLAR;
                    }

                    case '\'':
                    case '\"':
                    {
                        // literal string
                        string str = ParseString(c);
                        mValue = PutValue(str);
                        return Token.T_CONSTVAL;
                    }

                    case '@':
                    {
                        // embeddable expression in string (such as @"this can be embeddable like &variable;")
                        int offset = mStream.GetOffset();
                        mStream.SkipSpace();
                        c = mStream.Next();
                        if (c == '\'' || c == '\"')
                        {
                            EmbeddableExpressionData data = new EmbeddableExpressionData();
                            data.mState = EmbeddableExpressionData.START;
                            data.mWaitingNestLevel = mNestLevel;
                            data.mDelimiter = c;
                            data.mNeedPlus = false;
                            if (mStream.IsEOF())
                            {
                                return 0;
                            }
                            mEmbeddableExpressionDataStack.AddItem(data);
                            return -1;
                        }
                        else
                        {
                            mStream.SetOffset(offset);
                        }
                        switch (ProcessPPStatement())
                        {
                            case StringStream.CONTINUE:
                            {
                                // possible pre-procesor statements
                                retry = true;
                                break;
                            }

                            case StringStream.ENDED:
                            {
                                return 0;
                            }

                            case StringStream.NOT_COMMENT:
                            {
                                mStream.SetOffset(offset);
                                break;
                            }
                        }
                        break;
                    }

                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    {
                        mStream.UngetC();
                        object o = ParseNumber();
                        if (o != null)
                        {
                            if (o is int)
                            {
                                mValue = PutValue((int)o);
                            }
                            else
                            {
                                if (o is double)
                                {
                                    mValue = PutValue((double)o);
                                }
                                else
                                {
                                    throw new CompileException(Error.NumberError);
                                }
                            }
                        }
                        else
                        {
                            throw new CompileException(Error.NumberError);
                        }
                        return Token.T_CONSTVAL;
                    }
                }
            }
            while (retry);
            // switch(c)
            if (IsWAlpha(c) == false && c != '_')
            {
                string str = Error.InvalidChar.Replace("%1", EscapeC((char)c));
                throw new CompileException(str);
            }
            int oldC = c;
            int offset_1 = mStream.GetOffset() - 1;
            int nch = 0;
            while (IsWDigit(c) || IsWAlpha(c) || c == '_' || c > unchecked((int)(0x0100)) ||
                c == LINE_FEED)
            {
                c = mStream.GetC();
                nch++;
            }
            if (nch == 0)
            {
                string str = Error.InvalidChar.Replace("%1", EscapeC((char)oldC));
                throw new CompileException(str);
            }
            else
            {
                mStream.UngetC();
            }
            string str_1 = mStream.Substring(offset_1, offset_1 + nch);
            int strLen = str_1.Length;
            StringBuilder symStr = new StringBuilder(BUFFER_CAPACITY);
            for (int i = 0; i < strLen; i++)
            {
                char t = str_1[i];
                if (t != LINE_FEED)
                {
                    symStr.Append(t);
                }
            }
            str_1 = symStr.ToString();
            int retnum;
            if (mBareWord)
            {
                retnum = -1;
            }
            else
            {
                int id = mReservedWordHash.Get(str_1);
                if (id != null)
                {
                    retnum = id;
                }
                else
                {
                    retnum = -1;
                }
            }
            mBareWord = false;
            if (retnum == -1)
            {
                // not a reserved word
                mValue = PutValue(str_1);
                return Token.T_SYMBOL;
            }
            switch (retnum)
            {
                case Token.T_FALSE:
                {
                    mValue = PutValue(Sharpen.Extensions.ValueOf(0));
                    return Token.T_CONSTVAL;
                }

                case Token.T_NULL:
                {
                    mValue = PutValue(new VariantClosure(null));
                    return Token.T_CONSTVAL;
                }

                case Token.T_TRUE:
                {
                    mValue = PutValue(Sharpen.Extensions.ValueOf(1));
                    return Token.T_CONSTVAL;
                }

                case Token.T_NAN:
                {
                    mValue = PutValue((double.NaN));
                    return Token.T_CONSTVAL;
                }

                case Token.T_INFINITY:
                {
                    mValue = PutValue((double.PositiveInfinity));
                    return Token.T_CONSTVAL;
                }
            }
            return retnum;
        }
예제 #2
0
        /// <exception cref="Kirikiri.Tjs2.CompileException"></exception>
        private int GetToken()
        {
            char[] ptr = mText;
            int c = ptr[mCurrent];
            if (c == 0)
            {
                return 0;
            }
            if (mRegularExpression == true)
            {
                mRegularExpression = false;
                mCurrent = mPrevPos;
                //next(); // 最初の'/'を读み飞ばし
                mCurrent++;
                if (mText[mCurrent] == CR && mText[mCurrent + 1] == LF)
                {
                    mCurrent++;
                }
                string pattern = ParseRegExp();
                mValue = PutValue(pattern);
                return Token.T_REGEXP;
            }
            bool retry;
            do
            {
                retry = false;
                mPrevPos = mCurrent;
                c = ptr[mCurrent];
                switch (c)
                {
                    case 0:
                    {
                        return 0;
                    }

                    case '>':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '>')
                        {
                            // >>
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '>')
                            {
                                // >>>
                                mCurrent++;
                                c = ptr[mCurrent];
                                if (c == '=')
                                {
                                    // >>>=
                                    mCurrent++;
                                    return Token.T_RBITSHIFTEQUAL;
                                }
                                else
                                {
                                    return Token.T_RBITSHIFT;
                                }
                            }
                            else
                            {
                                if (c == '=')
                                {
                                    // >>=
                                    mCurrent++;
                                    return Token.T_RARITHSHIFTEQUAL;
                                }
                                else
                                {
                                    // >>
                                    return Token.T_RARITHSHIFT;
                                }
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // >=
                                mCurrent++;
                                return Token.T_GTOREQUAL;
                            }
                            else
                            {
                                return Token.T_GT;
                            }
                        }
                        goto case '<';
                    }

                    case '<':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '<')
                        {
                            // <<
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '=')
                            {
                                // <<=
                                mCurrent++;
                                return Token.T_LARITHSHIFTEQUAL;
                            }
                            else
                            {
                                // <<
                                return Token.T_LARITHSHIFT;
                            }
                        }
                        else
                        {
                            if (c == '-')
                            {
                                // <-
                                mCurrent++;
                                c = ptr[mCurrent];
                                if (c == '>')
                                {
                                    // <->
                                    mCurrent++;
                                    return Token.T_SWAP;
                                }
                                else
                                {
                                    // <
                                    mCurrent--;
                                    return Token.T_LT;
                                }
                            }
                            else
                            {
                                if (c == '=')
                                {
                                    // <=
                                    mCurrent++;
                                    return Token.T_LTOREQUAL;
                                }
                                else
                                {
                                    if (c == '%')
                                    {
                                        // '<%'   octet literal
                                        ByteBuffer buffer = ParseOctet();
                                        mValue = PutValue(buffer);
                                        return Token.T_CONSTVAL;
                                    }
                                    else
                                    {
                                        // <
                                        return Token.T_LT;
                                    }
                                }
                            }
                        }
                        goto case '=';
                    }

                    case '=':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            // ===
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '=')
                            {
                                mCurrent++;
                                return Token.T_DISCEQUAL;
                            }
                            else
                            {
                                // ==
                                return Token.T_EQUALEQUAL;
                            }
                        }
                        else
                        {
                            if (c == '>')
                            {
                                // =>
                                mCurrent++;
                                return Token.T_COMMA;
                            }
                            else
                            {
                                // =
                                return Token.T_EQUAL;
                            }
                        }
                        goto case '!';
                    }

                    case '!':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '=')
                            {
                                // !==
                                mCurrent++;
                                return Token.T_DISCNOTEQUAL;
                            }
                            else
                            {
                                // !=
                                return Token.T_NOTEQUAL;
                            }
                        }
                        else
                        {
                            // !
                            return Token.T_EXCRAMATION;
                        }
                        goto case '&';
                    }

                    case '&':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '&')
                        {
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '=')
                            {
                                // &&=
                                mCurrent++;
                                return Token.T_LOGICALANDEQUAL;
                            }
                            else
                            {
                                // &&
                                return Token.T_LOGICALAND;
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // &=
                                mCurrent++;
                                return Token.T_AMPERSANDEQUAL;
                            }
                            else
                            {
                                // &
                                return Token.T_AMPERSAND;
                            }
                        }
                        goto case '|';
                    }

                    case '|':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '|')
                        {
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == '=')
                            {
                                // ||=
                                mCurrent++;
                                return Token.T_LOGICALOREQUAL;
                            }
                            else
                            {
                                // ||
                                return Token.T_LOGICALOR;
                            }
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // |=
                                mCurrent++;
                                return Token.T_VERTLINEEQUAL;
                            }
                            else
                            {
                                // |
                                return Token.T_VERTLINE;
                            }
                        }
                        goto case '.';
                    }

                    case '.':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c >= '0' && c <= '9')
                        {
                            // number
                            mCurrent--;
                            //mCurrent--;
                            Number o = ParseNumber();
                            if (o != null)
                            {
                                if (o.IsInt())
                                {
                                    mValue = PutValue((int)o);
                                }
                                else
                                {
                                    if (o.IsDouble())
                                    {
                                        mValue = PutValue((double)o);
                                    }
                                    else
                                    {
                                        mValue = PutValue(null);
                                    }
                                }
                            }
                            else
                            {
                                mValue = PutValue(null);
                            }
                            return Token.T_CONSTVAL;
                        }
                        else
                        {
                            if (c == '.')
                            {
                                mCurrent++;
                                c = ptr[mCurrent];
                                if (c == '.')
                                {
                                    // ...
                                    mCurrent++;
                                    return Token.T_OMIT;
                                }
                                else
                                {
                                    // .
                                    mCurrent--;
                                    //mCurrent--;
                                    return Token.T_DOT;
                                }
                            }
                            else
                            {
                                // .
                                return Token.T_DOT;
                            }
                        }
                        goto case '+';
                    }

                    case '+':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '+')
                        {
                            // ++
                            mCurrent++;
                            return Token.T_INCREMENT;
                        }
                        else
                        {
                            if (c == '=')
                            {
                                // +=
                                mCurrent++;
                                return Token.T_PLUSEQUAL;
                            }
                            else
                            {
                                // +
                                return Token.T_PLUS;
                            }
                        }
                        goto case '-';
                    }

                    case '-':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '-')
                        {
                            // --
                            mCurrent++;
                            return Token.T_DECREMENT;
                        }
                        else
                        {
                            if (c == '=')
                            {
                                mCurrent++;
                                return Token.T_MINUSEQUAL;
                            }
                            else
                            {
                                // -=
                                // -
                                return Token.T_MINUS;
                            }
                        }
                        goto case '*';
                    }

                    case '*':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            // *=
                            mCurrent++;
                            return Token.T_ASTERISKEQUAL;
                        }
                        else
                        {
                            // *
                            return Token.T_ASTERISK;
                        }
                        goto case '/';
                    }

                    case '/':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '/' || c == '*')
                        {
                            mCurrent--;
                            int comment = SkipComment();
                            if (comment == CONTINUE)
                            {
                                retry = true;
                                break;
                            }
                            else
                            {
                                if (comment == ENDED)
                                {
                                    return 0;
                                }
                            }
                        }
                        if (c == '=')
                        {
                            // /=
                            mCurrent++;
                            return Token.T_SLASHEQUAL;
                        }
                        else
                        {
                            // /
                            return Token.T_SLASH;
                        }
                        goto case '\\';
                    }

                    case '\\':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            // \=
                            mCurrent++;
                            return Token.T_BACKSLASHEQUAL;
                        }
                        else
                        {
                            // \
                            return Token.T_BACKSLASH;
                        }
                        goto case '%';
                    }

                    case '%':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            // %=
                            mCurrent++;
                            return Token.T_PERCENTEQUAL;
                        }
                        else
                        {
                            // %
                            return Token.T_PERCENT;
                        }
                        goto case '^';
                    }

                    case '^':
                    {
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == '=')
                        {
                            // ^=
                            mCurrent++;
                            return Token.T_CHEVRONEQUAL;
                        }
                        else
                        {
                            // ^
                            return Token.T_CHEVRON;
                        }
                        goto case '[';
                    }

                    case '[':
                    {
                        mNestLevel++;
                        mCurrent++;
                        return Token.T_LBRACKET;
                    }

                    case ']':
                    {
                        mNestLevel--;
                        mCurrent++;
                        return Token.T_RBRACKET;
                    }

                    case '(':
                    {
                        mNestLevel++;
                        mCurrent++;
                        return Token.T_LPARENTHESIS;
                    }

                    case ')':
                    {
                        mNestLevel--;
                        mCurrent++;
                        return Token.T_RPARENTHESIS;
                    }

                    case '~':
                    {
                        mCurrent++;
                        return Token.T_TILDE;
                    }

                    case '?':
                    {
                        mCurrent++;
                        return Token.T_QUESTION;
                    }

                    case ':':
                    {
                        mCurrent++;
                        return Token.T_COLON;
                    }

                    case ',':
                    {
                        mCurrent++;
                        return Token.T_COMMA;
                    }

                    case ';':
                    {
                        mCurrent++;
                        return Token.T_SEMICOLON;
                    }

                    case '{':
                    {
                        mNestLevel++;
                        mCurrent++;
                        return Token.T_LBRACE;
                    }

                    case '}':
                    {
                        mNestLevel--;
                        mCurrent++;
                        return Token.T_RBRACE;
                    }

                    case '#':
                    {
                        mCurrent++;
                        return Token.T_SHARP;
                    }

                    case '$':
                    {
                        mCurrent++;
                        return Token.T_DOLLAR;
                    }

                    case '\'':
                    case '\"':
                    {
                        // literal string
                        //String str = parseString(c);
                        //next();
                        mCurrent++;
                        if (mText[mCurrent] == CR && mText[mCurrent + 1] == LF)
                        {
                            mCurrent++;
                        }
                        string str = ReadString(c, false);
                        mValue = PutValue(str);
                        return Token.T_CONSTVAL;
                    }

                    case '@':
                    {
                        // embeddable expression in string (such as @"this can be embeddable like &variable;")
                        int org = mCurrent;
                        //if( !next() ) return 0;
                        mCurrent++;
                        c = ptr[mCurrent];
                        if (c == CR && ptr[mCurrent + 1] == LF)
                        {
                            mCurrent++;
                            c = ptr[mCurrent];
                        }
                        //if( !skipSpace() ) return 0;
                        while (c != 0 && c <= SPACE && (c == CR || c == LF || c == TAB || c == SPACE))
                        {
                            mCurrent++;
                            c = ptr[mCurrent];
                        }
                        if (c == 0)
                        {
                            return 0;
                        }
                        //c = ptr[mCurrent];
                        if (c == '\'' || c == '\"')
                        {
                            EmbeddableExpressionData data = new EmbeddableExpressionData();
                            data.mState = EmbeddableExpressionData.START;
                            data.mWaitingNestLevel = mNestLevel;
                            data.mDelimiter = c;
                            data.mNeedPlus = false;
                            //if( !next() ) return 0;
                            mCurrent++;
                            c = ptr[mCurrent];
                            if (c == CR && ptr[mCurrent + 1] == LF)
                            {
                                mCurrent++;
                                c = ptr[mCurrent];
                            }
                            if (c == 0)
                            {
                                return 0;
                            }
                            mEmbeddableExpressionDataStack.AddItem(data);
                            return -1;
                        }
                        else
                        {
                            mCurrent = org;
                        }
                        switch (ProcessPPStatement())
                        {
                            case CONTINUE:
                            {
                                // possible pre-procesor statements
                                retry = true;
                                break;
                            }

                            case ENDED:
                            {
                                return 0;
                            }

                            case NOT_COMMENT:
                            {
                                mCurrent = org;
                                break;
                            }
                        }
                        break;
                    }

                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    {
                        Number o = ParseNumber();
                        if (o != null)
                        {
                            if (o.IsInt())
                            {
                                mValue = PutValue((int)o);
                            }
                            else
                            {
                                if (o.IsDouble())
                                {
                                    mValue = PutValue((double)o);
                                }
                                else
                                {
                                    throw new CompileException(Error.NumberError, mBlock, mCurrent);
                                }
                            }
                        }
                        else
                        {
                            throw new CompileException(Error.NumberError, mBlock, mCurrent);
                        }
                        return Token.T_CONSTVAL;
                    }
                }
            }
            while (retry);
            // switch(c)
            if ((((c & unchecked((int)(0xFF00))) != 0) || (c >= 'A' && c <= 'Z') || (c >= 'a'
                 && c <= 'z')) == false && c != '_')
            {
                //if( isWAlpha(c) == false && c != '_' ) {
                string str = Error.InvalidChar.Replace("%1", EscapeC((char)c));
                throw new CompileException(str, mBlock, mCurrent);
            }
            int oldC = c;
            int offset = mCurrent;
            int nch = 0;
            while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || (c >= '0'
                && c <= '9') || ((c & unchecked((int)(0xFF00))) != 0))
            {
                //while( isWDigit(c) || isWAlpha(c) || c == '_' || c > 0x0100 || /*c == CARRIAGE_RETURN || */c == LINE_FEED ) {
                mCurrent++;
                c = ptr[mCurrent];
                nch++;
            }
            if (nch == 0)
            {
                string str = Error.InvalidChar.Replace("%1", EscapeC((char)oldC));
                throw new CompileException(str, mBlock, mCurrent);
            }
            string str_1 = new string(ptr, offset, nch);
            int retnum;
            if (mBareWord)
            {
                retnum = -1;
                mBareWord = false;
            }
            else
            {
                retnum = ReservedWordToken.GetToken(str_1);
            }
            if (retnum == -1)
            {
                // not a reserved word
                mValue = PutValue(str_1);
                return Token.T_SYMBOL;
            }
            switch (retnum)
            {
                case Token.T_FALSE:
                {
                    mValue = PutValue(Sharpen.Extensions.ValueOf(0));
                    return Token.T_CONSTVAL;
                }

                case Token.T_NULL:
                {
                    mValue = PutValue(new VariantClosure(null));
                    return Token.T_CONSTVAL;
                }

                case Token.T_TRUE:
                {
                    mValue = PutValue(Sharpen.Extensions.ValueOf(1));
                    return Token.T_CONSTVAL;
                }

                case Token.T_NAN:
                {
                    mValue = PutValue((double.NaN));
                    return Token.T_CONSTVAL;
                }

                case Token.T_INFINITY:
                {
                    mValue = PutValue((double.PositiveInfinity));
                    return Token.T_CONSTVAL;
                }
            }
            return retnum;
        }