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

📄 mjlexer.java

📁 SkipOOMiniJOOL教学语言的编译器前端
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* The following code was generated by JFlex 1.4.1 on 06-5-15 下午6:36 */

package edu.ustc.cs.minijool.lexer;


/**
 * This class is a scanner generated by 
 * <a href="http://www.jflex.de/">JFlex</a> 1.4.1
 * on 06-5-15 下午6:36 from the specification file
 * <tt>D:/Compiler/design/workspace/Lab2/JFlex/MiniJOOL.lex</tt>
 */
public class MJLexer {

  /** This character denotes the end of file */
  public static final int YYEOF = -1;

  /** initial size of the lookahead buffer */
  private static final int ZZ_BUFFERSIZE = 16384;

  /** lexical states */
  public static final int YYINITIAL = 0;

  /** 
   * Translates characters to character classes
   */
  private static final char [] ZZ_CMAP = {
     0,  0,  0,  0,  0,  0,  0,  0,  0,  2,  2,  0,  2,  2,  0,  0, 
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 
     3, 41,  1,  7,  7, 39, 42, 10, 29, 30, 38, 36, 34, 37, 35,  4, 
     6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  7, 33, 45, 40, 44,  7, 
     7,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5, 
     5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  7,  8,  7,  7,  7, 
     7, 13, 17, 15, 22, 20, 26,  5, 25, 14,  5,  5, 19,  5, 16, 18, 
    28,  5,  9, 11, 12, 27, 21, 24, 23,  5,  5, 31, 43, 32,  7,  0
  };

  /** 
   * Translates DFA states to action switch labels.
   */
  private static final int [] ZZ_ACTION = zzUnpackAction();

  private static final String ZZ_ACTION_PACKED_0 =
    "\1\0\2\1\1\2\1\3\1\4\1\5\14\4\1\6"+
    "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+
    "\1\17\1\20\1\21\1\22\2\1\1\23\1\24\1\25"+
    "\2\0\1\2\1\26\5\4\1\27\12\4\1\30\1\31"+
    "\1\32\1\33\1\34\1\35\1\36\1\37\1\40\1\41"+
    "\1\42\1\43\4\4\1\44\1\4\1\45\10\4\1\46"+
    "\1\47\2\4\1\50\1\51\1\4\1\52\1\4\1\53"+
    "\1\4\1\54\4\4\1\55\2\4\1\56\1\57\1\60"+
    "\1\61\2\4\1\62\1\63";

  private static int [] zzUnpackAction() {
    int [] result = new int[111];
    int offset = 0;
    offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
    return result;
  }

  private static int zzUnpackAction(String packed, int offset, int [] result) {
    int i = 0;       /* index in packed string  */
    int j = offset;  /* index in unpacked array */
    int l = packed.length();
    while (i < l) {
      int count = packed.charAt(i++);
      int value = packed.charAt(i++);
      do result[j++] = value; while (--count > 0);
    }
    return j;
  }


  /** 
   * Translates a state to a row index in the transition table
   */
  private static final int [] ZZ_ROWMAP = zzUnpackRowMap();

  private static final String ZZ_ROWMAP_PACKED_0 =
    "\0\0\0\56\0\134\0\56\0\212\0\270\0\346\0\u0114"+
    "\0\u0142\0\u0170\0\u019e\0\u01cc\0\u01fa\0\u0228\0\u0256\0\u0284"+
    "\0\u02b2\0\u02e0\0\u030e\0\56\0\56\0\56\0\56\0\56"+
    "\0\56\0\56\0\u033c\0\u036a\0\u0398\0\u03c6\0\u03f4\0\u0422"+
    "\0\u0450\0\u047e\0\u04ac\0\u04da\0\56\0\134\0\u0508\0\u0536"+
    "\0\56\0\u0564\0\u0592\0\u05c0\0\u05ee\0\u061c\0\270\0\u064a"+
    "\0\u0678\0\u06a6\0\u06d4\0\u0702\0\u0730\0\u075e\0\u078c\0\u07ba"+
    "\0\u07e8\0\56\0\56\0\56\0\56\0\56\0\56\0\56"+
    "\0\56\0\56\0\u0816\0\56\0\u0844\0\u0872\0\u08a0\0\u08ce"+
    "\0\u08fc\0\270\0\u092a\0\270\0\u0958\0\u0986\0\u09b4\0\u09e2"+
    "\0\u0a10\0\u0a3e\0\u0a6c\0\u0a9a\0\56\0\56\0\u0ac8\0\u0af6"+
    "\0\270\0\270\0\u0b24\0\270\0\u0b52\0\270\0\u0b80\0\270"+
    "\0\u0bae\0\u0bdc\0\u0c0a\0\u0c38\0\270\0\u0c66\0\u0c94\0\270"+
    "\0\270\0\270\0\270\0\u0cc2\0\u0cf0\0\270\0\270";

