169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/*
269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit.
369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version
669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with
769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License.  Alternatively, the contents of this file may be used under
869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later.
969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis,
1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the
1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License.
1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist.compiler;
1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalclass Token {
1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public Token next = null;
2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int tokenId;
2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public long longValue;
2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public double doubleValue;
2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String textValue;
2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic class Lex implements TokenId {
2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int lastChar;
2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private StringBuffer textBuffer;
3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private Token currentToken;
3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private Token lookAheadTokens;
3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private String input;
3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int position, maxlen, lineNumber;
3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Constructs a lexical analyzer.
3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public Lex(String s) {
4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        lastChar = -1;
4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        textBuffer = new StringBuffer();
4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        currentToken = new Token();
4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        lookAheadTokens = null;
4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        input = s;
4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        position = 0;
4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        maxlen = s.length();
4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        lineNumber = 0;
4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int get() {
5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (lookAheadTokens == null)
5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return get(currentToken);
5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else {
5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            Token t;
5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            currentToken = t = lookAheadTokens;
5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            lookAheadTokens = lookAheadTokens.next;
5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return t.tokenId;
5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Looks at the next token.
6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int lookAhead() {
6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return lookAhead(0);
6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int lookAhead(int i) {
7069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        Token tk = lookAheadTokens;
7169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (tk == null) {
7269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            lookAheadTokens = tk = currentToken;  // reuse an object!
7369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            tk.next = null;
7469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            get(tk);
7569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
7669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
7769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        for (; i-- > 0; tk = tk.next)
7869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (tk.next == null) {
7969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                Token tk2;
8069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                tk.next = tk2 = new Token();
8169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                get(tk2);
8269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
8369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
8469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        currentToken = tk;
8569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return tk.tokenId;
8669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
8769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
8869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String getString() {
8969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return currentToken.textValue;
9069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
9169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
9269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public long getLong() {
9369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return currentToken.longValue;
9469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
9569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
9669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public double getDouble() {
9769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return currentToken.doubleValue;
9869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
9969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
10069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int get(Token token) {
10169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int t;
10269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        do {
10369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            t = readLine(token);
10469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        } while (t == '\n');
10569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        token.tokenId = t;
10669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return t;
10769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
10869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
10969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readLine(Token token) {
11069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c = getNextNonWhiteChar();
11169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if(c < 0)
11269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return c;
11369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if(c == '\n') {
11469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            ++lineNumber;
11569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return '\n';
11669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
11769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == '\'')
11869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readCharConst(token);
11969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == '"')
12069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readStringL(token);
12169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if ('0' <= c && c <= '9')
12269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readNumber(c, token);
12369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if(c == '.'){
12469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = getc();
12569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if ('0' <= c && c <= '9') {
12669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                StringBuffer tbuf = textBuffer;
12769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                tbuf.setLength(0);
12869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                tbuf.append('.');
12969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return readDouble(tbuf, c, token);
13069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
13169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else{
13269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                ungetc(c);
13369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return readSeparator('.');
13469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
13569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
13669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (Character.isJavaIdentifierStart((char)c))
13769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readIdentifier(c, token);
13869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else
13969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readSeparator(c);
14069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
14169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
14269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int getNextNonWhiteChar() {
14369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c;
14469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        do {
14569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = getc();
14669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c == '/') {
14769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c = getc();
14869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if (c == '/')
14969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    do {
15069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        c = getc();
15169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    } while (c != '\n' && c != '\r' && c != -1);
15269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else if (c == '*')
15369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    while (true) {
15469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        c = getc();
15569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        if (c == -1)
15669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            break;
15769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else if (c == '*')
15869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            if ((c = getc()) == '/') {
15969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                c = ' ';
16069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                break;
16169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            }
16269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            else
16369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                ungetc(c);
16469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    }
16569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else {
16669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    ungetc(c);
16769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    c = '/';
16869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                }
16969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
17069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        } while(isBlank(c));
17169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return c;
17269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
17369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
17469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readCharConst(Token token) {
17569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c;
17669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int value = 0;
17769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        while ((c = getc()) != '\'')
17869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c == '\\')
17969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                value = readEscapeChar();
18069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else if (c < 0x20) {
18169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if (c == '\n')
18269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    ++lineNumber;
18369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
18469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return BadToken;
18569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
18669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else
18769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                value = c;
18869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
18969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        token.longValue = value;
19069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return CharConstant;
19169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
19269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
19369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readEscapeChar() {
19469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c = getc();
19569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c == 'n')
19669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = '\n';
19769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == 't')
19869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = '\t';
19969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == 'r')
20069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = '\r';
20169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == 'f')
20269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = '\f';
20369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == '\n')
20469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            ++lineNumber;
20569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
20669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return c;
20769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
20869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
20969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readStringL(Token token) {
21069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c;
21169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        StringBuffer tbuf = textBuffer;
21269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        tbuf.setLength(0);
21369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        for (;;) {
21469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            while ((c = getc()) != '"') {
21569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if (c == '\\')
21669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    c = readEscapeChar();
21769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else if (c == '\n' || c < 0) {
21869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    ++lineNumber;
21969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    return BadToken;
22069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                }
22169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
22269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                tbuf.append((char)c);
22369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
22469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
22569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            for (;;) {
22669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c = getc();
22769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if (c == '\n')
22869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    ++lineNumber;
22969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else if (!isBlank(c))
23069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    break;
23169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
23269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
23369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c != '"') {
23469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                ungetc(c);
23569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                break;
23669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
23769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
23869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
23969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        token.textValue = tbuf.toString();
24069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return StringL;
24169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
24269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
24369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readNumber(int c, Token token) {
24469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        long value = 0;
24569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c2 = getc();
24669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c == '0')
24769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c2 == 'X' || c2 == 'x')
24869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                for (;;) {
24969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    c = getc();
25069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    if ('0' <= c && c <= '9')
25169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        value = value * 16 + (long)(c - '0');
25269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    else if ('A' <= c && c <= 'F')
25369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        value = value * 16 + (long)(c - 'A' + 10);
25469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    else if ('a' <= c && c <= 'f')
25569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        value = value * 16 + (long)(c - 'a' + 10);
25669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    else {
25769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        token.longValue = value;
25869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        if (c == 'L' || c == 'l')
25969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return LongConstant;
26069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else {
26169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            ungetc(c);
26269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return IntConstant;
26369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        }
26469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    }
26569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                }
26669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else if ('0' <= c2 && c2 <= '7') {
26769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                value = c2 - '0';
26869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                for (;;) {
26969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    c = getc();
27069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    if ('0' <= c && c <= '7')
27169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        value = value * 8 + (long)(c - '0');
27269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    else {
27369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        token.longValue = value;
27469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        if (c == 'L' || c == 'l')
27569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return LongConstant;
27669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else {
27769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            ungetc(c);
27869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return IntConstant;
27969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        }
28069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    }
28169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                }
28269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
28369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
28469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        value = c - '0';
28569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        while ('0' <= c2 && c2 <= '9') {
28669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            value = value * 10 + c2 - '0';
28769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c2 = getc();
28869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
28969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
29069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        token.longValue = value;
29169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c2 == 'F' || c2 == 'f') {
29269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            token.doubleValue = (double)value;
29369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return FloatConstant;
29469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
29569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c2 == 'E' || c2 == 'e'
29669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                 || c2 == 'D' || c2 == 'd' || c2 == '.') {
29769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            StringBuffer tbuf = textBuffer;
29869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            tbuf.setLength(0);
29969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            tbuf.append(value);
30069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return readDouble(tbuf, c2, token);
30169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
30269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c2 == 'L' || c2 == 'l')
30369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return LongConstant;
30469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else {
30569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            ungetc(c2);
30669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return IntConstant;
30769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
30869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
30969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
31069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readDouble(StringBuffer sbuf, int c, Token token) {
31169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c != 'E' && c != 'e' && c != 'D' && c != 'd') {
31269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            sbuf.append((char)c);
31369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            for (;;) {
31469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c = getc();
31569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if ('0' <= c && c <= '9')
31669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    sbuf.append((char)c);
31769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else
31869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    break;
31969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
32069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
32169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
32269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c == 'E' || c == 'e') {
32369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            sbuf.append((char)c);
32469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = getc();
32569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c == '+' || c == '-') {
32669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                sbuf.append((char)c);
32769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c = getc();
32869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
32969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
33069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            while ('0' <= c && c <= '9') {
33169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                sbuf.append((char)c);
33269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c = getc();
33369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
33469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
33569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
33669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        try {
33769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            token.doubleValue = Double.parseDouble(sbuf.toString());
33869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
33969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        catch (NumberFormatException e) {
34069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return BadToken;
34169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
34269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
34369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (c == 'F' || c == 'f')
34469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return FloatConstant;
34569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else {
34669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c != 'D' && c != 'd')
34769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                ungetc(c);
34869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
34969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return DoubleConstant;
35069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
35169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
35269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
35369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    // !"#$%&'(    )*+,-./0    12345678    9:;<=>?
35469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private static final int[] equalOps
35569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        =  { NEQ, 0, 0, 0, MOD_E, AND_E, 0, 0,
35669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             0, MUL_E, PLUS_E, 0, MINUS_E, 0, DIV_E, 0,
35769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             0, 0, 0, 0, 0, 0, 0, 0,
35869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             0, 0, 0, LE, EQ, GE, 0 };
35969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
36069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readSeparator(int c) {
36169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int c2, c3;
36269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if ('!' <= c && c <= '?') {
36369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            int t = equalOps[c - '!'];
36469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (t == 0)
36569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return c;
36669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else {
36769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                c2 = getc();
36869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                if (c == c2)
36969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    switch (c) {
37069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '=' :
37169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        return EQ;
37269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '+' :
37369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        return PLUSPLUS;
37469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '-' :
37569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        return MINUSMINUS;
37669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '&' :
37769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        return ANDAND;
37869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '<' :
37969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        c3 = getc();
38069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        if (c3 == '=')
38169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return LSHIFT_E;
38269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else {
38369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            ungetc(c3);
38469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return LSHIFT;
38569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        }
38669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    case '>' :
38769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        c3 = getc();
38869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        if (c3 == '=')
38969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return RSHIFT_E;
39069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else if (c3 == '>') {
39169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            c3 = getc();
39269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            if (c3 == '=')
39369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                return ARSHIFT_E;
39469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            else {
39569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                ungetc(c3);
39669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                                return ARSHIFT;
39769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            }
39869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        }
39969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        else {
40069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            ungetc(c3);
40169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                            return RSHIFT;
40269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        }
40369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    default :
40469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                        break;
40569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    }
40669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                else if (c2 == '=')
40769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    return t;
40869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            }
40969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
41069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == '^') {
41169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c2 = getc();
41269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c2 == '=')
41369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return EXOR_E;
41469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
41569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else if (c == '|') {
41669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c2 = getc();
41769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (c2 == '=')
41869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return OR_E;
41969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else if (c2 == '|')
42069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return OROR;
42169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
42269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else
42369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return c;
42469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
42569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ungetc(c2);
42669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return c;
42769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
42869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
42969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int readIdentifier(int c, Token token) {
43069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        StringBuffer tbuf = textBuffer;
43169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        tbuf.setLength(0);
43269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
43369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        do {
43469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            tbuf.append((char)c);
43569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            c = getc();
43669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        } while (Character.isJavaIdentifierPart((char)c));
43769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
43869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ungetc(c);
43969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
44069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        String name = tbuf.toString();
44169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int t = ktable.lookup(name);
44269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (t >= 0)
44369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return t;
44469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else {
44569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            /* tbuf.toString() is executed quickly since it does not
44669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             * need memory copy.  Using a hand-written extensible
44769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             * byte-array class instead of StringBuffer is not a good idea
44869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             * for execution speed.  Converting a byte array to a String
44969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             * object is very slow.  Using an extensible char array
45069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             * might be OK.
45169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal             */
45269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            token.textValue = name;
45369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return Identifier;
45469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
45569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
45669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
45769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private static final KeywordTable ktable = new KeywordTable();
45869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
45969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    static {
46069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("abstract", ABSTRACT);
46169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("boolean", BOOLEAN);
46269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("break", BREAK);
46369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("byte", BYTE);
46469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("case", CASE);
46569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("catch", CATCH);
46669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("char", CHAR);
46769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("class", CLASS);
46869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("const", CONST);
46969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("continue", CONTINUE);
47069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("default", DEFAULT);
47169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("do", DO);
47269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("double", DOUBLE);
47369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("else", ELSE);
47469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("extends", EXTENDS);
47569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("false", FALSE);
47669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("final", FINAL);
47769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("finally", FINALLY);
47869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("float", FLOAT);
47969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("for", FOR);
48069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("goto", GOTO);
48169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("if", IF);
48269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("implements", IMPLEMENTS);
48369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("import", IMPORT);
48469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("instanceof", INSTANCEOF);
48569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("int", INT);
48669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("interface", INTERFACE);
48769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("long", LONG);
48869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("native", NATIVE);
48969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("new", NEW);
49069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("null", NULL);
49169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("package", PACKAGE);
49269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("private", PRIVATE);
49369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("protected", PROTECTED);
49469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("public", PUBLIC);
49569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("return", RETURN);
49669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("short", SHORT);
49769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("static", STATIC);
49869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("strictfp", STRICT);
49969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("super", SUPER);
50069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("switch", SWITCH);
50169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("synchronized", SYNCHRONIZED);
50269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("this", THIS);
50369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("throw", THROW);
50469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("throws", THROWS);
50569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("transient", TRANSIENT);
50669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("true", TRUE);
50769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("try", TRY);
50869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("void", VOID);
50969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("volatile", VOLATILE);
51069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        ktable.append("while", WHILE);
51169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
51269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
51369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private static boolean isBlank(int c) {
51469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return c == ' ' || c == '\t' || c == '\f' || c == '\r'
51569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            || c == '\n';
51669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
51769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
51869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private static boolean isDigit(int c) {
51969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return '0' <= c && c <= '9';
52069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
52169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
52269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private void ungetc(int c) {
52369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        lastChar = c;
52469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
52569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
52669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String getTextAround() {
52769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int begin = position - 10;
52869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (begin < 0)
52969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            begin = 0;
53069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
53169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int end = position + 10;
53269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (end > maxlen)
53369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            end = maxlen;
53469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
53569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return input.substring(begin, end);
53669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
53769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
53869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int getc() {
53969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (lastChar < 0)
54069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            if (position < maxlen)
54169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return input.charAt(position++);
54269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            else
54369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                return -1;
54469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        else {
54569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            int c = lastChar;
54669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            lastChar = -1;
54769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return c;
54869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
54969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
55069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
551