home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / StreamTokenizer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  5.6 KB  |  445 lines

  1. package java.io;
  2.  
  3. public class StreamTokenizer {
  4.    private Reader reader;
  5.    private InputStream input;
  6.    private char[] buf;
  7.    private int peekc;
  8.    private boolean pushedBack;
  9.    private boolean forceLower;
  10.    private int LINENO;
  11.    private boolean eolIsSignificantP;
  12.    private boolean slashSlashCommentsP;
  13.    private boolean slashStarCommentsP;
  14.    private byte[] ctype;
  15.    private static final byte CT_WHITESPACE = 1;
  16.    private static final byte CT_DIGIT = 2;
  17.    private static final byte CT_ALPHA = 4;
  18.    private static final byte CT_QUOTE = 8;
  19.    private static final byte CT_COMMENT = 16;
  20.    public int ttype;
  21.    public static final int TT_EOF = -1;
  22.    public static final int TT_EOL = 10;
  23.    public static final int TT_NUMBER = -2;
  24.    public static final int TT_WORD = -3;
  25.    private static final int TT_NOTHING = -4;
  26.    public String sval;
  27.    public double nval;
  28.  
  29.    private StreamTokenizer() {
  30.       this.buf = new char[20];
  31.       this.LINENO = 1;
  32.       this.eolIsSignificantP = false;
  33.       this.slashSlashCommentsP = false;
  34.       this.slashStarCommentsP = false;
  35.       this.ctype = new byte[256];
  36.       this.ttype = -4;
  37.       this.wordChars(97, 122);
  38.       this.wordChars(65, 90);
  39.       this.wordChars(160, 255);
  40.       this.whitespaceChars(0, 32);
  41.       this.commentChar(47);
  42.       this.quoteChar(34);
  43.       this.quoteChar(39);
  44.       this.parseNumbers();
  45.    }
  46.  
  47.    /** @deprecated */
  48.    public StreamTokenizer(InputStream var1) {
  49.       this();
  50.       this.input = var1;
  51.    }
  52.  
  53.    public StreamTokenizer(Reader var1) {
  54.       this();
  55.       this.reader = var1;
  56.    }
  57.  
  58.    public void resetSyntax() {
  59.       int var1 = this.ctype.length;
  60.  
  61.       while(true) {
  62.          --var1;
  63.          if (var1 < 0) {
  64.             return;
  65.          }
  66.  
  67.          this.ctype[var1] = 0;
  68.       }
  69.    }
  70.  
  71.    public void wordChars(int var1, int var2) {
  72.       if (var1 < 0) {
  73.          var1 = 0;
  74.       }
  75.  
  76.       if (var2 >= this.ctype.length) {
  77.          var2 = this.ctype.length - 1;
  78.       }
  79.  
  80.       while(var1 <= var2) {
  81.          byte[] var10000 = this.ctype;
  82.          int var10001 = var1++;
  83.          var10000[var10001] = (byte)(var10000[var10001] | 4);
  84.       }
  85.  
  86.    }
  87.  
  88.    public void whitespaceChars(int var1, int var2) {
  89.       if (var1 < 0) {
  90.          var1 = 0;
  91.       }
  92.  
  93.       if (var2 >= this.ctype.length) {
  94.          var2 = this.ctype.length - 1;
  95.       }
  96.  
  97.       while(var1 <= var2) {
  98.          this.ctype[var1++] = 1;
  99.       }
  100.  
  101.    }
  102.  
  103.    public void ordinaryChars(int var1, int var2) {
  104.       if (var1 < 0) {
  105.          var1 = 0;
  106.       }
  107.  
  108.       if (var2 >= this.ctype.length) {
  109.          var2 = this.ctype.length - 1;
  110.       }
  111.  
  112.       while(var1 <= var2) {
  113.          this.ctype[var1++] = 0;
  114.       }
  115.  
  116.    }
  117.  
  118.    public void ordinaryChar(int var1) {
  119.       if (var1 >= 0 && var1 < this.ctype.length) {
  120.          this.ctype[var1] = 0;
  121.       }
  122.  
  123.    }
  124.  
  125.    public void commentChar(int var1) {
  126.       if (var1 >= 0 && var1 < this.ctype.length) {
  127.          this.ctype[var1] = 16;
  128.       }
  129.  
  130.    }
  131.  
  132.    public void quoteChar(int var1) {
  133.       if (var1 >= 0 && var1 < this.ctype.length) {
  134.          this.ctype[var1] = 8;
  135.       }
  136.  
  137.    }
  138.  
  139.    public void parseNumbers() {
  140.       for(int var1 = 48; var1 <= 57; ++var1) {
  141.          byte[] var10000 = this.ctype;
  142.          var10000[var1] = (byte)(var10000[var1] | 2);
  143.       }
  144.  
  145.       byte[] var2 = this.ctype;
  146.       var2[46] = (byte)(var2[46] | 2);
  147.       var2 = this.ctype;
  148.       var2[45] = (byte)(var2[45] | 2);
  149.    }
  150.  
  151.    public void eolIsSignificant(boolean var1) {
  152.       this.eolIsSignificantP = var1;
  153.    }
  154.  
  155.    public void slashStarComments(boolean var1) {
  156.       this.slashStarCommentsP = var1;
  157.    }
  158.  
  159.    public void slashSlashComments(boolean var1) {
  160.       this.slashSlashCommentsP = var1;
  161.    }
  162.  
  163.    public void lowerCaseMode(boolean var1) {
  164.       this.forceLower = var1;
  165.    }
  166.  
  167.    private int read() throws IOException {
  168.       if (this.reader != null) {
  169.          return this.reader.read();
  170.       } else if (this.input != null) {
  171.          return this.input.read();
  172.       } else {
  173.          throw new IllegalStateException();
  174.       }
  175.    }
  176.  
  177.    public int nextToken() throws IOException {
  178.       if (this.pushedBack) {
  179.          this.pushedBack = false;
  180.          return this.ttype;
  181.       } else {
  182.          byte[] var1 = this.ctype;
  183.          this.sval = null;
  184.          int var2;
  185.          if (this.ttype == -4) {
  186.             var2 = this.read();
  187.             if (var2 >= 0) {
  188.                this.ttype = var2;
  189.             }
  190.          } else {
  191.             var2 = this.peekc;
  192.          }
  193.  
  194.          if (var2 < 0) {
  195.             return this.ttype = -1;
  196.          } else {
  197.             byte var3;
  198.             for(var3 = var2 < 256 ? var1[var2] : 4; (var3 & 1) != 0; var3 = var2 < 256 ? var1[var2] : 4) {
  199.                if (var2 == 13) {
  200.                   ++this.LINENO;
  201.                   var2 = this.read();
  202.                   if (var2 == 10) {
  203.                      var2 = this.read();
  204.                   }
  205.  
  206.                   if (this.eolIsSignificantP) {
  207.                      this.peekc = var2;
  208.                      return this.ttype = 10;
  209.                   }
  210.                } else {
  211.                   if (var2 == 10) {
  212.                      ++this.LINENO;
  213.                      if (this.eolIsSignificantP) {
  214.                         this.peekc = this.read();
  215.                         return this.ttype = 10;
  216.                      }
  217.                   }
  218.  
  219.                   var2 = this.read();
  220.                }
  221.  
  222.                if (var2 < 0) {
  223.                   return this.ttype = -1;
  224.                }
  225.             }
  226.  
  227.             if ((var3 & 2) != 0) {
  228.                boolean var19 = false;
  229.                if (var2 == 45) {
  230.                   var2 = this.read();
  231.                   if (var2 != 46 && (var2 < 48 || var2 > 57)) {
  232.                      this.peekc = var2;
  233.                      return this.ttype = 45;
  234.                   }
  235.  
  236.                   var19 = true;
  237.                }
  238.  
  239.                double var22 = (double)0.0F;
  240.                int var7 = 0;
  241.                byte var8 = 0;
  242.  
  243.                while(true) {
  244.                   if (var2 == 46 && var8 == 0) {
  245.                      var8 = 1;
  246.                   } else {
  247.                      if (var2 < 48 || var2 > 57) {
  248.                         this.peekc = var2;
  249.                         if (var7 != 0) {
  250.                            double var9 = (double)10.0F;
  251.                            --var7;
  252.  
  253.                            while(var7 > 0) {
  254.                               var9 *= (double)10.0F;
  255.                               --var7;
  256.                            }
  257.  
  258.                            var22 /= var9;
  259.                         }
  260.  
  261.                         this.nval = var19 ? -var22 : var22;
  262.                         return this.ttype = -2;
  263.                      }
  264.  
  265.                      var22 = var22 * (double)10.0F + (double)(var2 - 48);
  266.                      var7 += var8;
  267.                   }
  268.  
  269.                   var2 = this.read();
  270.                }
  271.             } else if ((var3 & 4) != 0) {
  272.                int var18 = 0;
  273.  
  274.                do {
  275.                   if (var18 >= this.buf.length) {
  276.                      char[] var21 = new char[this.buf.length * 2];
  277.                      System.arraycopy(this.buf, 0, var21, 0, this.buf.length);
  278.                      this.buf = var21;
  279.                   }
  280.  
  281.                   this.buf[var18++] = (char)var2;
  282.                   var2 = this.read();
  283.                   var3 = var2 < 0 ? 1 : (var2 < 256 ? var1[var2] : 4);
  284.                } while((var3 & 6) != 0);
  285.  
  286.                this.peekc = var2;
  287.                this.sval = String.copyValueOf(this.buf, 0, var18);
  288.                if (this.forceLower) {
  289.                   this.sval = this.sval.toLowerCase();
  290.                }
  291.  
  292.                return this.ttype = -3;
  293.             } else if ((var3 & 16) != 0) {
  294.                while((var2 = this.read()) != 10 && var2 != 13 && var2 >= 0) {
  295.                }
  296.  
  297.                this.peekc = var2;
  298.                return this.nextToken();
  299.             } else if ((var3 & 8) != 0) {
  300.                this.ttype = var2;
  301.                int var17 = 0;
  302.  
  303.                for(this.peekc = this.read(); this.peekc >= 0 && this.peekc != this.ttype && this.peekc != 10 && this.peekc != 13; this.buf[var17++] = (char)var2) {
  304.                   if (this.peekc == 92) {
  305.                      var2 = this.read();
  306.                      int var5 = var2;
  307.                      if (var2 >= 48 && var2 <= 55) {
  308.                         var2 -= 48;
  309.                         int var6 = this.read();
  310.                         if (var6 >= 48 && var6 <= 55) {
  311.                            var2 = (var2 << 3) + (var6 - 48);
  312.                            var6 = this.read();
  313.                            if (var6 >= 48 && var6 <= 55 && var5 <= 51) {
  314.                               var2 = (var2 << 3) + (var6 - 48);
  315.                               this.peekc = this.read();
  316.                            } else {
  317.                               this.peekc = var6;
  318.                            }
  319.                         } else {
  320.                            this.peekc = var6;
  321.                         }
  322.                      } else {
  323.                         switch (var2) {
  324.                            case 97:
  325.                               var2 = 7;
  326.                               break;
  327.                            case 98:
  328.                               var2 = 8;
  329.                               break;
  330.                            case 102:
  331.                               var2 = 12;
  332.                               break;
  333.                            case 110:
  334.                               var2 = 10;
  335.                               break;
  336.                            case 114:
  337.                               var2 = 13;
  338.                               break;
  339.                            case 116:
  340.                               var2 = 9;
  341.                               break;
  342.                            case 118:
  343.                               var2 = 11;
  344.                         }
  345.  
  346.                         this.peekc = this.read();
  347.                      }
  348.                   } else {
  349.                      var2 = this.peekc;
  350.                      this.peekc = this.read();
  351.                   }
  352.  
  353.                   if (var17 >= this.buf.length) {
  354.                      char[] var20 = new char[this.buf.length * 2];
  355.                      System.arraycopy(this.buf, 0, var20, 0, this.buf.length);
  356.                      this.buf = var20;
  357.                   }
  358.                }
  359.  
  360.                if (this.peekc == this.ttype) {
  361.                   this.peekc = this.read();
  362.                }
  363.  
  364.                this.sval = String.copyValueOf(this.buf, 0, var17);
  365.                return this.ttype;
  366.             } else if (var2 == 47 && (this.slashSlashCommentsP || this.slashStarCommentsP)) {
  367.                var2 = this.read();
  368.                if (var2 == 42 && this.slashStarCommentsP) {
  369.                   for(int var4 = 0; (var2 = this.read()) != 47 || var4 != 42; var4 = var2) {
  370.                      if (var2 == 13) {
  371.                         ++this.LINENO;
  372.                         var2 = this.read();
  373.                         if (var2 == 10) {
  374.                            var2 = this.read();
  375.                         }
  376.                      } else if (var2 == 10) {
  377.                         ++this.LINENO;
  378.                         var2 = this.read();
  379.                      }
  380.  
  381.                      if (var2 < 0) {
  382.                         return this.ttype = -1;
  383.                      }
  384.                   }
  385.  
  386.                   this.peekc = this.read();
  387.                   return this.nextToken();
  388.                } else if (var2 == 47 && this.slashSlashCommentsP) {
  389.                   while((var2 = this.read()) != 10 && var2 != 13 && var2 >= 0) {
  390.                   }
  391.  
  392.                   this.peekc = var2;
  393.                   return this.nextToken();
  394.                } else {
  395.                   this.peekc = var2;
  396.                   return this.ttype = 47;
  397.                }
  398.             } else {
  399.                this.peekc = this.read();
  400.                return this.ttype = var2;
  401.             }
  402.          }
  403.       }
  404.    }
  405.  
  406.    public void pushBack() {
  407.       if (this.ttype != -4) {
  408.          this.pushedBack = true;
  409.       }
  410.  
  411.    }
  412.  
  413.    public int lineno() {
  414.       return this.LINENO;
  415.    }
  416.  
  417.    public String toString() {
  418.       String var1;
  419.       switch (this.ttype) {
  420.          case -4:
  421.             var1 = "NOTHING";
  422.             break;
  423.          case -3:
  424.             var1 = this.sval;
  425.             break;
  426.          case -2:
  427.             var1 = "n=" + this.nval;
  428.             break;
  429.          case -1:
  430.             var1 = "EOF";
  431.             break;
  432.          case 10:
  433.             var1 = "EOL";
  434.             break;
  435.          default:
  436.             char[] var2 = new char[3];
  437.             var2[0] = var2[2] = '\'';
  438.             var2[1] = (char)this.ttype;
  439.             var1 = new String(var2);
  440.       }
  441.  
  442.       return "Token[" + var1 + "], line " + this.LINENO;
  443.    }
  444. }
  445.