  private static int [] zzUnpackRowMap() {
    int [] result = new int[111];
    int offset = 0;
    offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
    return result;
  }

  private static int zzUnpackRowMap(String packed, int offset, int [] result) {
    int i = 0;  /* index in packed string  */
    int j = offset;  /* index in unpacked array */
    int l = packed.length();
    while (i < l) {
      int high = packed.charAt(i++) << 16;
      result[j++] = high | packed.charAt(i++);
    }
    return j;
  }

  /** 
   * The transition table of the DFA
   */
  private static final int [] ZZ_TRANS = zzUnpackTrans();

  private static final String ZZ_TRANS_PACKED_0 =
    "\1\2\1\3\2\4\1\5\1\6\1\7\2\2\1\10"+
    "\1\2\1\11\1\12\1\6\1\13\1\14\1\15\1\16"+
    "\2\6\1\17\1\20\2\6\1\21\1\6\1\22\1\6"+
    "\1\23\1\24\1\25\1\26\1\27\1\30\1\31\1\32"+
    "\1\33\1\34\1\35\1\36\1\37\1\40\1\41\1\42"+
    "\1\43\1\44\57\0\1\45\1\0\5\46\1\47\45\46"+
    "\4\0\1\50\43\0\1\51\12\0\2\6\2\0\1\6"+
    "\1\0\22\6\27\0\1\7\54\0\2\6\2\0\1\6"+
    "\1\0\11\6\1\52\10\6\26\0\2\6\2\0\1\6"+
    "\1\0\1\6\1\53\20\6\26\0\2\6\2\0\1\54"+
    "\1\0\16\6\1\55\3\6\26\0\2\6\2\0\1\6"+
    "\1\0\5\6\1\56\11\6\1\57\2\6\26\0\2\6"+
    "\2\0\1\6\1\0\10\6\1\60\11\6\26\0\2\6"+
    "\2\0\1\6\1\0\11\6\1\61\6\6\1\62\1\6"+
    "\26\0\2\6\2\0\1\6\1\0\7\6\1\63\12\6"+
    "\26\0\2\6\2\0\1\6\1\0\10\6\1\64\3\6"+
    "\1\65\5\6\26\0\2\6\2\0\1\6\1\0\7\6"+
    "\1\66\12\6\26\0\2\6\2\0\1\6\1\0\16\6"+
    "\1\67\3\6\26\0\2\6\2\0\1\6\1\0\2\6"+
    "\1\70\17\6\26\0\2\6\2\0\1\71\1\0\22\6"+
    "\71\0\1\72\55\0\1\73\55\0\1\74\55\0\1\75"+
    "\55\0\1\76\55\0\1\77\57\0\1\100\56\0\1\101"+
    "\52\0\1\102\3\0\1\103\51\0\1\104\4\0\1\105"+
    "\1\0\1\46\6\0\3\46\1\0\1\46\3\0\1\46"+
    "\11\0\1\46\24\0\1\50\1\0\53\50\5\0\2\6"+
    "\2\0\1\6\1\0\1\6\1\106\20\6\26\0\2\6"+
    "\2\0\1\6\1\0\2\6\1\107\17\6\26\0\2\6"+
    "\2\0\1\6\1\0\20\6\1\110\1\6\26\0\2\6"+
    "\2\0\1\6\1\0\3\6\1\111\16\6\26\0\2\6"+
    "\2\0\1\6\1\0\1\6\1\112\20\6\26\0\2\6"+
    "\2\0\1\6\1\0\2\6\1\113\17\6\26\0\2\6"+
    "\2\0\1\6\1\0\15\6\1\114\4\6\26\0\2\6"+
    "\2\0\1\6\1\0\10\6\1\115\11\6\26\0\2\6"+
    "\2\0\1\6\1\0\7\6\1\116\12\6\26\0\2\6"+
    "\2\0\1\6\1\0\1\117\21\6\26\0\2\6\2\0"+
    "\1\6\1\0\1\6\1\120\20\6\26\0\2\6\2\0"+
    "\1\6\1\0\3\6\1\121\16\6\26\0\2\6\2\0"+
    "\1\6\1\0\3\6\1\122\16\6\26\0\2\6\2\0"+
    "\1\6\1\0\10\6\1\123\11\6\26\0\2\6\2\0"+
    "\1\6\1\0\3\6\1\124\16\6\71\0\1\125\55\0"+
    "\1\126\12\0\2\6\2\0\1\6\1\0\20\6\1\127"+
    "\1\6\26\0\2\6\2\0\1\6\1\0\1\6\1\130"+
    "\20\6\26\0\2\6\2\0\1\6\1\0\11\6\1\131"+
    "\10\6\26\0\2\6\2\0\1\6\1\0\1\132\21\6"+
    "\26\0\2\6\2\0\1\6\1\0\1\133\21\6\26\0"+
    "\2\6\2\0\1\6\1\0\10\6\1\134\11\6\26\0"+
    "\2\6\2\0\1\6\1\0\10\6\1\135\11\6\26\0"+
    "\2\6\2\0\1\6\1\0\11\6\1\136\10\6\26\0"+
    "\2\6\2\0\1\6\1\0\11\6\1\137\10\6\26\0"+
    "\2\6\2\0\1\6\1\0\13\6\1\140\6\6\26\0"+
    "\2\6\2\0\1\6\1\0\10\6\1\141\11\6\26\0"+
    "\2\6\2\0\1\6\1\0\1\110\21\6\26\0\2\6"+
    "\2\0\1\6\1\0\5\6\1\142\14\6\26\0\2\6"+
    "\2\0\1\143\1\0\22\6\26\0\2\6\2\0\1\6"+
    "\1\0\3\6\1\144\16\6\26\0\2\6\2\0\1\6"+
    "\1\0\1\145\21\6\26\0\2\6\2\0\1\6\1\0"+
    "\11\6\1\146\10\6\26\0\2\6\2\0\1\6\1\0"+
    "\5\6\1\147\14\6\26\0\2\6\2\0\1\6\1\0"+
    "\11\6\1\150\10\6\26\0\2\6\2\0\1\6\1\0"+
    "\1\6\1\151\20\6\26\0\2\6\2\0\1\6\1\0"+
    "\5\6\1\152\14\6\26\0\2\6\2\0\1\6\1\0"+
    "\4\6\1\153\15\6\26\0\2\6\2\0\1\6\1\0"+
    "\2\6\1\154\17\6\26\0\2\6\2\0\1\6\1\0"+
    "\13\6\1\155\6\6\26\0\2\6\2\0\1\6\1\0"+
    "\5\6\1\156\14\6\26\0\2\6\2\0\1\6\1\0"+
    "\1\157\21\6\21\0";

