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