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

📄 scanner.java

📁 非常好的编译源代码 将一个l语言转换为中间代码 java版本
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   */
  public final void yyclose() throws java.io.IOException {
    zzAtEOF = true;            /* indicate end of file */
    zzEndRead = zzStartRead;  /* invalidate buffer    */

    if (zzReader != null)
      zzReader.close();
  }


  /**
   * Resets the scanner to read from a new input stream.
   * Does not close the old reader.
   *
   * All internal variables are reset, the old input stream 
   * <b>cannot</b> be reused (internal buffer is discarded and lost).
   * Lexical state is set to <tt>ZZ_INITIAL</tt>.
   *
   * @param reader   the new input stream 
   */
  public final void yyreset(java.io.Reader reader) {
    zzReader = reader;
    zzAtBOL  = true;
    zzAtEOF  = false;
    zzEndRead = zzStartRead = 0;
    zzCurrentPos = zzMarkedPos = zzPushbackPos = 0;
    yyline = yychar = yycolumn = 0;
    zzLexicalState = YYINITIAL;
  }


  /**
   * Returns the current lexical state.
   */
  public final int yystate() {
    return zzLexicalState;
  }


  /**
   * Enters a new lexical state
   *
   * @param newState the new lexical state
   */
  public final void yybegin(int newState) {
    zzLexicalState = newState;
  }


  /**
   * Returns the text matched by the current regular expression.
   */
  public final String yytext() {
    return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
  }


  /**
   * Returns the character at position <tt>pos</tt> from the 
   * matched text. 
   * 
   * It is equivalent to yytext().charAt(pos), but faster
   *
   * @param pos the position of the character to fetch. 
   *            A value from 0 to yylength()-1.
   *
   * @return the character at position pos
   */
  public final char yycharat(int pos) {
    return zzBuffer[zzStartRead+pos];
  }


  /**
   * Returns the length of the matched text region.
   */
  public final int yylength() {
    return zzMarkedPos-zzStartRead;
  }


  /**
   * Reports an error that occured while scanning.
   *
   * In a wellformed scanner (no or only correct usage of 
   * yypushback(int) and a match-all fallback rule) this method 
   * will only be called with things that "Can't Possibly Happen".
   * If this method is called, something is seriously wrong
   * (e.g. a JFlex bug producing a faulty scanner etc.).
   *
   * Usual syntax/scanner level error handling should be done
   * in error fallback rules.
   *
   * @param   errorCode  the code of the errormessage to display
   */
  private void zzScanError(int errorCode) {
    String message;
    try {
      message = ZZ_ERROR_MSG[errorCode];
    }
    catch (ArrayIndexOutOfBoundsException e) {
      message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
    }

    throw new Error(message);
  } 


  /**
   * Pushes the specified amount of characters back into the input stream.
   *
   * They will be read again by then next call of the scanning method
   *
   * @param number  the number of characters to be read again.
   *                This number must not be greater than yylength()!
   */
  public void yypushback(int number)  {
    if ( number > yylength() )
      zzScanError(ZZ_PUSHBACK_2BIG);

    zzMarkedPos -= number;
  }


  /**
   * Contains user EOF-code, which will be executed exactly once,
   * when the end of file is reached
   */
  private void zzDoEOF() throws java.io.IOException {
    if (!zzEOFDone) {
      zzEOFDone = true;
      yyclose();
    }
  }


  /**
   * Resumes scanning until the next regular expression is matched,
   * the end of input is encountered or an I/O-Error occurs.
   *
   * @return      the next token
   * @exception   java.io.IOException  if any I/O-Error occurs
   */
  public java_cup.runtime.Symbol next_token() throws java.io.IOException {
    int zzInput;
    int zzAction;

    // cached fields:
    int zzCurrentPosL;
    int zzMarkedPosL;
    int zzEndReadL = zzEndRead;
    char [] zzBufferL = zzBuffer;
    char [] zzCMapL = ZZ_CMAP;

    int [] zzTransL = ZZ_TRANS;
    int [] zzRowMapL = ZZ_ROWMAP;
    int [] zzAttrL = ZZ_ATTRIBUTE;

    while (true) {
      zzMarkedPosL = zzMarkedPos;

      boolean zzR = false;
      for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL;
                                                             zzCurrentPosL++) {
        switch (zzBufferL[zzCurrentPosL]) {
        case '\u000B':
        case '\u000C':
        case '\u0085':
        case '\u2028':
        case '\u2029':
          yyline++;
          yycolumn = 0;
          zzR = false;
          break;
        case '\r':
          yyline++;
          yycolumn = 0;
          zzR = true;
          break;
        case '\n':
          if (zzR)
            zzR = false;
          else {
            yyline++;
            yycolumn = 0;
          }
          break;
        default:
          zzR = false;
          yycolumn++;
        }
      }

      if (zzR) {
        // peek one character ahead if it is \n (if we have counted one line too much)
        boolean zzPeek;
        if (zzMarkedPosL < zzEndReadL)
          zzPeek = zzBufferL[zzMarkedPosL] == '\n';
        else if (zzAtEOF)
          zzPeek = false;
        else {
          boolean eof = zzRefill();
          zzEndReadL = zzEndRead;
          zzMarkedPosL = zzMarkedPos;
          zzBufferL = zzBuffer;
          if (eof) 
            zzPeek = false;
          else 
            zzPeek = zzBufferL[zzMarkedPosL] == '\n';
        }
        if (zzPeek) yyline--;
      }
      zzAction = -1;

      zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
  
      zzState = zzLexicalState;


      zzForAction: {
        while (true) {
    
          if (zzCurrentPosL < zzEndReadL)
            zzInput = zzBufferL[zzCurrentPosL++];
          else if (zzAtEOF) {
            zzInput = YYEOF;
            break zzForAction;
          }
          else {
            // store back cached positions
            zzCurrentPos  = zzCurrentPosL;
            zzMarkedPos   = zzMarkedPosL;
            boolean eof = zzRefill();
            // get translated positions and possibly new buffer
            zzCurrentPosL  = zzCurrentPos;
            zzMarkedPosL   = zzMarkedPos;
            zzBufferL      = zzBuffer;
            zzEndReadL     = zzEndRead;
            if (eof) {
              zzInput = YYEOF;
              break zzForAction;
            }
            else {
              zzInput = zzBufferL[zzCurrentPosL++];
            }
          }
          int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
          if (zzNext == -1) break zzForAction;
          zzState = zzNext;

          int zzAttributes = zzAttrL[zzState];
          if ( (zzAttributes & 1) == 1 ) {
            zzAction = zzState;
            zzMarkedPosL = zzCurrentPosL;
            if ( (zzAttributes & 8) == 8 ) break zzForAction;
          }

        }
      }

      // store back cached position
      zzMarkedPos = zzMarkedPosL;

      switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
        case 73: 
          { return symbol(END);
          }
        case 120: break;
        case 49: 
          { return symbol(GTEQ);
          }
        case 121: break;
        case 28: 
          { return symbol(XOR);
          }
        case 122: break;
        case 21: 
          { return symbol(GT);
          }
        case 123: break;
        case 52: 
          { return symbol(NOTEQ);
          }
        case 124: break;
        case 114: 
          { return symbol(PROGRAM);
          }
        case 125: break;
        case 94: 
          { return symbol(BYTE);
          }
        case 126: break;
        case 9: 
          { yybegin(STRING); string.setLength(0);
          }
        case 127: break;
        case 13: 
          { return symbol(LBRACE);
          }
        case 128: break;
        case 19: 
          { return symbol(EQ);
          }
        case 129: break;
        case 41: 
          { return symbol(MINUSMINUS);
          }
        case 130: break;
        case 118: 
          { return symbol(CONTINUE);
          }
        case 131: break;
        case 40: 
          { return symbol(FLOATING_POINT_LITERAL, new Double(yytext().substring(0,yylength()-1)));
          }
        case 132: break;
        case 45: 
          { return symbol(DO);
          }
        case 133: break;
        case 55: 
          { return symbol(PLUSPLUS);
          }
        case 134: break;
        case 119: 
          { return symbol(PROCEDURE);
          }
        case 135: break;
        case 22: 
          { return symbol(LT);
          }
        case 136: break;
        case 56: 
          { return symbol(ANDEQ);
          }
        case 137: break;
        case 66: 
          { string.append( '\t' );
          }
        case 138: break;
        case 59: 
          { return symbol(MODEQ);
          }
        case 139: break;
        case 83: 
          { yybegin(YYINITIAL); return symbol(CHARACTER_LITERAL, new Character('\t'));
          }
        case 140: break;
        case 115: 
          { return symbol(BOOLEAN);
          }
        case 141: break;
        case 105: 
          { return symbol(SHORT);
          }
        case 142: break;
        case 103: 
          { return symbol(BEGIN);
          }
        case 143: break;
        case 10: 
          { yybegin(CHARLITERAL);
          }
        case 144: break;
        case 47: 
          { return symbol(EQEQ);
          }
        case 145: break;
        case 39: 
          { return symbol(FLOATING_POINT_LITERAL, new Float(yytext().substring(0,yylength()-1)));
          }
        case 146: break;
        case 95: 
          { return symbol(LONG);
          }
        case 147: break;
        case 92: 
          { return symbol(BOOLEAN_LITERAL, new Boolean(true));
          }
        case 148: break;
        case 27: 
          { return symbol(OR);
          }
        case 149: break;
        case 25: 
          { return symbol(PLUS);
          }
        case 150: break;
        case 96: 
          { return symbol(CALL);
          }
        case 151: break;
        case 68: 
          { string.append( '\n' );
          }
        case 152: break;
        case 12: 
          { return symbol(RPAREN);
          }
        case 153: break;
        case 104: 
          { return symbol(CONST);
          }
        case 154: break;
        case 85: 
          { yybegin(YYINITIAL); return symbol(CHARACTER_LITERAL, new Character('\n'));
          }
        case 155: break;
        case 50: 
          { return symbol(RSHIFT);
          }
        case 156: break;
        case 35: 
          { return symbol(MULTEQ);
          }
        case 157: break;

⌨️ 快捷键说明

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