⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenizer.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            iType = NAME;        } else if (Character.isDigit(c)) {            iType = NUMBER;            digit = true;        } else {            switch (c) {                case '(' :                    sToken = Token.T_OPENBRACKET;                    iType  = SPECIAL;                    iIndex++;                    return;                case ')' :                    sToken = Token.T_CLOSEBRACKET;                    iType  = SPECIAL;                    iIndex++;                    return;                case ',' :                    sToken = Token.T_COMMA;                    iType  = SPECIAL;                    iIndex++;                    return;                case '*' :                    sToken = Token.T_MULTIPLY;                    iType  = SPECIAL;                    iIndex++;                    return;                case '=' :                    sToken = Token.T_EQUALS;                    iType  = SPECIAL;                    iIndex++;                    return;                case ';' :                    sToken = Token.T_SEMICOLON;                    iType  = SPECIAL;                    iIndex++;                    return;                case '+' :                    sToken = Token.T_PLUS;                    iType  = SPECIAL;                    iIndex++;                    return;                case '%' :                    sToken = Token.T_PERCENT;                    iType  = SPECIAL;                    iIndex++;                    return;                case '?' :                    sToken = Token.T_QUESTION;                    iType  = SPECIAL;                    iIndex++;                    return;                case '\"' :                    lastTokenQuotedID = true;                    iType             = QUOTED_IDENTIFIER;                    iIndex++;                    sToken = getString('"');                    if (iIndex == sCommand.length()) {                        return;                    }                    c = sCommand.charAt(iIndex);                    if (c == '.') {                        sLongNameFirst    = sToken;                        typeLongNameFirst = iType;                        iIndex++;                        if (retainFirst) {                            throw Trace.error(Trace.THREE_PART_IDENTIFIER);                        }// fredt - todo - avoid recursion - this has problems when there is whitespace// after the dot - the same with NAME                        retainFirst = true;                        getToken();                        retainFirst = false;                        iType       = LONG_NAME;                    }                    return;                case '\'' :                    iType = STRING;                    iIndex++;                    sToken = getString('\'');                    return;                case '!' :                case '<' :                case '>' :                case '|' :                case '/' :                case '-' :                    cfirst = c;                    iType  = SPECIAL;                    break;                case '.' :                    iType = DECIMAL;                    point = true;                    break;                default :                    throw Trace.error(Trace.UNEXPECTED_TOKEN,                                      String.valueOf(c));            }        }        int start = iIndex++;        while (true) {            if (iIndex >= iLength) {                c   = ' ';                end = true;                Trace.check(iType != STRING && iType != QUOTED_IDENTIFIER,                            Trace.UNEXPECTED_END_OF_COMMAND);            } else {                c = sCommand.charAt(iIndex);            }            switch (iType) {                case NAME :                    if (Character.isJavaIdentifierPart(c)) {                        break;                    }                    // fredt - todo new char[] to back sToken                    sToken = sCommand.substring(start, iIndex).toUpperCase(                        Locale.ENGLISH);                    if (c == '.') {                        typeLongNameFirst = iType;                        sLongNameFirst    = sToken;                        iIndex++;                        if (retainFirst) {                            throw Trace.error(Trace.THREE_PART_IDENTIFIER);                        }                        retainFirst = true;                        getToken();    // todo: eliminate recursion                        retainFirst = false;                        iType       = LONG_NAME;                    } else if (c == '(') {                        // it is a function call                    } else {                        // if in value list then it is a value                        int type = valueTokens.get(sToken, -1);                        if (type != -1) {                            iType = type;                        }                    }                    return;                case QUOTED_IDENTIFIER :                case STRING :                    // shouldn't get here                    break;                case REMARK :                    if (end) {                        // unfinished remark                        // maybe print error here                        iType = NO_TYPE;                        return;                    } else if (c == '*') {                        iIndex++;                        if (iIndex < iLength                                && sCommand.charAt(iIndex) == '/') {                            // using recursion here                            iIndex++;                            getToken();                            return;                        }                    }                    break;                case REMARK_LINE :                    if (end) {                        iType = NO_TYPE;                        return;                    } else if (c == '\r' || c == '\n') {                        // using recursion here                        getToken();                        return;                    }                    break;                case SPECIAL :                    if (c == '/' && cfirst == '/') {                        iType = REMARK_LINE;                        break;                    } else if (c == '-' && cfirst == '-') {                        iType = REMARK_LINE;                        break;                    } else if (c == '*' && cfirst == '/') {                        iType = REMARK;                        break;                    } else if (c == '>' || c == '=' || c == '|') {                        break;                    }                    sToken = sCommand.substring(start, iIndex);                    return;                case NUMBER :                case FLOAT :                case DECIMAL :                    if (Character.isDigit(c)) {                        digit = true;                    } else if (c == '.') {                        iType = DECIMAL;                        if (point) {                            throw Trace.error(Trace.UNEXPECTED_TOKEN, ".");                        }                        point = true;                    } else if (c == 'E' || c == 'e') {                        if (exp) {                            throw Trace.error(Trace.UNEXPECTED_TOKEN, "E");                        }                        // HJB-2001-08-2001 - now we are sure it's a float                        iType = FLOAT;                        // first character after exp may be + or -                        afterexp = true;                        point    = true;                        exp      = true;                    } else if (c == '-' && afterexp) {                        afterexp = false;                    } else if (c == '+' && afterexp) {                        afterexp = false;                    } else {                        afterexp = false;                        if (!digit) {                            if (point && start == iIndex - 1) {                                sToken = ".";                                iType  = SPECIAL;                                return;                            }                            throw Trace.error(Trace.UNEXPECTED_TOKEN,                                              String.valueOf(c));                        }                        sToken = sCommand.substring(start, iIndex);                        return;                    }            }            iIndex++;        }    }// fredt - strings are constructed from new char[] objects to avoid slack// because these strings might end up as part of internal data structures// or table elements.// we may consider using pools to avoid recreating the strings    private String getString(char quoteChar) throws HsqlException {        try {            int     nextIndex   = iIndex;            boolean quoteInside = false;            for (;;) {                nextIndex = sCommand.indexOf(quoteChar, nextIndex);                if (nextIndex < 0) {                    throw Trace.error(Trace.UNEXPECTED_END_OF_COMMAND);                }                if (nextIndex < iLength - 1                        && sCommand.charAt(nextIndex + 1) == quoteChar) {                    quoteInside = true;                    nextIndex   += 2;                    continue;                }                break;            }            char[] chBuffer = new char[nextIndex - iIndex];            sCommand.getChars(iIndex, nextIndex, chBuffer, 0);            int j = chBuffer.length;            if (quoteInside) {                j = 0;                // fredt - loop assumes all occurences of quoteChar are paired                // this has already been checked by the preprocessing loop                for (int i = 0; i < chBuffer.length; i++, j++) {                    if (chBuffer[i] == quoteChar) {                        i++;                    }                    chBuffer[j] = chBuffer[i];                }            }            iIndex = ++nextIndex;            return new String(chBuffer, 0, j);        } catch (HsqlException e) {            throw e;        } catch (Exception e) {            e.getMessage();        }        return null;    }    /**     * Method declaration     *     *     * @return     */    int getLength() {        return iLength;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -