cup-0.11a+20060608/ 0000755 0001750 0001750 00000000000 11075731252 013225 5 ustar twerner twerner cup-0.11a+20060608/bin/ 0000755 0001750 0001750 00000000000 11075722356 014002 5 ustar twerner twerner cup-0.11a+20060608/cup/ 0000755 0001750 0001750 00000000000 11075720101 014003 5 ustar twerner twerner cup-0.11a+20060608/cup/parser.cup 0000644 0001750 0001750 00000062445 10441773704 016040 0 ustar twerner twerner /*================================================================*/ /* JavaCup Specification for the JavaCup Specification Language by Scott Hudson, GVU Center, Georgia Tech, August 1995 and Frank Flannery, Department of Computer Science, Princeton Univ, July 1996 Bug Fixes: C. Scott Ananian, Dept of Electrical Engineering, Princeton University, October 1996. [later Massachusetts Institute of Technology] This JavaCup specification is used to implement JavaCup itself. It specifies the parser for the JavaCup specification language. (It also serves as a reasonable example of what a typical JavaCup spec looks like). The specification has the following parts: Package and import declarations These serve the same purpose as in a normal Java source file (and will appear in the generated code for the parser). In this case we are part of the java_cup package and we import both the java_cup runtime system and Hashtable from the standard Java utilities package. Action code This section provides code that is included with the class encapsulating the various pieces of user code embedded in the grammar (i.e., the semantic actions). This provides a series of helper routines and data structures that the semantic actions use. Parser code This section provides code included in the parser class itself. In this case we override the default error reporting routines. Init with and scan with These sections provide small bits of code that initialize, then indicate how to invoke the scanner. Symbols and grammar These sections declare all the terminal and non terminal symbols and the types of objects that they will be represented by at runtime, then indicate the start symbol of the grammar (), and finally provide the grammar itself (with embedded actions). Operation of the parser The parser acts primarily by accumulating data structures representing various parts of the specification. Various small parts (e.g., single code strings) are stored as static variables of the emit class and in a few cases as variables declared in the action code section. Terminals, non terminals, and productions, are maintained as collection accessible via static methods of those classes. In addition, two symbol tables are kept: symbols maintains the name to object mapping for all symbols non_terms maintains a separate mapping containing only the non terms Several intermediate working structures are also declared in the action code section. These include: rhs_parts, rhs_pos, and lhs_nt which build up parts of the current production while it is being parsed. Author(s) Scott Hudson, GVU Center, Georgia Tech. Frank Flannery, Department of Computer Science, Princeton Univ. C. Scott Ananian, Department of Electrical Engineering, Princeton Univ. Revisions v0.9a First released version [SEH] 8/29/95 v0.9b Updated for beta language (throws clauses) [SEH] 11/25/95 v0.10a Made many improvements/changes. now offers: return value left/right positions and propagations cleaner label references precedence and associativity for terminals contextual precedence for productions [FF] 7/3/96 v0.10b Fixed %prec directive so it works like it's supposed to. [CSA] 10/10/96 v0.10g Added support for array types on symbols. [CSA] 03/23/98 v0.10i Broaden set of IDs allowed in multipart_id and label_id so that only java reserved words (and not CUP reserved words like 'parser' and 'start') are prohibited. Allow reordering of action code, parser code, init code, and scan with sections, and made closing semicolon optional for these sections. Added 'nonterminal' as a terminal symbol, finally fixing a spelling mistake that's been around since the beginning. For backwards compatibility, you can still misspell the word if you like. */ /*================================================================*/ package java_cup; import java_cup.runtime.*; import java.util.Hashtable; import java.util.Stack; /*----------------------------------------------------------------*/ action code {: /** 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(); protected Stack multipart_names = new Stack(); /** append a new name segment to the accumulated multipart name */ // TUM CHANGES // 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); // } // TUM CHANGES /** 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); } } } :}; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ parser code {: /* override error routines */ protected Lexer lexer; public void report_fatal_error( String message, Object info) { done_parsing(); if (info instanceof Symbol) ErrorManager.getManager().emit_fatal(message+ "\nCan't recover from previous error(s), giving up.",(Symbol)info); else ErrorManager.getManager().emit_fatal(message + "\nCan't recover from previous error(s), giving up.",cur_token); System.exit(1); } public void report_error(String message, Object info) { if (info instanceof Symbol) ErrorManager.getManager().emit_error(message,(Symbol)info); else ErrorManager.getManager().emit_error(message,cur_token); } :}; /*---------------------------------------------------------------- */ init with {: ComplexSymbolFactory f = new ComplexSymbolFactory(); symbolFactory = f; lexer = new Lexer(f); :} /*lexer.init(); :};*/ scan with {: return lexer.next_token(); :}; /*----------------------------------------------------------------*/ terminal PACKAGE, IMPORT, CODE, ACTION, PARSER, TERMINAL, NON, INIT, SCAN, WITH, START, SEMI, COMMA, STAR, DOT, COLON, COLON_COLON_EQUALS, BAR, PRECEDENCE, LEFT, RIGHT, NONASSOC, PERCENT_PREC, LBRACK, RBRACK, NONTERMINAL, GT, LT, QUESTION, SUPER, EXTENDS; terminal String ID, CODE_STRING; non terminal spec, package_spec, import_list, action_code_part, code_parts, code_part, opt_semi, non_terminal, parser_code_part, symbol_list, start_spec, production_list, multipart_id, import_spec, import_id, init_code, scan_code, symbol, type_id, term_name_list, non_term_name_list, production, prod_part_list, prod_part, new_term_id, new_non_term_id, rhs_list, rhs, empty, precedence_list, preced, terminal_list, precedence_l, declares_term, declares_non_term; non terminal String nt_id, symbol_id, label_id, opt_label, terminal_id, term_id, robust_id, typearglist, typearguement, wildcard; /*----------------------------------------------------------------*/ start with spec; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ spec ::= {: /* declare "error" as a terminal */ symbols.put("error", new symbol_part(terminal.error)); /* declare start non terminal */ non_terms.put("$START", non_terminal.START_nt); :} package_spec import_list code_parts symbol_list precedence_list start_spec production_list | /* error recovery assuming something went wrong before symbols and we have TERMINAL or NON TERMINAL to sync on. if we get an error after that, we recover inside symbol_list or production_list */ error symbol_list precedence_list start_spec production_list ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ package_spec ::= PACKAGE multipart_id {: /* save the package name */ emit.package_name = multipart_name; /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI | empty ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ import_list ::= import_list import_spec | empty ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ import_spec ::= IMPORT import_id {: /* save this import on the imports list */ emit.import_list.push(multipart_name); /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ // allow any order; all parts are optional. [CSA, 23-Jul-1999] // (we check in the part action to make sure we don't have 2 of any part) code_part ::= action_code_part | parser_code_part | init_code | scan_code ; code_parts ::= | code_parts code_part; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ action_code_part ::= ACTION CODE CODE_STRING:user_code opt_semi {: if (emit.action_code!=null) ErrorManager.getManager().emit_warning("Redundant action code (skipping)"); else /* save the user included code string */ emit.action_code = user_code; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ parser_code_part ::= PARSER CODE CODE_STRING:user_code opt_semi {: if (emit.parser_code!=null) ErrorManager.getManager().emit_warning("Redundant parser code (skipping)"); else /* save the user included code string */ emit.parser_code = user_code; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ init_code ::= INIT WITH CODE_STRING:user_code opt_semi {: if (emit.init_code!=null) ErrorManager.getManager().emit_warning("Redundant init code (skipping)"); else /* save the user code */ emit.init_code = user_code; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ scan_code ::= SCAN WITH CODE_STRING:user_code opt_semi {: if (emit.scan_code!=null) ErrorManager.getManager().emit_warning("Redundant scan code (skipping)"); else /* save the user code */ emit.scan_code = user_code; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ symbol_list ::= symbol_list symbol | symbol; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ symbol ::= TERMINAL type_id declares_term | TERMINAL declares_term | non_terminal type_id declares_non_term | non_terminal declares_non_term | /* error recovery productions -- sync on semicolon */ TERMINAL error {: /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI | non_terminal error {: /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ declares_term ::= term_name_list {: /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ declares_non_term ::= non_term_name_list {: /* reset the accumulated multipart name */ multipart_name = new String(); :} SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ term_name_list ::= term_name_list COMMA new_term_id | new_term_id; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ non_term_name_list ::= non_term_name_list COMMA new_non_term_id | new_non_term_id ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ precedence_list ::= precedence_l | empty; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ precedence_l ::= precedence_l preced | preced; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ preced ::= PRECEDENCE LEFT {: update_precedence(assoc.left); :} terminal_list SEMI | PRECEDENCE RIGHT {: update_precedence(assoc.right); :} terminal_list SEMI | PRECEDENCE NONASSOC {: update_precedence(assoc.nonassoc); :} terminal_list SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ terminal_list ::= terminal_list COMMA terminal_id | terminal_id ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ terminal_id ::= term_id:sym {: add_precedence(sym); RESULT = sym; :}; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ term_id ::= symbol_id:sym {: /* check that the symbol_id is a terminal */ if (symbols.get(sym) == null) { /* issue a message */ ErrorManager.getManager().emit_error("Terminal \"" + sym + "\" has not been declared"); } RESULT = sym; :}; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ start_spec ::= START WITH nt_id:start_name {: /* verify that the name has been declared as a non terminal */ non_terminal nt = (non_terminal)non_terms.get(start_name); if (nt == null) { ErrorManager.getManager().emit_error( "Start non terminal \"" + start_name + "\" has not been declared"); } else { /* remember the non-terminal for later */ start_nt = nt; /* build a special start production */ new_rhs(); add_rhs_part(add_lab(new symbol_part(start_nt), "start_val")); add_rhs_part(new symbol_part(terminal.EOF)); add_rhs_part(new action_part("RESULT = start_val;")); emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos); new_rhs(); } :} SEMI | empty ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ production_list ::= production_list production | production; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ production ::= nt_id:lhs_id {: /* lookup the lhs nt */ lhs_nt = (non_terminal)non_terms.get(lhs_id); /* if it wasn't declared, emit a message */ if (lhs_nt == null) { if (ErrorManager.getManager().getErrorCount() == 0) ErrorManager.getManager().emit_warning("LHS non terminal \"" + lhs_id + "\" has not been declared"); } /* reset the rhs accumulation */ new_rhs(); :} COLON_COLON_EQUALS /* {: :}*/ rhs_list SEMI | error {: ErrorManager.getManager().emit_error("Syntax Error"); :} SEMI ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ rhs_list ::= rhs_list BAR rhs | rhs; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ rhs ::= prod_part_list PERCENT_PREC term_id:term_name {: java_cup.symbol sym = null; if (lhs_nt != null) { /* Find the precedence symbol */ if (term_name == null) { System.err.println("No terminal for contextual precedence"); sym = null; } else { sym = ((symbol_part)symbols.get(term_name)).the_symbol(); } /* build the production */ production p; if ((sym!=null) && (sym instanceof terminal)) { p = new production(lhs_nt, rhs_parts, rhs_pos, ((terminal)sym).precedence_num(), ((terminal)sym).precedence_side()); ((symbol_part)symbols.get(term_name)).the_symbol().note_use(); } else { System.err.println("Invalid terminal " + term_name + " for contextual precedence assignment"); p = new production(lhs_nt, rhs_parts, rhs_pos); } /* if we have no start non-terminal declared and this is the first production, make its lhs nt the start_nt and build a special start production for it. */ if (start_nt == null) { start_nt = lhs_nt; /* build a special start production */ new_rhs(); add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); add_rhs_part(new symbol_part(terminal.EOF)); add_rhs_part(new action_part("RESULT = start_val;")); if ((sym!=null) && (sym instanceof terminal)) { emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos, ((terminal)sym).precedence_num(), ((terminal)sym).precedence_side()); } else { emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos); } new_rhs(); } } /* reset the rhs accumulation in any case */ new_rhs(); :} | prod_part_list {: if (lhs_nt != null) { /* build the production */ production p = new production(lhs_nt, rhs_parts, rhs_pos); /* if we have no start non-terminal declared and this is the first production, make its lhs nt the start_nt and build a special start production for it. */ if (start_nt == null) { start_nt = lhs_nt; /* build a special start production */ new_rhs(); add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); add_rhs_part(new symbol_part(terminal.EOF)); add_rhs_part(new action_part("RESULT = start_val;")); emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos); new_rhs(); } } /* reset the rhs accumulation in any case */ new_rhs(); :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ prod_part_list ::= prod_part_list prod_part | empty; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ prod_part ::= symbol_id:symid opt_label:labid {: /* try to look up the id */ production_part symb = (production_part)symbols.get(symid); /* if that fails, symbol is undeclared */ if (symb == null) { if (ErrorManager.getManager().getErrorCount() == 0) ErrorManager.getManager().emit_error("java_cup.runtime.Symbol \"" + symid + "\" has not been declared"); } else { /* add a labeled production part */ add_rhs_part(add_lab(symb, labid)); } :} | CODE_STRING:code_str {: /* add a new production part */ add_rhs_part(new action_part(code_str)); :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ opt_label ::= COLON label_id:labid {: RESULT = labid; :} | empty {: RESULT = null; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ multipart_id ::= multipart_id DOT robust_id:another_id {: multipart_name = multipart_name.concat("."+another_id); :} |multipart_id {: multipart_names.push(multipart_name); multipart_name="";:} LT typearglist:types GT {: multipart_name = ((String)multipart_names.pop()).concat("<"+types+">"); :} | robust_id:an_id {: multipart_name = multipart_name.concat(an_id); :} ; /*. . . . . . . . . . . .TUM CHANGES. . . . . . . . . . . . . . . */ typearglist ::= typearguement:arg {: RESULT = arg; :} | typearglist:list COMMA typearguement:arg {: RESULT = list + "," + arg; :} ; typearguement ::= type_id {: RESULT = multipart_name; multipart_name = new String(); :} | wildcard:w {: RESULT = w; :} ; wildcard ::= QUESTION {: RESULT = " ? "; :} | QUESTION EXTENDS type_id {: RESULT = " ? extends "+multipart_name; multipart_name = new String(); :} | QUESTION SUPER type_id {: RESULT = " ? super "+multipart_name; multipart_name = new String(); :} ; /*. . . . . . . . . . .END TUM CHANGES. . . . . . . . . . . . . . */ /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ import_id ::= multipart_id DOT STAR {: multipart_name = multipart_name.concat(".*"); :} | multipart_id ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ type_id ::= multipart_id | type_id LBRACK RBRACK {: multipart_name = multipart_name.concat("[]"); :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ new_term_id ::= ID:term_id {: /* see if this terminal has been declared before */ if (symbols.get(term_id) != null) { /* issue a message */ ErrorManager.getManager().emit_error("java_cup.runtime.Symbol \"" + term_id + "\" has already been declared"); } else { /* if no type declared, declare one */ if (multipart_name.equals("")) { multipart_name = "Object"; } /* build a production_part and put it in the table */ symbols.put(term_id, new symbol_part(new terminal(term_id, multipart_name))); } :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ new_non_term_id ::= ID:non_term_id {: /* see if this non terminal has been declared before */ if (symbols.get(non_term_id) != null) { /* issue a message */ ErrorManager.getManager().emit_error( "java_cup.runtime.Symbol \"" + non_term_id + "\" has already been declared"); } else { if (multipart_name.equals("")) { multipart_name ="Object"; } /* build the non terminal object */ non_terminal this_nt = new non_terminal(non_term_id, multipart_name); /* put it in the non_terms table */ non_terms.put(non_term_id, this_nt); /* build a production_part and put it in the symbols table */ symbols.put(non_term_id, new symbol_part(this_nt)); } :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ nt_id ::= ID:the_id {: RESULT = the_id; :} | error {: ErrorManager.getManager().emit_error("Illegal use of reserved word"); RESULT="ILLEGAL"; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ symbol_id ::= ID:the_id {: RESULT = the_id; :} | error {: ErrorManager.getManager().emit_error("Illegal use of reserved word"); RESULT="ILLEGAL"; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ label_id ::= robust_id:the_id {: RESULT = the_id; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ robust_id ::= /* all ids that aren't reserved words in Java */ ID:the_id {: RESULT = the_id; :} /* package is reserved. */ /* import is reserved. */ | CODE {: RESULT = "code"; :} | ACTION {: RESULT = "action"; :} | PARSER {: RESULT = "parser"; :} | TERMINAL {: RESULT = "terminal"; :} | NON {: RESULT = "non"; :} | NONTERMINAL {: RESULT = "nonterminal"; :} | INIT {: RESULT = "init"; :} | SCAN {: RESULT = "scan"; :} | WITH {: RESULT = "with"; :} | START {: RESULT = "start"; :} | PRECEDENCE {: RESULT = "precedence"; :} | LEFT {: RESULT = "left"; :} | RIGHT {: RESULT = "right"; :} | NONASSOC {: RESULT = "nonassoc"; :} | error {: ErrorManager.getManager().emit_error("Illegal use of reserved word"); RESULT="ILLEGAL"; :} ; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ non_terminal ::= NON TERMINAL | NONTERMINAL; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ opt_semi ::= /* nothing */ | SEMI; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ empty ::= /* nothing */; /*----------------------------------------------------------------*/ cup-0.11a+20060608/lib/ 0000755 0001750 0001750 00000000000 11075720101 013762 5 ustar twerner twerner cup-0.11a+20060608/src/ 0000755 0001750 0001750 00000000000 11075720101 014003 5 ustar twerner twerner cup-0.11a+20060608/src/java_cup/ 0000755 0001750 0001750 00000000000 11075720102 015574 5 ustar twerner twerner cup-0.11a+20060608/src/java_cup/lr_item_core.java 0000644 0001750 0001750 00000017565 10250537770 021133 0 ustar twerner twerner package java_cup; /** The "core" of an LR item. This includes a production and the position * of a marker (the "dot") within the production. Typically item cores * are written using a production with an embedded "dot" to indicate their * position. For example:
* A ::= B * C d E ** This represents a point in a parse where the parser is trying to match * the given production, and has succeeded in matching everything before the * "dot" (and hence is expecting to see the symbols after the dot next). See * lalr_item, lalr_item_set, and lalr_start for full details on the meaning * and use of items. * * @see java_cup.lalr_item * @see java_cup.lalr_item_set * @see java_cup.lalr_state * @version last updated: 11/25/95 * @author Scott Hudson */ public class lr_item_core { /*-----------------------------------------------------------*/ /*--- Constructor(s) ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Full constructor. * @param prod production this item uses. * @param pos position of the "dot" within the item. */ public lr_item_core(production prod, int pos) throws internal_error { symbol after_dot = null; production_part part; if (prod == null) throw new internal_error( "Attempt to create an lr_item_core with a null production"); _the_production = prod; if (pos < 0 || pos > _the_production.rhs_length()) throw new internal_error( "Attempt to create an lr_item_core with a bad dot position"); _dot_pos = pos; /* compute and cache hash code now */ _core_hash_cache = 13*_the_production.hashCode() + pos; /* cache the symbol after the dot */ if (_dot_pos < _the_production.rhs_length()) { part = _the_production.rhs(_dot_pos); if (!part.is_action()) _symbol_after_dot = ((symbol_part)part).the_symbol(); } } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Constructor for dot at start of right hand side. * @param prod production this item uses. */ public lr_item_core(production prod) throws internal_error { this(prod,0); } /*-----------------------------------------------------------*/ /*--- (Access to) Instance Variables ------------------------*/ /*-----------------------------------------------------------*/ /** The production for the item. */ protected production _the_production; /** The production for the item. */ public production the_production() {return _the_production;} /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** The position of the "dot" -- this indicates the part of the production * that the marker is before, so 0 indicates a dot at the beginning of * the RHS. */ protected int _dot_pos; /** The position of the "dot" -- this indicates the part of the production * that the marker is before, so 0 indicates a dot at the beginning of * the RHS. */ public int dot_pos() {return _dot_pos;} /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Cache of the hash code. */ protected int _core_hash_cache; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Cache of symbol after the dot. */ protected symbol _symbol_after_dot = null; /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Is the dot at the end of the production? */ public boolean dot_at_end() { return _dot_pos >= _the_production.rhs_length(); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Return the symbol after the dot. If there is no symbol after the dot * we return null. */ public symbol symbol_after_dot() { /* use the cached symbol */ return _symbol_after_dot; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if we have a dot before a non terminal, and if so which one * (return null or the non terminal). */ public non_terminal dot_before_nt() { symbol sym; /* get the symbol after the dot */ sym = symbol_after_dot(); /* if it exists and is a non terminal, return it */ if (sym != null && sym.is_non_term()) return (non_terminal)sym; else return null; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Produce a new lr_item_core that results from shifting the dot one * position to the right. */ public lr_item_core shift_core() throws internal_error { if (dot_at_end()) throw new internal_error( "Attempt to shift past end of an lr_item_core"); return new lr_item_core(_the_production, _dot_pos+1); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Equality comparison for the core only. This is separate out because we * need separate access in a super class. */ public boolean core_equals(lr_item_core other) { return other != null && _the_production.equals(other._the_production) && _dot_pos == other._dot_pos; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Equality comparison. */ public boolean equals(lr_item_core other) {return core_equals(other);} /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Generic equality comparison. */ public boolean equals(Object other) { if (!(other instanceof lr_item_core)) return false; else return equals((lr_item_core)other); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Hash code for the core (separated so we keep non overridden version). */ public int core_hashCode() { return _core_hash_cache; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Hash code for the item. */ public int hashCode() { return _core_hash_cache; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Return the hash code that object would have provided for us so we have * a (nearly) unique id for debugging. */ protected int obj_hash() { return super.hashCode(); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Convert to a string (separated out from toString() so we can call it * from subclass that overrides toString()). */ public String to_simple_string() throws internal_error { String result; production_part part; if (_the_production.lhs() != null && _the_production.lhs().the_symbol() != null && _the_production.lhs().the_symbol().name() != null) result = _the_production.lhs().the_symbol().name(); else result = "$$NULL$$"; result += " ::= "; for (int i = 0; i<_the_production.rhs_length(); i++) { /* do we need the dot before this one? */ if (i == _dot_pos) result += "(*) "; /* print the name of the part */ if (_the_production.rhs(i) == null) { result += "$$NULL$$ "; } else { part = _the_production.rhs(i); if (part == null) result += "$$NULL$$ "; else if (part.is_action()) result += "{ACTION} "; else if (((symbol_part)part).the_symbol() != null && ((symbol_part)part).the_symbol().name() != null) result += ((symbol_part)part).the_symbol().name() + " "; else result += "$$NULL$$ "; } } /* put the dot after if needed */ if (_dot_pos == _the_production.rhs_length()) result += "(*) "; return result; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Convert to a string */ public String toString() { /* can't throw here since super class doesn't, so we crash instead */ try { return to_simple_string(); } catch(internal_error e) { e.crash(); return null; } } /*-----------------------------------------------------------*/ } cup-0.11a+20060608/src/java_cup/terminal_set.java 0000644 0001750 0001750 00000014735 10250537770 021152 0 ustar twerner twerner package java_cup; import java.util.BitSet; /** A set of terminals implemented as a bitset. * @version last updated: 11/25/95 * @author Scott Hudson */ public class terminal_set { /*-----------------------------------------------------------*/ /*--- Constructor(s) ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Constructor for an empty set. */ public terminal_set() { /* allocate the bitset at what is probably the right size */ _elements = new BitSet(terminal.number()); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Constructor for cloning from another set. * @param other the set we are cloning from. */ public terminal_set(terminal_set other) throws internal_error { not_null(other); _elements = (BitSet)other._elements.clone(); } /*-----------------------------------------------------------*/ /*--- (Access to) Static (Class) Variables ------------------*/ /*-----------------------------------------------------------*/ /** Constant for the empty set. */ public static final terminal_set EMPTY = new terminal_set(); /*-----------------------------------------------------------*/ /*--- (Access to) Instance Variables ------------------------*/ /*-----------------------------------------------------------*/ /** Bitset to implement the actual set. */ protected BitSet _elements; /*-----------------------------------------------------------*/ /*--- General Methods ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Helper function to test for a null object and throw an exception if * one is found. * @param obj the object we are testing. */ protected void not_null(Object obj) throws internal_error { if (obj == null) throw new internal_error("Null object used in set operation"); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if the set is empty. */ public boolean empty() { return equals(EMPTY); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if the set contains a particular terminal. * @param sym the terminal symbol we are looking for. */ public boolean contains(terminal sym) throws internal_error { not_null(sym); return _elements.get(sym.index()); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Given its index determine if the set contains a particular terminal. * @param indx the index of the terminal in question. */ public boolean contains(int indx) { return _elements.get(indx); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if this set is an (improper) subset of another. * @param other the set we are testing against. */ public boolean is_subset_of(terminal_set other) throws internal_error { not_null(other); /* make a copy of the other set */ BitSet copy_other = (BitSet)other._elements.clone(); /* and or in */ copy_other.or(_elements); /* if it hasn't changed, we were a subset */ return copy_other.equals(other._elements); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if this set is an (improper) superset of another. * @param other the set we are testing against. */ public boolean is_superset_of(terminal_set other) throws internal_error { not_null(other); return other.is_subset_of(this); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Add a single terminal to the set. * @param sym the terminal being added. * @return true if this changes the set. */ public boolean add(terminal sym) throws internal_error { boolean result; not_null(sym); /* see if we already have this */ result = _elements.get(sym.index()); /* if not we add it */ if (!result) _elements.set(sym.index()); return result; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Remove a terminal if it is in the set. * @param sym the terminal being removed. */ public void remove(terminal sym) throws internal_error { not_null(sym); _elements.clear(sym.index()); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Add (union) in a complete set. * @param other the set being added. * @return true if this changes the set. */ public boolean add(terminal_set other) throws internal_error { not_null(other); /* make a copy */ BitSet copy = (BitSet)_elements.clone(); /* or in the other set */ _elements.or(other._elements); /* changed if we are not the same as the copy */ return !_elements.equals(copy); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Determine if this set intersects another. * @param other the other set in question. */ public boolean intersects(terminal_set other) throws internal_error { not_null(other); /* make a copy of the other set */ BitSet copy = (BitSet)other._elements.clone(); /* xor out our values */ copy.xor(this._elements); /* see if its different */ return !copy.equals(other._elements); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Equality comparison. */ public boolean equals(terminal_set other) { if (other == null) return false; else return _elements.equals(other._elements); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Generic equality comparison. */ public boolean equals(Object other) { if (!(other instanceof terminal_set)) return false; else return equals((terminal_set)other); } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Convert to string. */ public String toString() { String result; boolean comma_flag; result = "{"; comma_flag = false; for (int t = 0; t < terminal.number(); t++) { if (_elements.get(t)) { if (comma_flag) result += ", "; else comma_flag = true; result += terminal.find(t).name(); } } result += "}"; return result; } /*-----------------------------------------------------------*/ } cup-0.11a+20060608/src/java_cup/version.java 0000644 0001750 0001750 00000003644 10441773704 020147 0 ustar twerner twerner package java_cup; /** This class contains version and authorship information. * It contains only static data elements and basically just a central * place to put this kind of information so it can be updated easily * for each release. * * Version numbers used here are broken into 3 parts: major, minor, and * update, and are written as v
lr_parser.scan()
. Integration
* of scanners implementing Scanner
is facilitated.
*
* @version last updated 23-Jul-1999
* @author David MacMahon new Symbol(lr_parser.EOF_sym())
or
null
.
***************************************************/
public interface Scanner {
/** Return the next token, or null
on end-of-file. */
public Symbol next_token() throws java.lang.Exception;
}
cup-0.11a+20060608/src/java_cup/runtime/virtual_parse_stack.java 0000644 0001750 0001750 00000011577 10250537770 024215 0 ustar twerner twerner
package java_cup.runtime;
import java.util.Stack;
/** This class implements a temporary or "virtual" parse stack that
* replaces the top portion of the actual parse stack (the part that
* has been changed by some set of operations) while maintaining its
* original contents. This data structure is used when the parse needs
* to "parse ahead" to determine if a given error recovery attempt will
* allow the parse to continue far enough to consider it successful. Once
* success or failure of parse ahead is determined the system then
* reverts to the original parse stack (which has not actually been
* modified). Since parse ahead does not execute actions, only parse
* state is maintained on the virtual stack, not full Symbol objects.
*
* @see java_cup.runtime.lr_parser
* @version last updated: 7/3/96
* @author Frank Flannery
*/
public class virtual_parse_stack {
/*-----------------------------------------------------------*/
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
/** Constructor to build a virtual stack out of a real stack. */
public virtual_parse_stack(Stack shadowing_stack) throws java.lang.Exception
{
/* sanity check */
if (shadowing_stack == null)
throw new Exception(
"Internal parser error: attempt to create null virtual stack");
/* set up our internals */
real_stack = shadowing_stack;
vstack = new Stack();
real_next = 0;
/* get one element onto the virtual portion of the stack */
get_from_real();
}
/*-----------------------------------------------------------*/
/*--- (Access to) Instance Variables ------------------------*/
/*-----------------------------------------------------------*/
/** The real stack that we shadow. This is accessed when we move off
* the bottom of the virtual portion of the stack, but is always left
* unmodified.
*/
protected Stack real_stack;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Top of stack indicator for where we leave off in the real stack.
* This is measured from top of stack, so 0 would indicate that no
* elements have been "moved" from the real to virtual stack.
*/
protected int real_next;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The virtual top portion of the stack. This stack contains Integer
* objects with state numbers. This stack shadows the top portion
* of the real stack within the area that has been modified (via operations
* on the virtual stack). When this portion of the stack becomes empty we
* transfer elements from the underlying stack onto this stack.
*/
protected Stack vstack;
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/** Transfer an element from the real to the virtual stack. This assumes
* that the virtual stack is currently empty.
*/
protected void get_from_real()
{
Symbol stack_sym;
/* don't transfer if the real stack is empty */
if (real_next >= real_stack.size()) return;
/* get a copy of the first Symbol we have not transfered */
stack_sym = (Symbol)real_stack.elementAt(real_stack.size()-1-real_next);
/* record the transfer */
real_next++;
/* put the state number from the Symbol onto the virtual stack */
vstack.push(new Integer(stack_sym.parse_state));
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Indicate whether the stack is empty. */
public boolean empty()
{
/* if vstack is empty then we were unable to transfer onto it and
the whole thing is empty. */
return vstack.empty();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Return value on the top of the stack (without popping it). */
public int top() throws java.lang.Exception
{
if (vstack.empty())
throw new Exception(
"Internal parser error: top() called on empty virtual stack");
return ((Integer)vstack.peek()).intValue();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Pop the stack. */
public void pop() throws java.lang.Exception
{
if (vstack.empty())
throw new Exception(
"Internal parser error: pop from empty virtual stack");
/* pop it */
vstack.pop();
/* if we are now empty transfer an element (if there is one) */
if (vstack.empty())
get_from_real();
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Push a state number onto the stack. */
public void push(int state_num)
{
vstack.push(new Integer(state_num));
}
/*-----------------------------------------------------------*/
}
cup-0.11a+20060608/src/java_cup/runtime/ComplexSymbolFactory.java 0000644 0001750 0001750 00000007627 10413036260 024263 0 ustar twerner twerner package java_cup.runtime;
/**
* Default Implementation for SymbolFactory, creates
* plain old Symbols
*
* @version last updated 27-03-2006
* @author Michael Petter
*/
/* *************************************************
class DefaultSymbolFactory
interface for creating new symbols
***************************************************/
public class ComplexSymbolFactory implements SymbolFactory{
public static class Location {
private String unit="unknown";
private int line, column;
public Location(String unit, int line, int column){
this.unit=unit;
this.line=line;
this.column=column;
}
public Location(int line, int column){
this.line=line;
this.column=column;
}
public String toString(){
return unit+":"+line+"/"+column;
}
public int getColumn(){
return column;
}
public int getLine(){
return line;
}
public String getUnit(){
return unit;
}
}
/**
* ComplexSymbol with detailed Location Informations and a Name
*/
public static class ComplexSymbol extends Symbol {
protected String name;
protected Location xleft,xright;
public ComplexSymbol(String name, int id) {
super(id);
this.name=name;
}
public ComplexSymbol(String name, int id, Object value) {
super(id,value);
this.name=name;
}
public String toString(){
if (xleft==null || xright==null) return "Symbol: "+name;
return "Symbol: "+name+" ("+xleft+" - "+xright+")";
}
public ComplexSymbol(String name, int id, int state) {
super(id,state);
this.name=name;
}
public ComplexSymbol(String name, int id, Symbol left, Symbol right) {
super(id,left,right);
this.name=name;
if (left!=null) this.xleft = ((ComplexSymbol)left).xleft;
if (right!=null) this.xright= ((ComplexSymbol)right).xright;
}
public ComplexSymbol(String name, int id, Location left, Location right) {
super(id);
this.name=name;
this.xleft=left;
this.xright=right;
}
public ComplexSymbol(String name, int id, Symbol left, Symbol right, Object value) {
super(id,value);
this.name=name;
if (left!=null) this.xleft = ((ComplexSymbol)left).xleft;
if (right!=null) this.xright= ((ComplexSymbol)right).xright;
}
public ComplexSymbol(String name, int id, Location left, Location right, Object value) {
super(id,value);
this.name=name;
this.xleft=left;
this.xright=right;
}
public Location getLeft(){
return xleft;
}
public Location getRight(){
return xright;
}
}
// Factory methods
public Symbol newSymbol(String name, int id, Location left, Location right, Object value){
return new ComplexSymbol(name,id,left,right,value);
}
public Symbol newSymbol(String name, int id, Location left, Location right){
return new ComplexSymbol(name,id,left,right);
}
public Symbol newSymbol(String name, int id, Symbol left, Symbol right, Object value){
return new ComplexSymbol(name,id,left,right,value);
}
public Symbol newSymbol(String name, int id, Symbol left, Symbol right){
return new ComplexSymbol(name,id,left,right);
}
public Symbol newSymbol(String name, int id){
return new ComplexSymbol(name,id);
}
public Symbol newSymbol(String name, int id, Object value){
return new ComplexSymbol(name,id,value);
}
public Symbol startSymbol(String name, int id, int state){
return new ComplexSymbol(name,id,state);
}
}
cup-0.11a+20060608/src/java_cup/runtime/Symbol.java 0000644 0001750 0001750 00000006115 10412217534 021376 0 ustar twerner twerner package java_cup.runtime;
/**
* Defines the Symbol class, which is used to represent all terminals
* and nonterminals while parsing. The lexer should pass CUP Symbols
* and CUP returns a Symbol.
*
* @version last updated: 7/3/96
* @author Frank Flannery
*/
/* ****************************************************************
Class Symbol
what the parser expects to receive from the lexer.
the token is identified as follows:
sym: the symbol type
parse_state: the parse state.
value: is the lexical value of type Object
left : is the left position in the original input file
right: is the right position in the original input file
xleft: is the left position Object in the original input file
xright: is the left position Object in the original input file
******************************************************************/
public class Symbol {
// TUM 20060327: Added new Constructor to provide more flexible way
// for location handling
/*******************************
*******************************/
public Symbol(int id, Symbol left, Symbol right, Object o){
this(id,left.left,right.right,o);
}
public Symbol(int id, Symbol left, Symbol right){
this(id,left.left,right.right);
}
/*******************************
Constructor for l,r values
*******************************/
public Symbol(int id, int l, int r, Object o) {
this(id);
left = l;
right = r;
value = o;
}
/*******************************
Constructor for no l,r values
********************************/
public Symbol(int id, Object o) {
this(id, -1, -1, o);
}
/*****************************
Constructor for no value
***************************/
public Symbol(int id, int l, int r) {
this(id, l, r, null);
}
/***********************************
Constructor for no value or l,r
***********************************/
public Symbol(int sym_num) {
this(sym_num, -1);
left = -1;
right = -1;
}
/***********************************
Constructor to give a start state
***********************************/
Symbol(int sym_num, int state)
{
sym = sym_num;
parse_state = state;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The symbol number of the terminal or non terminal being represented */
public int sym;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The parse state to be recorded on the parse stack with this symbol.
* This field is for the convenience of the parser and shouldn't be
* modified except by the parser.
*/
public int parse_state;
/** This allows us to catch some errors caused by scanners recycling
* symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
boolean used_by_parser = false;
/*******************************
The data passed to parser
*******************************/
public int left, right;
public Object value;
/*****************************
Printing this token out. (Override for pretty-print).
****************************/
public String toString() { return "#"+sym; }
}
cup-0.11a+20060608/src/java_cup/runtime/DefaultSymbolFactory.java 0000644 0001750 0001750 00000003342 10413036260 024226 0 ustar twerner twerner package java_cup.runtime;
/**
* Default Implementation for SymbolFactory, creates
* plain old Symbols
*
* @version last updated 27-03-2006
* @author Michael Petter
*/
/* *************************************************
class DefaultSymbolFactory
interface for creating new symbols
***************************************************/
public class DefaultSymbolFactory implements SymbolFactory{
// Factory methods
/**
* DefaultSymbolFactory for CUP.
* Users are strongly encoraged to use ComplexSymbolFactory instead, since
* it offers more detailed information about Symbols in source code.
* Yet since migrating has always been a critical process, You have the
* chance of still using the oldstyle Symbols.
*
* @deprecated as of CUP v11a
* replaced by the new java_cup.runtime.ComplexSymbolFactory
*/
//@deprecated
public DefaultSymbolFactory(){
}
public Symbol newSymbol(String name ,int id, Symbol left, Symbol right, Object value){
return new Symbol(id,left,right,value);
}
public Symbol newSymbol(String name, int id, Symbol left, Symbol right){
return new Symbol(id,left,right);
}
public Symbol newSymbol(String name, int id, int left, int right, Object value){
return new Symbol(id,left,right,value);
}
public Symbol newSymbol(String name, int id, int left, int right){
return new Symbol(id,left,right);
}
public Symbol startSymbol(String name, int id, int state){
return new Symbol(id,state);
}
public Symbol newSymbol(String name, int id){
return new Symbol(id);
}
public Symbol newSymbol(String name, int id, Object value){
return new Symbol(id,value);
}
}
cup-0.11a+20060608/src/java_cup/runtime/SymbolFactory.java 0000644 0001750 0001750 00000002072 10413036260 022720 0 ustar twerner twerner package java_cup.runtime;
/**
* Creates the Symbols interface, which CUP uses as default
*
* @version last updated 27-03-2006
* @author Michael Petter
*/
/* *************************************************
Interface SymbolFactory
interface for creating new symbols
You can also use this interface for your own callback hooks
Declare Your own factory methods for creation of Objects in Your scanner!
***************************************************/
public interface SymbolFactory {
// Factory methods
/**
* Construction with left/right propagation switched on
*/
public Symbol newSymbol(String name, int id, Symbol left, Symbol right, Object value);
public Symbol newSymbol(String name, int id, Symbol left, Symbol right);
/**
* Construction with left/right propagation switched off
*/
public Symbol newSymbol(String name, int id, Object value);
public Symbol newSymbol(String name, int id);
/**
* Construction of start symbol
*/
public Symbol startSymbol(String name, int id, int state);
}
cup-0.11a+20060608/src/java_cup/runtime/lr_parser.java 0000644 0001750 0001750 00000127426 10412217534 022133 0 ustar twerner twerner
package java_cup.runtime;
import java.util.Stack;
/** This class implements a skeleton table driven LR parser. In general,
* LR parsers are a form of bottom up shift-reduce parsers. Shift-reduce
* parsers act by shifting input onto a parse stack until the Symbols
* matching the right hand side of a production appear on the top of the
* stack. Once this occurs, a reduce is performed. This involves removing
* the Symbols corresponding to the right hand side of the production
* (the so called "handle") and replacing them with the non-terminal from
* the left hand side of the production. * * To control the decision of whether to shift or reduce at any given point, * the parser uses a state machine (the "viable prefix recognition machine" * built by the parser generator). The current state of the machine is placed * on top of the parse stack (stored as part of a Symbol object representing * a terminal or non terminal). The parse action table is consulted * (using the current state and the current lookahead Symbol as indexes) to * determine whether to shift or to reduce. When the parser shifts, it * changes to a new state by pushing a new Symbol (containing a new state) * onto the stack. When the parser reduces, it pops the handle (right hand * side of a production) off the stack. This leaves the parser in the state * it was in before any of those Symbols were matched. Next the reduce-goto * table is consulted (using the new state and current lookahead Symbol as * indexes) to determine a new state to go to. The parser then shifts to * this goto state by pushing the left hand side Symbol of the production * (also containing the new state) onto the stack.
* * This class actually provides four LR parsers. The methods parse() and * debug_parse() provide two versions of the main parser (the only difference * being that debug_parse() emits debugging trace messages as it parses). * In addition to these main parsers, the error recovery mechanism uses two * more. One of these is used to simulate "parsing ahead" in the input * without carrying out actions (to verify that a potential error recovery * has worked), and the other is used to parse through buffered "parse ahead" * input in order to execute all actions and re-synchronize the actual parser * configuration.
* * This is an abstract class which is normally filled out by a subclass * generated by the JavaCup parser generator. In addition to supplying * the actual parse tables, generated code also supplies methods which * invoke various pieces of user supplied code, provide access to certain * special Symbols (e.g., EOF and error), etc. Specifically, the following * abstract methods are normally supplied by generated code: *