  private static int [] zzUnpackTrans() {
    int [] result = new int[3358];
    int offset = 0;
    offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
    return result;
  }

  private static int zzUnpackTrans(String packed, int offset, int [] result) {
    int i = 0;       /* index in packed string  */
    int j = offset;  /* index in unpacked array */
    int l = packed.length();
    while (i < l) {
      int count = packed.charAt(i++);
      int value = packed.charAt(i++);
      value--;
      do result[j++] = value; while (--count > 0);
    }
    return j;
  }


  /* error codes */
  private static final int ZZ_UNKNOWN_ERROR = 0;
  private static final int ZZ_NO_MATCH = 1;
  private static final int ZZ_PUSHBACK_2BIG = 2;

  /* error messages for the codes above */
  private static final String ZZ_ERROR_MSG[] = {
    "Unkown internal scanner error",
    "Error: could not match input",
    "Error: pushback value was too large"
  };

  /**
   * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
   */
  private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();

  private static final String ZZ_ATTRIBUTE_PACKED_0 =
    "\1\0\1\11\1\1\1\11\17\1\7\11\12\1\1\11"+
    "\2\0\1\1\1\11\20\1\11\11\1\1\1\11\20\1"+
    "\2\11\31\1";

  private static int [] zzUnpackAttribute() {
    int [] result = new int[111];
    int offset = 0;
    offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
    return result;
  }

