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

📄 exprelexer.java.svn-base

📁 实现的一个简单的语言编译器,可以编译类JAVA 的小语言
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/* The following code was generated by JFlex 1.4.1 on 08-4-11 上午9:26 */

package edu.ustc.cs.compile.parser.expr;

import java.util.Stack;

import java_cup.runtime.*;


/**
 * This class is a scanner generated by 
 * <a href="http://www.jflex.de/">JFlex</a> 1.4.1
 * on 08-4-11 上午9:26 from the specification file
 * <tt>F:/zhz/work/upload/svn/ComplierProj/student/lab/lab3/config/JFlex/expr_err.flex</tt>
 */
public class ExprELexer implements java_cup.runtime.Scanner {

  /** 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 String ZZ_CMAP_PACKED = 
    "\11\0\1\3\1\5\1\0\1\2\1\4\22\0\1\3\7\1\1\13"+
    "\1\14\1\20\1\16\1\1\1\17\1\1\1\6\12\12\1\1\1\15"+
    "\1\1\1\21\3\1\32\10\6\1\32\10\4\1\53\0\1\7\12\0"+
    "\1\7\4\0\1\7\5\0\27\7\1\0\37\7\1\0\u013f\7\31\0"+
    "\162\7\4\0\14\7\16\0\5\7\11\0\1\7\213\0\1\7\13\0"+
    "\1\7\1\0\3\7\1\0\1\7\1\0\24\7\1\0\54\7\1\0"+
    "\46\7\1\0\5\7\4\0\202\7\10\0\105\7\1\0\46\7\2\0"+
    "\2\7\6\0\20\7\41\0\46\7\2\0\1\7\7\0\47\7\110\0"+
    "\33\7\5\0\3\7\56\0\32\7\5\0\13\7\25\0\12\11\4\0"+
    "\2\7\1\0\143\7\1\0\1\7\17\0\2\7\7\0\2\7\12\11"+
    "\3\7\2\0\1\7\20\0\1\7\1\0\36\7\35\0\3\7\60\0"+
    "\46\7\13\0\1\7\u0152\0\66\7\3\0\1\7\22\0\1\7\7\0"+
    "\12\7\4\0\12\11\25\0\10\7\2\0\2\7\2\0\26\7\1\0"+
    "\7\7\1\0\1\7\3\0\4\7\3\0\1\7\36\0\2\7\1\0"+
    "\3\7\4\0\12\11\2\7\23\0\6\7\4\0\2\7\2\0\26\7"+
    "\1\0\7\7\1\0\2\7\1\0\2\7\1\0\2\7\37\0\4\7"+
    "\1\0\1\7\7\0\12\11\2\0\3\7\20\0\11\7\1\0\3\7"+
    "\1\0\26\7\1\0\7\7\1\0\2\7\1\0\5\7\3\0\1\7"+
    "\22\0\1\7\17\0\2\7\4\0\12\11\25\0\10\7\2\0\2\7"+
    "\2\0\26\7\1\0\7\7\1\0\2\7\1\0\5\7\3\0\1\7"+
    "\36\0\2\7\1\0\3\7\4\0\12\11\1\0\1\7\21\0\1\7"+
    "\1\0\6\7\3\0\3\7\1\0\4\7\3\0\2\7\1\0\1\7"+
    "\1\0\2\7\3\0\2\7\3\0\3\7\3\0\10\7\1\0\3\7"+
    "\55\0\11\11\25\0\10\7\1\0\3\7\1\0\27\7\1\0\12\7"+
    "\1\0\5\7\46\0\2\7\4\0\12\11\25\0\10\7\1\0\3\7"+
    "\1\0\27\7\1\0\12\7\1\0\5\7\3\0\1\7\40\0\1\7"+
    "\1\0\2\7\4\0\12\11\25\0\10\7\1\0\3\7\1\0\27\7"+
    "\1\0\20\7\46\0\2\7\4\0\12\11\25\0\22\7\3\0\30\7"+
    "\1\0\11\7\1\0\1\7\2\0\7\7\72\0\60\7\1\0\2\7"+
    "\14\0\7\7\11\0\12\11\47\0\2\7\1\0\1\7\2\0\2\7"+
    "\1\0\1\7\2\0\1\7\6\0\4\7\1\0\7\7\1\0\3\7"+
    "\1\0\1\7\1\0\1\7\2\0\2\7\1\0\4\7\1\0\2\7"+
    "\11\0\1\7\2\0\5\7\1\0\1\7\11\0\12\11\2\0\2\7"+
    "\42\0\1\7\37\0\12\11\26\0\10\7\1\0\42\7\35\0\4\7"+
    "\164\0\42\7\1\0\5\7\1\0\2\7\25\0\12\11\6\0\6\7"+
    "\112\0\46\7\12\0\51\7\7\0\132\7\5\0\104\7\5\0\122\7"+
    "\6\0\7\7\1\0\77\7\1\0\1\7\1\0\4\7\2\0\7\7"+
    "\1\0\1\7\1\0\4\7\2\0\47\7\1\0\1\7\1\0\4\7"+
    "\2\0\37\7\1\0\1\7\1\0\4\7\2\0\7\7\1\0\1\7"+
    "\1\0\4\7\2\0\7\7\1\0\7\7\1\0\27\7\1\0\37\7"+
    "\1\0\1\7\1\0\4\7\2\0\7\7\1\0\47\7\1\0\23\7"+
    "\16\0\11\11\56\0\125\7\14\0\u026c\7\2\0\10\7\12\0\32\7"+
    "\5\0\113\7\25\0\15\7\1\0\4\7\16\0\22\7\16\0\22\7"+
    "\16\0\15\7\1\0\3\7\17\0\64\7\43\0\1\7\4\0\1\7"+
    "\3\0\12\11\46\0\12\11\6\0\130\7\10\0\51\7\127\0\35\7"+
    "\51\0\12\11\36\7\2\0\5\7\u038b\0\154\7\224\0\234\7\4\0"+
    "\132\7\6\0\26\7\2\0\6\7\2\0\46\7\2\0\6\7\2\0"+
    "\10\7\1\0\1\7\1\0\1\7\1\0\1\7\1\0\37\7\2\0"+
    "\65\7\1\0\7\7\1\0\1\7\3\0\3\7\1\0\7\7\3\0"+
    "\4\7\2\0\6\7\4\0\15\7\5\0\3\7\1\0\7\7\164\0"+
    "\1\7\15\0\1\7\202\0\1\7\4\0\1\7\2\0\12\7\1\0"+
    "\1\7\3\0\5\7\6\0\1\7\1\0\1\7\1\0\1\7\1\0"+
    "\4\7\1\0\3\7\1\0\7\7\3\0\3\7\5\0\5\7\u0ebb\0"+
    "\2\7\52\0\5\7\5\0\2\7\4\0\126\7\6\0\3\7\1\0"+
    "\132\7\1\0\4\7\5\0\50\7\4\0\136\7\21\0\30\7\70\0"+
    "\20\7\u0200\0\u19b6\7\112\0\u51a6\7\132\0\u048d\7\u0773\0\u2ba4\7\u215c\0"+
    "\u012e\7\2\0\73\7\225\0\7\7\14\0\5\7\5\0\1\7\1\0"+
    "\12\7\1\0\15\7\1\0\5\7\1\0\1\7\1\0\2\7\1\0"+
    "\2\7\1\0\154\7\41\0\u016b\7\22\0\100\7\2\0\66\7\50\0"+
    "\14\7\164\0\5\7\1\0\207\7\23\0\12\11\7\0\32\7\6\0"+
    "\32\7\13\0\131\7\3\0\6\7\2\0\6\7\2\0\6\7\2\0"+
    "\3\7\43\0";

  /** 
   * Translates characters to character classes
   */
  private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);

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

  private static final String ZZ_ACTION_PACKED_0 =
    "\1\0\1\1\2\2\1\3\1\4\1\5\1\6\1\7"+
    "\1\10\1\11\1\12\1\13\1\14\1\2";

  private static int [] zzUnpackAction() {
    int [] result = new int[15];
    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\22\0\22\0\44\0\66\0\110\0\132\0\22"+
    "\0\22\0\22\0\22\0\22\0\22\0\22\0\154";

  private static int [] zzUnpackRowMap() {
    int [] result = new int[15];
    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 =
    "\2\2\2\3\1\4\1\3\1\5\2\6\2\7\1\10"+
    "\1\11\1\12\1\13\1\14\1\15\1\16\27\0\1\3"+
    "\22\0\1\17\22\0\4\6\20\0\2\7\10\0\1\17"+
    "\1\0\1\17\2\0\1\17\1\0\1\17\1\0\10\17";

  private static int [] zzUnpackTrans() {
    int [] result = new int[126];
    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\2\11\4\1\7\11\1\1";

  private static int [] zzUnpackAttribute() {
    int [] result = new int[15];
    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;

  /** denotes if the user-EOF-code has already been executed */
  private boolean zzEOFDone;

  /* user code: */
  private StringBuffer string = new StringBuffer();
  private Stack<LParen> lparenStack = new Stack<LParen>();
  private int preSymbol = -1;
  private boolean debug = true;
  
  private class LParen {
    private int line = -1;
    private int column = -1;
    
    public LParen(int line, int column) {
        this.line = line;
        this.column = column;
    }
    
    public int line() {
        return this.line;
    }
    
    public int column() {
        return this.column;
    }
  }  
  
  private void errMsg(String msg, int line, int column) {
    System.err.print("ERROR: ");
    System.err.print("At line "+line+", column "+column+" : ");    System.err.println(msg);
  }
  
  private void debugMsg(String msg) {
    System.err.print("DEBUG: ");
    System.err.println(msg);
  }
  
  private Symbol symbol(int type) {
    preSymbol = type;
    System.err.println("TOKEN: "+yytext());
    return new Symbol(type, yyline+1, yycolumn+1);
  }
  
  private Symbol symbol(int type, int preType) {
    preSymbol = preType;
    System.err.println("TOKEN: "+yytext());
    return new Symbol(type, yyline+1, yycolumn+1);
  }

  private Symbol symbol(int type, Object value) {
    preSymbol = type;
    System.err.println("TOKEN: "+yytext());
    return new Symbol(type, yyline+1, yycolumn+1, value);
  } 
  
  private Symbol symbol(int type, Object value, int preType) {
    preSymbol = preType;
    System.err.println("TOKEN: "+yytext());
    return new Symbol(type, yyline+1, yycolumn+1, value);
  }
  
  /** 
   * assumes correct representation of a long value for 
   * specified radix in scanner buffer from <code>start</code> 
   * to <code>end</code> 
   */
  private long parseLong(int start, int end, int radix) {
    long result = 0;
    long digit;

    for (int i = start; i < end; i++) {
      digit  = Character.digit(yycharat(i),radix);
      result*= radix;
      result+= digit;
    }

    return result;
  }



  /**
   * 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 ExprELexer(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 ExprELexer(java.io.InputStream in) {
    this(new java.io.InputStreamReader(in));
  }

  /** 
   * Unpacks the compressed character translation table.
   *
   * @param packed   the packed character translation table
   * @return         the unpacked character translation table
   */
  private static char [] zzUnpackCMap(String packed) {
    char [] map = new char[0x10000];
    int i = 0;  /* index in packed string  */
    int j = 0;  /* index in unpacked array */
    while (i < 1224) {
      int  count = packed.charAt(i++);
      char value = packed.charAt(i++);
      do map[j++] = value; while (--count > 0);
    }
    return map;
  }


  /**
   * 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 */

⌨️ 快捷键说明

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