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

📄 lexer.java

📁 有关编译器的编译器.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* This file was generated by SableCC (http://www.sablecc.org/). */package org.sablecc.sablecc.lexer;import java.io.*;import java.util.*;import org.sablecc.sablecc.node.*;public class Lexer{  protected Token token;  protected State state = State.NORMAL;  private PushbackReader in;  private int line;  private int pos;  private boolean cr;  private boolean eof;  private final StringBuffer text = new StringBuffer();  protected void filter() throws LexerException, IOException    {}  public Lexer(PushbackReader in)  {    this.in = in;    if(gotoTable == null)    {      try      {        DataInputStream s = new DataInputStream(                              new BufferedInputStream(                                Lexer.class.getResourceAsStream("lexer.dat")));        // read gotoTable        int length = s.readInt();        gotoTable = new int[length][][][];        for(int i = 0; i < gotoTable.length; i++)        {          length = s.readInt();          gotoTable[i] = new int[length][][];          for(int j = 0; j < gotoTable[i].length; j++)          {            length = s.readInt();            gotoTable[i][j] = new int[length][3];            for(int k = 0; k < gotoTable[i][j].length; k++)            {              for(int l = 0; l < 3; l++)              {                gotoTable[i][j][k][l] = s.readInt();              }            }          }        }        // read accept        length = s.readInt();        accept = new int[length][];        for(int i = 0; i < accept.length; i++)        {          length = s.readInt();          accept[i] = new int[length];          for(int j = 0; j < accept[i].length; j++)          {            accept[i][j] = s.readInt();          }        }        s.close();      }      catch(Exception e)      {        throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.");      }    }  }  public Token peek() throws LexerException, IOException  {    while(token == null)    {      token = getToken();      filter();    }    return token;  }  public Token next() throws LexerException, IOException  {    while(token == null)    {      token = getToken();      filter();    }    Token result = token;    token = null;    return result;  }  protected Token getToken() throws IOException, LexerException  {    int dfa_state = 0;    int start_pos = pos;    int start_line = line;    int accept_state = -1;    int accept_token = -1;    int accept_length = -1;    int accept_pos = -1;    int accept_line = -1;    int[][][] gotoTable = this.gotoTable[state.id()];    int[] accept = this.accept[state.id()];    text.setLength(0);    while(true)    {      int c = getChar();      if(c != -1)      {        switch(c)        {        case 10:          if(cr)          {            cr = false;          }          else          {            line++;            pos = 0;          }          break;        case 13:          line++;          pos = 0;          cr = true;          break;        default:          pos++;          cr = false;          break;        };        text.append((char) c);        do        {          int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state;          dfa_state = -1;          int[][] tmp1 =  gotoTable[oldState];          int low = 0;          int high = tmp1.length - 1;          while(low <= high)          {            int middle = (low + high) / 2;            int[] tmp2 = tmp1[middle];            if(c < tmp2[0])            {              high = middle - 1;            }            else if(c > tmp2[1])            {              low = middle + 1;            }            else            {              dfa_state = tmp2[2];              break;            }          }        }        while(dfa_state < -1);      }      else      {        dfa_state = -1;      }      if(dfa_state >= 0)      {        if(accept[dfa_state] != -1)        {          accept_state = dfa_state;          accept_token = accept[dfa_state];          accept_length = text.length();          accept_pos = pos;          accept_line = line;        }      }      else      {        if(accept_state != -1)        {          switch(accept_token)          {          case 0:            {              Token token = new0(                              getText(accept_length),                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              switch(state.id())              {              case 1:                state = State.PACKAGE;                break;              }              return token;            }          case 1:            {              Token token = new1(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              switch(state.id())              {              case 0:                state = State.PACKAGE;                break;              }              return token;            }          case 2:            {              Token token = new2(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 3:            {              Token token = new3(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 4:            {              Token token = new4(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 5:            {              Token token = new5(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 6:            {              Token token = new6(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 7:            {              Token token = new7(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 8:            {              Token token = new8(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 9:            {              Token token = new9(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 10:            {              Token token = new10(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 11:            {              Token token = new11(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              switch(state.id())              {              case 0:                state = State.NORMAL;                break;              case 1:                state = State.NORMAL;                break;              }              return token;            }          case 12:            {              Token token = new12(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 13:            {              Token token = new13(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 14:            {              Token token = new14(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 15:            {              Token token = new15(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 16:            {              Token token = new16(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 17:            {              Token token = new17(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 18:            {              Token token = new18(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 19:            {              Token token = new19(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 20:            {              Token token = new20(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 21:            {              Token token = new21(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 22:            {              Token token = new22(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 23:            {              Token token = new23(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 24:            {              Token token = new24(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 25:            {              Token token = new25(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 26:            {              Token token = new26(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 27:            {              Token token = new27(                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 28:            {              Token token = new28(                              getText(accept_length),                              start_line + 1,                              start_pos + 1);              pushBack(accept_length);              pos = accept_pos;              line = accept_line;              return token;            }          case 29:            {

⌨️ 快捷键说明

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