  private static int zzUnpackAttribute(String packed, int offset, int [] result) {
    int i = 0;       /* index in packed string  */
    int j = offset;  /* index in unpacked array */
    int l = packed.length();
    while (i < l) {
      int count = packed.charAt(i++);
      int value = packed.charAt(i++);
      do result[j++] = value; while (--count > 0);
    }
    return j;
  }

  /** the input device */
  private java.io.Reader zzReader;

  /** the current state of the DFA */
  private int zzState;

  /** the current lexical state */
  private int zzLexicalState = YYINITIAL;

  /** this buffer contains the current text to be matched and is
      the source of the yytext() string */
  private char zzBuffer[] = new char[ZZ_BUFFERSIZE];

  /** the textposition at the last accepting state */
  private int zzMarkedPos;

  /** the textposition at the last state to be included in yytext */
  private int zzPushbackPos;

  /** the current text position in the buffer */
  private int zzCurrentPos;

  /** startRead marks the beginning of the yytext() string in the buffer */
  private int zzStartRead;

  /** endRead marks the last character in the buffer, that has been read
      from input */
  private int zzEndRead;

  /** number of newlines encountered up to the start of the matched text */
  private int yyline;

  /** the number of characters up to the start of the matched text */
  private int yychar;

  /**
   * the number of characters from the last newline up to the start of the 
   * matched text
   */
  private int yycolumn;

  /** 
   * zzAtBOL == true <=> the scanner is currently at the beginning of a line
   */
  private boolean zzAtBOL = true;

  /** zzAtEOF == true <=> the scanner is at the EOF */
  private boolean zzAtEOF;

  /* user code: */
	public static void main(String argv[]) {
		if (argv.length != 1) {
			System.out.println("Usage: java MJLexer inputfile");
		}
		else {
			MJLexer l =null;
			try	{
				l = new MJLexer(new java.io.FileReader(argv[0]));
				Symbol s = l.yylex();
				while (s.getType() != Symbol.EOF) {
					System.out.println(s);
					s = l.yylex();
				}
			} catch (Exception e) {
				System.out.println("Unexpected exception:");
				e.printStackTrace();
			}
		}
	}

	private Symbol symbol(int type) {
		return new Symbol(type, yytext(), yyline, yycolumn);
	}


  /**
   * Creates a new scanner
   * There is also a java.io.InputStream version of this constructor.
   *
   * @param   in  the java.io.Reader to read input from.
   */
  public MJLexer(java.io.Reader in) {
    this.zzReader = in;
  }

  /**
   * Creates a new scanner.
   * There is also java.io.Reader version of this constructor.
   *
   * @param   in  the java.io.Inputstream to read input from.
   */
  public MJLexer(java.io.InputStream in) {
    this(new java.io.InputStreamReader(in));
  }


  /**
   * Refills the input buffer.
   *
   * @return      <code>false</code>, iff there was new input.
   * 
   * @exception   java.io.IOException  if any I/O-Error occurs
   */
  private boolean zzRefill() throws java.io.IOException {

    /* first: make room (if you can) */
    if (zzStartRead > 0) {
      System.arraycopy(zzBuffer, zzStartRead,
                       zzBuffer, 0,
                       zzEndRead-zzStartRead);

      /* translate stored positions */
      zzEndRead-= zzStartRead;
      zzCurrentPos-= zzStartRead;
      zzMarkedPos-= zzStartRead;
      zzPushbackPos-= zzStartRead;
      zzStartRead = 0;
    }

    /* is the buffer big enough? */
    if (zzCurrentPos >= zzBuffer.length) {
      /* if not: blow it up */
      char newBuffer[] = new char[zzCurrentPos*2];
      System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
      zzBuffer = newBuffer;
    }

    /* finally: fill the buffer with new input */
    int numRead = zzReader.read(zzBuffer, zzEndRead,
                                            zzBuffer.length-zzEndRead);

    if (numRead < 0) {
      return true;
    }
    else {
      zzEndRead+= numRead;
      return false;
    }
  }

    
  /**
   * Closes the input stream.
   */
  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
   *

⌨️ 快捷键说明

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