📄 parser.java
字号:
"\004\012\254\001\001\000\002\001\001\000\002\001\001" + "\000\006\010\036\014\256\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\035\267\001\001\000" + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + "\001\001\000\006\007\272\010\273\001\001\000\002\001" + "\001\000\002\001\001\000\004\046\031\001\001\000\004" + "\051\276\001\001\000\002\001\001\000\004\052\300\001" + "\001\000\014\010\036\013\034\014\040\033\037\036\301" + "\001\001\000\002\001\001\000\004\053\303\001\001\000" + "\004\015\304\001\001\000\002\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 3;} /** <code>EOF</code> Symbol index. */ public int EOF_sym() {return 0;} /** <code>error</code> Symbol index. */ public int error_sym() {return 1;}public static ClassProgram classProgram;public static int curType, curOffset;public static SymbolTable curST, curScopeST;public static MethodDescriptor curMD;public static String infile;public static boolean debug; // = Compiler.PARSER_DEBUG;public void startParse(String i) throws Exception{ parser.infile = i; this.parse(); } /** Report a non fatal error (or warning). This method takes a message * string and an additional object (to be used by specializations * implemented in subclasses). Here in the base class a very simple * implementation is provided which simply prints the message to * System.err. * * @param message an error message. * @param info an extra object reserved for use by specialized subclasses. */ public void report_error(String message, Object info) { ClassProgram.numOfError++; ClassProgram.semanticCheck=false; if (info instanceof Symbol) if (((Symbol)info).left != -1) System.out.println(parser.infile + ":"+ ((Symbol)info).left + ": Syntax error: '" + ((Symbol)info).value+"'"); //else System.err.println(""); //else System.err.println(""); } /** Overriding original error message to handle the errors just before EOF */ public void report_fatal_error( String message, Object info) throws java.lang.Exception { //ClassProgram.numOfError++; ClassProgram.semanticCheck=false; System.out.println(parser.infile + ":" + Scanner.lineno + ": Syntax error: missing '}'"); /* stop parsing */ done_parsing(); }/* This function handles conversion of +ve integers and detection of over-sized +ve integers *//* This function handles conversion of -ve integers and detection of over-sized -ve integers */public static Exp convPos( Exp e, int lineNo ){ //if not a direct interger, not handling at all if (!(e instanceof LtrInt)) return e; LtrInt ltrInt = (LtrInt)e; //if already converted, not handling again, if (ltrInt.converted()) return e; int intNum; String intStr = ltrInt.getIntString(); try{ if (intStr.startsWith("0x")){ //always take as Uminus a Positive intNum = Integer.parseInt(intStr.substring(2), 16); //if (debug) System.out.println("Processed integer (+ve integer) at line (" + lineNo + "): " + intStr + "-> " + intNum); }else{ //decimal is always a negative number here intNum = Integer.parseInt(intStr); //if (debug) System.out.println("Processed integer (+ve integer) at line (" + lineNo + "): " + intStr); } ltrInt.convNum(intNum); return ltrInt; }catch(NumberFormatException err){ System.err.println(parser.infile + ": "+ lineNo +": Integer above upper bound: '"+intStr+"'"); ClassProgram.numOfError++; ltrInt.convNum(1); //default negative number return ltrInt; }}/* This function handles conversion of -ve integers and detection of over-sized -ve integers */public static Exp convNeg( Exp e, int lineNo ){ //if not a direct interger, not handling at all if (!(e instanceof LtrInt)) return new ExpUMinus((Exp)e); LtrInt ltrInt = (LtrInt)e; //if already converted, not handling again, if (ltrInt.converted()) return new ExpUMinus((Exp)e); int intNum; String intStr = ltrInt.getIntString(); try{ if (intStr.startsWith("0x")){ //always take as Uminus a Positive intNum = Integer.parseInt("-"+intStr.substring(2), 16); //if (debug) System.out.println("Processed integer (-ve integer) at line (" + lineNo + "): " + intStr + " -> " + intNum); }else{ //decimal is always a negative number here intNum = Integer.parseInt("-"+intStr); //if (debug) System.out.println("Processed integer (-ve integer) at line (" + lineNo + "): -" + intStr); } ltrInt.convNum(intNum); return ltrInt; }catch(NumberFormatException err){ System.err.println(parser.infile + ": "+ lineNo +": Integer below lower bound: '-"+intStr+"'"); ClassProgram.numOfError++; ltrInt.convNum(-1); //default negative number return ltrInt; }}}/** Cup generated class to encapsulate user supplied action code.*/class CUP$parser$actions {/* This flag is used for printing DEBUG messages */public static boolean debug = parser.debug;public static Stmt stmtTemp = null; 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 108: // empty ::= { Object RESULT = null; CUP$parser$result = new java_cup.runtime.Symbol(25/*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; /*. . . . . . . . . . . . . . . . . . . .*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -