home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class StreamTokenizer {
- private InputStream input;
- private char[] buf;
- private int peekc = 32;
- private boolean pushedBack;
- private boolean forceLower;
- private int LINENO = 1;
- private boolean eolIsSignificantP = false;
- private boolean slashSlashCommentsP = false;
- private boolean slashStarCommentsP = false;
- private byte[] ctype = new byte[256];
- private static final byte CT_WHITESPACE = 1;
- private static final byte CT_DIGIT = 2;
- private static final byte CT_ALPHA = 4;
- private static final byte CT_QUOTE = 8;
- private static final byte CT_COMMENT = 16;
- public int ttype;
- public static final int TT_EOF = -1;
- public static final int TT_EOL = 10;
- public static final int TT_NUMBER = -2;
- public static final int TT_WORD = -3;
- public String sval;
- public double nval;
-
- public StreamTokenizer(InputStream I) {
- this.input = I;
- this.buf = new char[20];
- this.wordChars(97, 122);
- this.wordChars(65, 90);
- this.wordChars(160, 255);
- this.whitespaceChars(0, 32);
- this.commentChar(47);
- this.quoteChar(34);
- this.quoteChar(39);
- this.parseNumbers();
- }
-
- public void resetSyntax() {
- int i = this.ctype.length;
-
- while(true) {
- --i;
- if (i < 0) {
- return;
- }
-
- this.ctype[i] = 0;
- }
- }
-
- public void wordChars(int low, int hi) {
- if (low < 0) {
- low = 0;
- }
-
- if (hi > this.ctype.length) {
- hi = this.ctype.length;
- }
-
- while(low <= hi) {
- byte[] var10000 = this.ctype;
- int var10001 = low++;
- var10000[var10001] = (byte)(var10000[var10001] | 4);
- }
-
- }
-
- public void whitespaceChars(int low, int hi) {
- if (low < 0) {
- low = 0;
- }
-
- if (hi > this.ctype.length) {
- hi = this.ctype.length;
- }
-
- while(low <= hi) {
- this.ctype[low++] = 1;
- }
-
- }
-
- public void ordinaryChars(int low, int hi) {
- if (low < 0) {
- low = 0;
- }
-
- if (hi > this.ctype.length) {
- hi = this.ctype.length;
- }
-
- while(low <= hi) {
- this.ctype[low++] = 0;
- }
-
- }
-
- public void ordinaryChar(int ch) {
- this.ctype[ch] = 0;
- }
-
- public void commentChar(int ch) {
- this.ctype[ch] = 16;
- }
-
- public void quoteChar(int ch) {
- this.ctype[ch] = 8;
- }
-
- public void parseNumbers() {
- for(int i = 48; i <= 57; ++i) {
- byte[] var10000 = this.ctype;
- var10000[i] = (byte)(var10000[i] | 2);
- }
-
- byte[] var2 = this.ctype;
- var2[46] = (byte)(var2[46] | 2);
- var2 = this.ctype;
- var2[45] = (byte)(var2[45] | 2);
- }
-
- public void eolIsSignificant(boolean flag) {
- this.eolIsSignificantP = flag;
- }
-
- public void slashStarComments(boolean flag) {
- this.slashStarCommentsP = flag;
- }
-
- public void slashSlashComments(boolean flag) {
- this.slashSlashCommentsP = flag;
- }
-
- public void lowerCaseMode(boolean fl) {
- this.forceLower = fl;
- }
-
- public int nextToken() throws IOException {
- if (this.pushedBack) {
- this.pushedBack = false;
- return this.ttype;
- } else {
- InputStream is = this.input;
- byte[] ct = this.ctype;
- int c = this.peekc;
- this.sval = null;
- if (c < 0) {
- return this.ttype = -1;
- } else {
- int ctype;
- for(ctype = c < 256 ? ct[c] : 4; (ctype & 1) != 0; ctype = c < 256 ? ct[c] : 4) {
- if (c == 13) {
- ++this.LINENO;
- c = is.read();
- if (c == 10) {
- c = is.read();
- }
-
- if (this.eolIsSignificantP) {
- this.peekc = c;
- return this.ttype = 10;
- }
- } else {
- if (c == 10) {
- ++this.LINENO;
- if (this.eolIsSignificantP) {
- this.peekc = 32;
- return this.ttype = 10;
- }
- }
-
- c = is.read();
- }
-
- if (c < 0) {
- return this.ttype = -1;
- }
- }
-
- if ((ctype & 2) != 0) {
- boolean neg = false;
- if (c == 45) {
- c = is.read();
- if (c != 46 && (c < 48 || c > 57)) {
- this.peekc = c;
- return this.ttype = 45;
- }
-
- neg = true;
- }
-
- double v = (double)0.0F;
- int decexp = 0;
- int seendot = 0;
-
- while(true) {
- if (c == 46 && seendot == 0) {
- seendot = 1;
- } else {
- if (c < 48 || c > 57) {
- this.peekc = c;
- if (decexp != 0) {
- double denom = (double)10.0F;
- --decexp;
-
- while(decexp > 0) {
- denom *= (double)10.0F;
- --decexp;
- }
-
- v /= denom;
- }
-
- this.nval = neg ? -v : v;
- return this.ttype = -2;
- }
-
- v = v * (double)10.0F + (double)(c - 48);
- decexp += seendot;
- }
-
- c = is.read();
- }
- } else if ((ctype & 4) != 0) {
- int i = 0;
-
- do {
- if (i >= this.buf.length) {
- char[] nb = new char[this.buf.length * 2];
- System.arraycopy(this.buf, 0, nb, 0, this.buf.length);
- this.buf = nb;
- }
-
- this.buf[i++] = (char)c;
- c = is.read();
- ctype = c < 0 ? 1 : (c < 256 ? ct[c] : 4);
- } while((ctype & 6) != 0);
-
- this.peekc = c;
- this.sval = String.copyValueOf(this.buf, 0, i);
- if (this.forceLower) {
- this.sval = this.sval.toLowerCase();
- }
-
- return this.ttype = -3;
- } else if ((ctype & 16) != 0) {
- while((c = is.read()) != 10 && c != 13 && c >= 0) {
- }
-
- this.peekc = c;
- return this.nextToken();
- } else if ((ctype & 8) != 0) {
- this.ttype = c;
-
- int i;
- for(i = 0; (c = is.read()) >= 0 && c != this.ttype && c != 10 && c != 13; this.buf[i++] = (char)c) {
- if (c == 92) {
- switch (c = is.read()) {
- case 98:
- c = 8;
- break;
- case 97:
- c = 7;
- break;
- case 55:
- case 54:
- case 53:
- case 52:
- case 51:
- case 50:
- case 49:
- case 48:
- c -= 48;
- int c2 = is.read();
- if (c2 >= 48 && c2 <= 55) {
- c = (c << 3) + (c2 - 48);
- c2 = is.read();
- if (c2 >= 48 && c2 <= 55) {
- c = (c << 3) + (c2 - 48);
- } else {
- this.peekc = c;
- }
- } else {
- this.peekc = c;
- }
- break;
- case 118:
- c = 11;
- break;
- case 116:
- c = 9;
- break;
- case 114:
- c = 13;
- break;
- case 110:
- c = 10;
- break;
- case 102:
- c = 12;
- }
- }
-
- if (i >= this.buf.length) {
- char[] nb = new char[this.buf.length * 2];
- System.arraycopy(this.buf, 0, nb, 0, this.buf.length);
- this.buf = nb;
- }
- }
-
- this.peekc = 32;
- this.sval = String.copyValueOf(this.buf, 0, i);
- return this.ttype;
- } else if (c == 47 && (this.slashSlashCommentsP || this.slashStarCommentsP)) {
- c = is.read();
- if (c == 42 && this.slashStarCommentsP) {
- for(int prevc = 0; (c = is.read()) != 47 || prevc != 42; prevc = c) {
- if (c == 10) {
- ++this.LINENO;
- }
-
- if (c < 0) {
- return this.ttype = -1;
- }
- }
-
- this.peekc = 32;
- return this.nextToken();
- } else if (c == 47 && this.slashSlashCommentsP) {
- while((c = is.read()) != 10 && c != 13 && c >= 0) {
- }
-
- this.peekc = c;
- return this.nextToken();
- } else {
- this.peekc = c;
- return this.ttype = 47;
- }
- } else {
- this.peekc = 32;
- return this.ttype = c;
- }
- }
- }
- }
-
- public void pushBack() {
- this.pushedBack = true;
- }
-
- public int lineno() {
- return this.LINENO;
- }
-
- public String toString() {
- String ret;
- switch (this.ttype) {
- case -1:
- ret = "EOF";
- break;
- case -2:
- ret = "n=" + this.nval;
- break;
- case -3:
- ret = this.sval;
- break;
- case 10:
- ret = "EOL";
- break;
- default:
- char[] s = new char[3];
- s[0] = s[2] = '\'';
- s[1] = (char)this.ttype;
- ret = new String(s);
- }
-
- return "Token[" + ret + "], line " + this.LINENO;
- }
- }
-