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

📄 parser.java

📁 我开发的一个用java语言实现的编译器,内含词法分析器,语法分析器,而且可以实现中间代码生成.用到了SLR算法和LR(1)算法
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\002\001\001\000\004\061\042\001\001\000\002\001" +    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\002\001\001\000\002\001\001\000\002\001\001\000" +    "\002\001\001\000\002\001\001\000\002\001\001\000\002" +    "\001\001\000\002\001\001\000\004\054\051\001\001\000" +    "\002\001\001\000\002\001\001\000\002\001\001\000\004" +    "\034\057\001\001\000\002\001\001\000\002\001\001\000" +    "\002\001\001\000\002\001\001\000\006\015\114\037\113" +    "\001\001\000\004\041\112\001\001\000\002\001\001\000" +    "\002\001\001\000\002\001\001\000\002\001\001\000\004" +    "\066\107\001\001\000\004\064\104\001\001\000\004\065" +    "\072\001\001\000\012\042\077\047\074\052\100\053\075" +    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\002\001\001\000\010\047\074\052\103\053\075\001" +    "\001\000\002\001\001\000\012\042\105\047\074\052\100" +    "\053\075\001\001\000\002\001\001\000\002\001\001\000" +    "\012\042\110\047\074\052\100\053\075\001\001\000\002" +    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +    "\001\000\010\016\126\030\127\046\124\001\001\000\002" +    "\001\001\000\004\046\120\001\001\000\002\001\001\000" +    "\004\067\122\001\001\000\002\001\001\000\002\001\001" +    "\000\002\001\001\000\004\070\133\001\001\000\004\072" +    "\131\001\001\000\006\030\130\046\124\001\001\000\002" +    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +    "\001\000\002\001\001\000\004\071\135\001\001\000\012" +    "\031\137\035\141\036\140\037\136\001\001\000\002\001" +    "\001\000\006\032\150\047\147\001\001\000\002\001\001" +    "\000\002\001\001\000\002\001\001\000\010\031\137\036" +    "\144\037\136\001\001\000\002\001\001\000\002\001\001" +    "\000\006\047\074\053\156\001\001\000\006\037\151\051" +    "\152\001\001\000\002\001\001\000\002\001\001\000\002" +    "\001\001\000\006\050\154\054\155\001\001\000\002\001" +    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\010\026\164\033\161\044\174\001\001\000\002\001" +    "\001\000\004\060\172\001\001\000\002\001\001\000\004" +    "\062\165\001\001\000\002\001\001\000\004\033\170\001" +    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\002\001\001\000\002\001\001\000\002\001\001\000" +    "\002\001\001\000\006\005\203\037\204\001\001\000\006" +    "\017\200\054\030\001\001\000\004\056\201\001\001\000" +    "\002\001\001\000\002\001\001\000\006\007\205\020\206" +    "\001\001\000\002\001\001\000\022\006\225\010\220\012" +    "\012\013\217\014\227\022\221\023\216\024\007\001\001" +    "\000\002\001\001\000\010\017\210\021\211\054\030\001" +    "\001\000\002\001\001\000\004\057\212\001\001\000\002" +    "\001\001\000\002\001\001\000\004\054\051\001\001\000" +    "\002\001\001\000\002\001\001\000\002\001\001\000\002" +    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +    "\000\016\012\012\024\065\037\063\040\230\041\066\043" +    "\062\001\001\000\006\015\231\037\113\001\001\000\010" +    "\016\232\030\127\046\124\001\001\000\006\030\130\046" +    "\124\001\001\000\002\001\001\000\004\011\236\001\001" +    "\000\002\001\001\000\002\001\001\000\002\001\001\000" +    "\004\011\241\001\001\000\002\001\001\000\002\001\001" +    "\000\004\011\244\001\001\000\002\001\001\000\002\001" +    "\001\000\004\011\247\001\001\000\002\001\001\000\002" +    "\001\001" });  /** Access to <code>reduce_goto</code> table. */  public short[][] reduce_table() {return _reduce_table;}  /** Instance of action encapsulation class. */  protected CUP$parser$actions action_obj;  /** Action encapsulation object initializer. */  protected void init_actions()    {      action_obj = new CUP$parser$actions(this);    }  /** Invoke a user supplied parse action. */  public java_cup.runtime.Symbol do_action(    int                        act_num,    java_cup.runtime.lr_parser parser,    java.util.Stack            stack,    int                        top)    throws java.lang.Exception  {    /* call code in generated class */    return action_obj.CUP$parser$do_action(act_num, parser, stack, top);  }  /** Indicates start state. */  public int start_state() {return 0;}  /** Indicates start production. */  public int start_production() {return 0;}  /** <code>EOF</code> Symbol index. */  public int EOF_sym() {return 0;}  /** <code>error</code> Symbol index. */  public int error_sym() {return 1;}  /** User initialization code. */  public void user_init() throws java.lang.Exception    { lexer.init();     }  /** Scan to get the next Symbol. */  public java_cup.runtime.Symbol scan()    throws java.lang.Exception    { return lexer.next_token();     }  /* override error routines */  public void report_fatal_error(    String   message,    Object   info)    {      done_parsing();      lexer.emit_error(message);      System.err.println("Can't recover from previous error(s), giving up.");      System.exit(1);    }    public void report_error(String message, Object info)    {      lexer.emit_error(message);    }}/** Cup generated class to encapsulate user supplied action code.*/class CUP$parser$actions {  /** helper routine to clone a new production part adding a given label */  protected production_part add_lab(production_part part, String lab)    throws internal_error    {      /* if there is no label, or this is an action, just return the original */      if (lab == null || part.is_action()) return part;      /* otherwise build a new one with the given label attached */      return new symbol_part(((symbol_part)part).the_symbol(),lab);    }  /** max size of right hand side we will support */  protected final int MAX_RHS = 200;  /** array for accumulating right hand side parts */  protected production_part[] rhs_parts = new production_part[MAX_RHS];  /** where we are currently in building a right hand side */  protected int rhs_pos = 0;  /** start a new right hand side */  protected void new_rhs() {rhs_pos = 0; }  /** add a new right hand side part */  protected void add_rhs_part(production_part part) throws java.lang.Exception    {      if (rhs_pos >= MAX_RHS)	throw new Exception("Internal Error: Productions limited to " + 			     MAX_RHS + " symbols and actions");       rhs_parts[rhs_pos] = part;      rhs_pos++;    }  /** string to build up multiple part names */  protected String multipart_name = new String();  /** append a new name segment to the accumulated multipart name */  protected void append_multipart(String name)    {      String dot = "";      /* if we aren't just starting out, put on a dot */      if (multipart_name.length() != 0)  dot = ".";      multipart_name = multipart_name.concat(dot + name);    }  /** table of declared symbols -- contains production parts indexed by name */  protected Hashtable symbols = new Hashtable();  /** table of just non terminals -- contains non_terminals indexed by name */  protected Hashtable non_terms = new Hashtable();  /** declared start non_terminal */  protected non_terminal start_nt = null;  /** left hand side non terminal of the current production */  protected non_terminal lhs_nt;  /** Current precedence number */  int _cur_prec = 0;  /** Current precedence side */  int _cur_side = assoc.no_prec;  /** update the precedences we are declaring */  protected void update_precedence(int p) {    _cur_side = p;    _cur_prec++;  }  /** add relevant data to terminals */   protected void add_precedence(String term) {    if (term == null) {      System.err.println("Unable to add precedence to nonexistent terminal");    } else {      symbol_part sp = (symbol_part)symbols.get(term);      if (sp == null) {	System.err.println("Could find terminal " + term + " while declaring precedence");      } else {	java_cup.symbol sym = sp.the_symbol();	if (sym instanceof terminal) 	  ((terminal)sym).set_precedence(_cur_side, _cur_prec);	else System.err.println("Precedence declaration: Can't find terminal " + term);      }    }  }  private final parser parser;  /** Constructor */  CUP$parser$actions(parser parser) {    this.parser = parser;  }  /** Method with the actual generated action code. */  public final java_cup.runtime.Symbol CUP$parser$do_action(    int                        CUP$parser$act_num,    java_cup.runtime.lr_parser CUP$parser$parser,    java.util.Stack            CUP$parser$stack,    int                        CUP$parser$top)    throws java.lang.Exception    {      /* Symbol object for return from actions */      java_cup.runtime.Symbol CUP$parser$result;      /* select the action based on the action number */      switch (CUP$parser$act_num)        {          /*. . . . . . . . . . . . . . . . . . . .*/          case 106: // empty ::=             {              Object RESULT = null;              CUP$parser$result = new java_cup.runtime.Symbol(29/*empty*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);            }          return CUP$parser$result;          /*. . . . . . . . . . . . . . . . . . . .*/          case 105: // opt_semi ::= SEMI             {              Object RESULT = null;              CUP$parser$result = new java_cup.runtime.Symbol(7/*opt_semi*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);            }          return CUP$parser$result;          /*. . . . . . . . . . . . . . . . . . . .*/

⌨️ 快捷键说明

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