From b0ae87ec1f7bd2d6645e5c3900f4eca00f2b1498 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 3 Feb 2006 01:17:14 +0000 Subject: [PATCH] Checking in stuff --- Robust/cup/gnuwin/README | 30 + Robust/cup/gnuwin/makefile | 26 + Robust/cup/java_cup/CUP$parser$actions.class | Bin 0 -> 15583 bytes Robust/cup/java_cup/Main.class | Bin 0 -> 14758 bytes Robust/cup/java_cup/Main.java | 854 ++++++++ Robust/cup/java_cup/action_part.class | Bin 0 -> 1107 bytes Robust/cup/java_cup/action_part.java | 93 + Robust/cup/java_cup/action_production.class | Bin 0 -> 604 bytes Robust/cup/java_cup/action_production.java | 39 + Robust/cup/java_cup/assoc.class | Bin 0 -> 333 bytes Robust/cup/java_cup/assoc.java | 16 + Robust/cup/java_cup/emit.class | Bin 0 -> 13997 bytes Robust/cup/java_cup/emit.java | 897 +++++++++ Robust/cup/java_cup/internal_error.class | Bin 0 -> 580 bytes Robust/cup/java_cup/internal_error.java | 22 + Robust/cup/java_cup/lalr_item.class | Bin 0 -> 3745 bytes Robust/cup/java_cup/lalr_item.java | 330 ++++ Robust/cup/java_cup/lalr_item_set.class | Bin 0 -> 3945 bytes Robust/cup/java_cup/lalr_item_set.java | 371 ++++ Robust/cup/java_cup/lalr_state.class | Bin 0 -> 9712 bytes Robust/cup/java_cup/lalr_state.java | 884 +++++++++ Robust/cup/java_cup/lalr_transition.class | Bin 0 -> 1508 bytes Robust/cup/java_cup/lalr_transition.java | 93 + Robust/cup/java_cup/lexer.class | Bin 0 -> 5298 bytes Robust/cup/java_cup/lexer.java | 543 +++++ Robust/cup/java_cup/lr_item_core.class | Bin 0 -> 3162 bytes Robust/cup/java_cup/lr_item_core.java | 280 +++ Robust/cup/java_cup/non_terminal.class | Bin 0 -> 3771 bytes Robust/cup/java_cup/non_terminal.java | 301 +++ Robust/cup/java_cup/nonassoc_action.class | Bin 0 -> 675 bytes Robust/cup/java_cup/nonassoc_action.java | 71 + Robust/cup/java_cup/parse_action.class | Bin 0 -> 740 bytes Robust/cup/java_cup/parse_action.java | 92 + Robust/cup/java_cup/parse_action_row.class | Bin 0 -> 1035 bytes Robust/cup/java_cup/parse_action_row.java | 106 + Robust/cup/java_cup/parse_action_table.class | Bin 0 -> 2262 bytes Robust/cup/java_cup/parse_action_table.java | 143 ++ Robust/cup/java_cup/parse_reduce_row.class | Bin 0 -> 529 bytes Robust/cup/java_cup/parse_reduce_row.java | 41 + Robust/cup/java_cup/parse_reduce_table.class | Bin 0 -> 1295 bytes Robust/cup/java_cup/parse_reduce_table.java | 99 + Robust/cup/java_cup/parser.class | Bin 0 -> 7471 bytes Robust/cup/java_cup/parser.cup | 863 ++++++++ Robust/cup/java_cup/parser.java | 1849 ++++++++++++++++++ Robust/cup/java_cup/production.class | Bin 0 -> 8092 bytes Robust/cup/java_cup/production.java | 756 +++++++ Robust/cup/java_cup/production_part.class | Bin 0 -> 966 bytes Robust/cup/java_cup/production_part.java | 94 + Robust/cup/java_cup/reduce_action.class | Bin 0 -> 1218 bytes Robust/cup/java_cup/reduce_action.java | 84 + Robust/cup/java_cup/shift_action.class | Bin 0 -> 1199 bytes Robust/cup/java_cup/shift_action.java | 82 + Robust/cup/java_cup/sym.class | Bin 0 -> 1111 bytes Robust/cup/java_cup/sym.java | 43 + Robust/cup/java_cup/symbol.class | Bin 0 -> 925 bytes Robust/cup/java_cup/symbol.java | 107 + Robust/cup/java_cup/symbol_part.class | Bin 0 -> 1431 bytes Robust/cup/java_cup/symbol_part.java | 100 + Robust/cup/java_cup/symbol_set.class | Bin 0 -> 2612 bytes Robust/cup/java_cup/symbol_set.java | 231 +++ Robust/cup/java_cup/terminal.class | Bin 0 -> 2196 bytes Robust/cup/java_cup/terminal.java | 169 ++ Robust/cup/java_cup/terminal_set.class | Bin 0 -> 2459 bytes Robust/cup/java_cup/terminal_set.java | 253 +++ Robust/cup/java_cup/version.class | Bin 0 -> 549 bytes Robust/cup/java_cup/version.java | 55 + Robust/cup/winnt/README | 17 + Robust/cup/winnt/makefile | 51 + Robust/src/Makefile | 21 + 69 files changed, 10106 insertions(+) create mode 100644 Robust/cup/gnuwin/README create mode 100644 Robust/cup/gnuwin/makefile create mode 100644 Robust/cup/java_cup/CUP$parser$actions.class create mode 100644 Robust/cup/java_cup/Main.class create mode 100644 Robust/cup/java_cup/Main.java create mode 100644 Robust/cup/java_cup/action_part.class create mode 100644 Robust/cup/java_cup/action_part.java create mode 100644 Robust/cup/java_cup/action_production.class create mode 100644 Robust/cup/java_cup/action_production.java create mode 100644 Robust/cup/java_cup/assoc.class create mode 100644 Robust/cup/java_cup/assoc.java create mode 100644 Robust/cup/java_cup/emit.class create mode 100644 Robust/cup/java_cup/emit.java create mode 100644 Robust/cup/java_cup/internal_error.class create mode 100644 Robust/cup/java_cup/internal_error.java create mode 100644 Robust/cup/java_cup/lalr_item.class create mode 100644 Robust/cup/java_cup/lalr_item.java create mode 100644 Robust/cup/java_cup/lalr_item_set.class create mode 100644 Robust/cup/java_cup/lalr_item_set.java create mode 100644 Robust/cup/java_cup/lalr_state.class create mode 100644 Robust/cup/java_cup/lalr_state.java create mode 100644 Robust/cup/java_cup/lalr_transition.class create mode 100644 Robust/cup/java_cup/lalr_transition.java create mode 100644 Robust/cup/java_cup/lexer.class create mode 100644 Robust/cup/java_cup/lexer.java create mode 100644 Robust/cup/java_cup/lr_item_core.class create mode 100644 Robust/cup/java_cup/lr_item_core.java create mode 100644 Robust/cup/java_cup/non_terminal.class create mode 100644 Robust/cup/java_cup/non_terminal.java create mode 100644 Robust/cup/java_cup/nonassoc_action.class create mode 100644 Robust/cup/java_cup/nonassoc_action.java create mode 100644 Robust/cup/java_cup/parse_action.class create mode 100644 Robust/cup/java_cup/parse_action.java create mode 100644 Robust/cup/java_cup/parse_action_row.class create mode 100644 Robust/cup/java_cup/parse_action_row.java create mode 100644 Robust/cup/java_cup/parse_action_table.class create mode 100644 Robust/cup/java_cup/parse_action_table.java create mode 100644 Robust/cup/java_cup/parse_reduce_row.class create mode 100644 Robust/cup/java_cup/parse_reduce_row.java create mode 100644 Robust/cup/java_cup/parse_reduce_table.class create mode 100644 Robust/cup/java_cup/parse_reduce_table.java create mode 100644 Robust/cup/java_cup/parser.class create mode 100644 Robust/cup/java_cup/parser.cup create mode 100644 Robust/cup/java_cup/parser.java create mode 100644 Robust/cup/java_cup/production.class create mode 100644 Robust/cup/java_cup/production.java create mode 100644 Robust/cup/java_cup/production_part.class create mode 100644 Robust/cup/java_cup/production_part.java create mode 100644 Robust/cup/java_cup/reduce_action.class create mode 100644 Robust/cup/java_cup/reduce_action.java create mode 100644 Robust/cup/java_cup/shift_action.class create mode 100644 Robust/cup/java_cup/shift_action.java create mode 100644 Robust/cup/java_cup/sym.class create mode 100644 Robust/cup/java_cup/sym.java create mode 100644 Robust/cup/java_cup/symbol.class create mode 100644 Robust/cup/java_cup/symbol.java create mode 100644 Robust/cup/java_cup/symbol_part.class create mode 100644 Robust/cup/java_cup/symbol_part.java create mode 100644 Robust/cup/java_cup/symbol_set.class create mode 100644 Robust/cup/java_cup/symbol_set.java create mode 100644 Robust/cup/java_cup/terminal.class create mode 100644 Robust/cup/java_cup/terminal.java create mode 100644 Robust/cup/java_cup/terminal_set.class create mode 100644 Robust/cup/java_cup/terminal_set.java create mode 100644 Robust/cup/java_cup/version.class create mode 100644 Robust/cup/java_cup/version.java create mode 100644 Robust/cup/winnt/README create mode 100644 Robust/cup/winnt/makefile create mode 100644 Robust/src/Makefile diff --git a/Robust/cup/gnuwin/README b/Robust/cup/gnuwin/README new file mode 100644 index 00000000..53a94987 --- /dev/null +++ b/Robust/cup/gnuwin/README @@ -0,0 +1,30 @@ +Date: Fri, 05 Feb 1999 17:11:08 -0600 +From: jon miner +To: cananian@alumni.princeton.edu +Subject: Makefile for NT/DOS + +I've made (hah) a Makefile for java_cup that will install and test java_cup +on NT/9x/DOS with GNU Make... + +You (should) find it attached. + +thanks, + +jon + +------------------------------------------------------------- +Date: Sun, 07 Feb 1999 17:30:33 -0600 +From: Jon Miner +To: C. Scott Ananian +Subject: Re: Makefile for NT/DOS + +The Makefile included is for Microsoft's (I think) Nmake... it doesn't +jive with just plain old GNU make (At least not on my machine..) Also, the +Makefile I wrote _should_ (I haven't tested it, though) work (with minor +changes) on Un*x and WinTel machines... + +thanks, + +jon + +[The makefile has been included in this directory. -- CSA 24-Mar-1998 ] diff --git a/Robust/cup/gnuwin/makefile b/Robust/cup/gnuwin/makefile new file mode 100644 index 00000000..30f00d21 --- /dev/null +++ b/Robust/cup/gnuwin/makefile @@ -0,0 +1,26 @@ +SIMPLEDIR=SIMPLE~1 +# SIMPLEDIR=simple_calc +RM=del +# RM=rm +JAVA=java +JAVAOPTS= +JAVAC=javac +JAVACOPTS=-verbose + + +test: java_cup\\Main.class java_cup\\$(SIMPLEDIR)\\Main.class + echo "1*-2+2;" | $(JAVA) $(JAVAOPTS) java_cup.simple_calc.Main + + echo 'If the line above says "= 0" everything is OK.' + + +java_cup\\Main.class: + $(JAVAC) $(JAVACOPTS) java_cup\\Main.java + +java_cup\\$(SIMPLEDIR)\\Main.class: + cd java_cup + cd $(SIMPLEDIR) + echo $(RM) parser.java + echo $(RM) sym.java + $(JAVA) $(JAVAOPTS) java_cup.Main < parser.cup + $(JAVAC) $(JAVACOPTS) Main.java diff --git a/Robust/cup/java_cup/CUP$parser$actions.class b/Robust/cup/java_cup/CUP$parser$actions.class new file mode 100644 index 0000000000000000000000000000000000000000..79416853b16d91deed0d225981d03f5a84c3079c GIT binary patch literal 15583 zcmd5@34Bvk)<1WBFUd=qrb*MZX`3PllvPo{BFJKq9i*V*Rzn-0+NQNlS!7&r+}FW< zcT^NaK|pC$L_03vIDU>B-glP&J?GqW&r9kv zKR^5^031M$u|pZ$uE8C4ps+%H+-ZZwaF+%vby#Hw33sdUY8~!T*L&^I1J>xUR)hQO z;DUAPW4-#=pq|{Xcpgw68*R`A?K(VYhlk){HM7YMJ>d}@HtX=H29Mbx2pu~7#STkg zoqGPb22W`4q*Aj^gQpa?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8@fx>YvQzsgqnoLo$wm#5Pg5}14mQPh7dz5+H>jtjT^ZJJo(QYqqaqE%vo6W`Bh(w7<@l z+TUbsWoe|CJ$ZZkN$-SD$JjNWX8F^t`5Ok%5yW7s{$32co~ z!`2#Svj>dJSi8~A9x@(gj~bg6sXAtj|GlZAt4CDQCPT~V|YWR?x zdHmp<%lWXJEBK)~SMyOhkMhwuf8mumPx2#jw($u$@A64*7oXzJ7-xwu1fm-A)0*YQ8*-onqxeVAXE`zXIS_kDh8 z?nnHJ+)w#co_v0dC%|v?1o_RLN`9+n0$<^o%fF=3jfy=HGa);NN=hE!@u|5$N%MhmH*`3E~s~h;66=A zpItb7PT}+o6*;~`gx7bd$oEYZe%}cq;5$zg`7RV8-zB1lZ@K8{dsyu6+bsI|I`CwD zK@9Zm7K8Kc;=p{T7?$rAhvfUji2PAvWd0a2Hve#Oc>ZirnI92H7pDr5xGeyilTP*aS zAr||WiPQb(h%^0b#4`Unai0Hvae@C0agl$gxZMAiSYF@|R~ER$bp^TNhJp%lQ^81a zTft~?N5PR|ML}5HRdA75RdA_TQ}8FTuHZ(oq2NjJK*3h=P{A`|Q^9ueNWsVA(STQU z1pMNuK%sa#&`UfMm?oYL94TH1%n~mJBI4yhtN2IY7V&D}Ht}X)h1eCiPrMa)RlF0} zE|Hcf_AQzr2NqSy!9{Yl7QlB)CJK z9NaBW34S5#i-~L~_R7ZMLfKT@LpB%pma*dLa$)gIxwLq;JiYjId1moh@|@y7%JYiv zkrx!Nm6sN;mzNj6E|(X-DX%HsC9f;7$s0-xd230Iysc!oyrX1GChY`Qii<4=kS{299&3b*|q Dx=#Gp literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/Main.class b/Robust/cup/java_cup/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..fb7c76448ccae81ebe0dccac95424f79ba48e445 GIT binary patch literal 14758 zcmb7K34B!b@t>JZ*q6=Y3ilNrQRGZew4w=e7RqI925J^=Ok7^IAt<|>H+S)_?+fsYl+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SvNoF{p(oKQ<_E&^HyMZ1+$MY9Y!` z3<^B(ZN(@%JQRaki1Jf|0;jya7^TufIYeS_8x-7NhZLjyOi^%=&F#lK2J~k|JNxru zuy+mE&x^o*Q4ID=1NMs|u=k3=er3SkD+2p z)+@UUBX5Z2VlF%2y?0U{$8y-;jOWCC~CZvY&r1&r4rg(`kuTb`vc+CE^~k7#?4wm&rO zkF_1Fc(AryQKL@llrqnwD`l&qCQGFi4?=`P%JCW)?4UnZ{7Gx2Iw7dGqDLDC(D=x2 ze1t2&A1nS0IO9(TmU&|?sFFN}j4ssms+^X*HuW);Ty1>+- zI2Z4s(+UjWZ{T65dizhb(n){!;?<8`-a2T{u#$7FHWS}zBIF9|S7~1akVy8RN*RL48&w>46AJVq zE6|(z1^UvAKm{#EeN~`8wrc=21_sgkz+l=C7)tjBhS4t6_XbALzCb0t7#Kz03sljY zfurf|z-aCnIEDuW#&A_&EY}3a^9r=r1Sayifhuke)Nm{?sUUJI(_e(Urb7=v1@u-E z>7-|#qPrF#NM1O>3z7$+;s(i!#v}Q3|HS3E+!#?{C85AnB=VlQhpNX9n~Vr@C)s8Q z2}+Hl(AmKn{`6zmMaXEx>-oh`R(lPcM8QBE^$$#=%D{9Q9XN%?24>Q6fm5kAFq;+z z=FrN(TsjBsroidYUHpdKWBYh>uOJhFBZzgU(kPw_;s+CW29{7+U@27uK976fvK)b5 zdjz7$R0WZo8HHyko{@MK<5`MlHlC??#^9L&xKfnM@vJOEau!c-JQa8b;yD`65Ii^F zxe3p0c(&u&fu|DBL;1CzM?)d-rLewbxS+0pB+j5dbSCwuH8hyk(r`ML9BM!^w28*j zI+{r9=~!GwPe5|>B-%(*X*12B3y}i7h)$=AX(3$-YL|o3m7ww^WNWSgh3kNQJ*2f9 Ia|y5bf0)CiegFUf literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/Main.java b/Robust/cup/java_cup/Main.java new file mode 100644 index 00000000..50811b53 --- /dev/null +++ b/Robust/cup/java_cup/Main.java @@ -0,0 +1,854 @@ + +package java_cup; + +import java.util.Enumeration; +import java.io.*; + +/** This class serves as the main driver for the JavaCup system. + * It accepts user options and coordinates overall control flow. + * The main flow of control includes the following activities: + *
    + *
  • Parse user supplied arguments and options. + *
  • Open output files. + *
  • Parse the specification from standard input. + *
  • Check for unused terminals, non-terminals, and productions. + *
  • Build the state machine, tables, etc. + *
  • Output the generated code. + *
  • Close output files. + *
  • Print a summary if requested. + *
+ * + * Options to the main program include:
+ *
-package name + *
specify package generated classes go in [default none] + *
-parser name + *
specify parser class name [default "parser"] + *
-symbols name + *
specify name for symbol constant class [default "sym"] + *
-interface + *
emit symbol constant interface, rather than class + *
-nonterms + *
put non terminals in symbol constant class + *
-expect # + *
number of conflicts expected/allowed [default 0] + *
-compact_red + *
compact tables by defaulting to most frequent reduce + *
-nowarn + *
don't warn about useless productions, etc. + *
-nosummary + *
don't print the usual summary of parse states, etc. + *
-progress + *
print messages to indicate progress of the system + *
-time + *
print time usage summary + *
-dump_grammar + *
produce a dump of the symbols and grammar + *
-dump_states + *
produce a dump of parse state machine + *
-dump_tables + *
produce a dump of the parse tables + *
-dump + *
produce a dump of all of the above + *
-debug + *
turn on debugging messages within JavaCup + *
-nopositions + *
don't generate the positions code + *
-noscanner + *
don't refer to java_cup.runtime.Scanner in the parser + * (for compatibility with old runtimes) + *
-version + *
print version information for JavaCUP and halt. + *
+ * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class Main { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + /** Only constructor is private, so we do not allocate any instances of this + class. */ + private Main() { } + + /*-------------------------*/ + /* Options set by the user */ + /*-------------------------*/ + /** User option -- do we print progress messages. */ + protected static boolean print_progress = true; + /** User option -- do we produce a dump of the state machine */ + protected static boolean opt_dump_states = false; + /** User option -- do we produce a dump of the parse tables */ + protected static boolean opt_dump_tables = false; + /** User option -- do we produce a dump of the grammar */ + protected static boolean opt_dump_grammar = false; + /** User option -- do we show timing information as a part of the summary */ + protected static boolean opt_show_timing = false; + /** User option -- do we run produce extra debugging messages */ + protected static boolean opt_do_debug = false; + /** User option -- do we compact tables by making most common reduce the + default action */ + protected static boolean opt_compact_red = false; + /** User option -- should we include non terminal symbol numbers in the + symbol constant class. */ + protected static boolean include_non_terms = false; + /** User option -- do not print a summary. */ + protected static boolean no_summary = false; + /** User option -- number of conflicts to expect */ + protected static int expect_conflicts = 0; + + /* frankf added this 6/18/96 */ + /** User option -- should generator generate code for left/right values? */ + protected static boolean lr_values = true; + + /** User option -- should symbols be put in a class or an interface? [CSA]*/ + protected static boolean sym_interface = false; + + /** User option -- should generator suppress references to + * java_cup.runtime.Scanner for compatibility with old runtimes? */ + protected static boolean suppress_scanner = false; + + /*----------------------------------------------------------------------*/ + /* Timing data (not all of these time intervals are mutually exclusive) */ + /*----------------------------------------------------------------------*/ + /** Timing data -- when did we start */ + protected static long start_time = 0; + /** Timing data -- when did we end preliminaries */ + protected static long prelim_end = 0; + /** Timing data -- when did we end parsing */ + protected static long parse_end = 0; + /** Timing data -- when did we end checking */ + protected static long check_end = 0; + /** Timing data -- when did we end dumping */ + protected static long dump_end = 0; + /** Timing data -- when did we end state and table building */ + protected static long build_end = 0; + /** Timing data -- when did we end nullability calculation */ + protected static long nullability_end = 0; + /** Timing data -- when did we end first set calculation */ + protected static long first_end = 0; + /** Timing data -- when did we end state machine construction */ + protected static long machine_end = 0; + /** Timing data -- when did we end table construction */ + protected static long table_end = 0; + /** Timing data -- when did we end checking for non-reduced productions */ + protected static long reduce_check_end = 0; + /** Timing data -- when did we finish emitting code */ + protected static long emit_end = 0; + /** Timing data -- when were we completely done */ + protected static long final_time = 0; + + /* Additional timing information is also collected in emit */ + + /*-----------------------------------------------------------*/ + /*--- Main Program ------------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The main driver for the system. + * @param argv an array of strings containing command line arguments. + */ + public static void main(String argv[]) + throws internal_error, java.io.IOException, java.lang.Exception + { + boolean did_output = false; + + start_time = System.currentTimeMillis(); + + /* process user options and arguments */ + parse_args(argv); + + /* frankf 6/18/96 + hackish, yes, but works */ + emit.set_lr_values(lr_values); + /* open output files */ + if (print_progress) System.err.println("Opening files..."); + /* use a buffered version of standard input */ + input_file = new BufferedInputStream(System.in); + + prelim_end = System.currentTimeMillis(); + + /* parse spec into internal data structures */ + if (print_progress) + System.err.println("Parsing specification from standard input..."); + parse_grammar_spec(); + + parse_end = System.currentTimeMillis(); + + /* don't proceed unless we are error free */ + if (lexer.error_count == 0) + { + /* check for unused bits */ + if (print_progress) System.err.println("Checking specification..."); + check_unused(); + + check_end = System.currentTimeMillis(); + + /* build the state machine and parse tables */ + if (print_progress) System.err.println("Building parse tables..."); + build_parser(); + + build_end = System.currentTimeMillis(); + + /* output the generated code, if # of conflicts permits */ + if (lexer.error_count != 0) { + // conflicts! don't emit code, don't dump tables. + opt_dump_tables = false; + } else { // everything's okay, emit parser. + if (print_progress) System.err.println("Writing parser..."); + open_files(); + emit_parser(); + did_output = true; + } + } + /* fix up the times to make the summary easier */ + emit_end = System.currentTimeMillis(); + + /* do requested dumps */ + if (opt_dump_grammar) dump_grammar(); + if (opt_dump_states) dump_machine(); + if (opt_dump_tables) dump_tables(); + + dump_end = System.currentTimeMillis(); + + /* close input/output files */ + if (print_progress) System.err.println("Closing files..."); + close_files(); + + /* produce a summary if desired */ + if (!no_summary) emit_summary(did_output); + + /* If there were errors during the run, + * exit with non-zero status (makefile-friendliness). --CSA */ + if (lexer.error_count != 0) + System.exit(100); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Print a "usage message" that described possible command line options, + * then exit. + * @param message a specific error message to preface the usage message by. + */ + protected static void usage(String message) + { + System.err.println(); + System.err.println(message); + System.err.println(); + System.err.println( +"Usage: " + version.program_name + " [options] [filename]\n" + +" and expects a specification file on standard input if no filename is given.\n" + +" Legal options include:\n" + +" -package name specify package generated classes go in [default none]\n" + +" -parser name specify parser class name [default \"parser\"]\n" + +" -symbols name specify name for symbol constant class [default \"sym\"]\n"+ +" -interface put symbols in an interface, rather than a class\n" + +" -nonterms put non terminals in symbol constant class\n" + +" -expect # number of conflicts expected/allowed [default 0]\n" + +" -compact_red compact tables by defaulting to most frequent reduce\n" + +" -nowarn don't warn about useless productions, etc.\n" + +" -nosummary don't print the usual summary of parse states, etc.\n" + +" -nopositions don't propagate the left and right token position values\n" + +" -noscanner don't refer to java_cup.runtime.Scanner\n" + +" -progress print messages to indicate progress of the system\n" + +" -time print time usage summary\n" + +" -dump_grammar produce a human readable dump of the symbols and grammar\n"+ +" -dump_states produce a dump of parse state machine\n"+ +" -dump_tables produce a dump of the parse tables\n"+ +" -dump produce a dump of all of the above\n"+ +" -version print the version information for CUP and exit\n" + ); + System.exit(1); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Parse command line options and arguments to set various user-option + * flags and variables. + * @param argv the command line arguments to be parsed. + */ + protected static void parse_args(String argv[]) + { + int len = argv.length; + int i; + + /* parse the options */ + for (i=0; i= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-package must have a name argument"); + + /* record the name */ + emit.package_name = argv[i]; + } + else if (argv[i].equals("-parser")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-parser must have a name argument"); + + /* record the name */ + emit.parser_class_name = argv[i]; + } + else if (argv[i].equals("-symbols")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-symbols must have a name argument"); + + /* record the name */ + emit.symbol_const_class_name = argv[i]; + } + else if (argv[i].equals("-nonterms")) + { + include_non_terms = true; + } + else if (argv[i].equals("-expect")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-expect must have a name argument"); + + /* record the number */ + try { + expect_conflicts = Integer.parseInt(argv[i]); + } catch (NumberFormatException e) { + usage("-expect must be followed by a decimal integer"); + } + } + else if (argv[i].equals("-compact_red")) opt_compact_red = true; + else if (argv[i].equals("-nosummary")) no_summary = true; + else if (argv[i].equals("-nowarn")) emit.nowarn = true; + else if (argv[i].equals("-dump_states")) opt_dump_states = true; + else if (argv[i].equals("-dump_tables")) opt_dump_tables = true; + else if (argv[i].equals("-progress")) print_progress = true; + else if (argv[i].equals("-dump_grammar")) opt_dump_grammar = true; + else if (argv[i].equals("-dump")) + opt_dump_states = opt_dump_tables = opt_dump_grammar = true; + else if (argv[i].equals("-time")) opt_show_timing = true; + else if (argv[i].equals("-debug")) opt_do_debug = true; + /* frankf 6/18/96 */ + else if (argv[i].equals("-nopositions")) lr_values = false; + /* CSA 12/21/97 */ + else if (argv[i].equals("-interface")) sym_interface = true; + /* CSA 23-Jul-1999 */ + else if (argv[i].equals("-noscanner")) suppress_scanner = true; + /* CSA 23-Jul-1999 */ + else if (argv[i].equals("-version")) { + System.out.println(version.title_str); + System.exit(1); + } + /* CSA 24-Jul-1999; suggestion by Jean Vaucher */ + else if (!argv[i].startsWith("-") && i==len-1) { + /* use input from file. */ + try { + System.setIn(new FileInputStream(argv[i])); + } catch (java.io.FileNotFoundException e) { + usage("Unable to open \"" + argv[i] +"\" for input"); + } + } + else + { + usage("Unrecognized option \"" + argv[i] + "\""); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /*-------*/ + /* Files */ + /*-------*/ + + /** Input file. This is a buffered version of System.in. */ + protected static BufferedInputStream input_file; + + /** Output file for the parser class. */ + protected static PrintWriter parser_class_file; + + /** Output file for the symbol constant class. */ + protected static PrintWriter symbol_class_file; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Open various files used by the system. */ + protected static void open_files() + { + File fil; + String out_name; + + /* open each of the output files */ + + /* parser class */ + out_name = emit.parser_class_name + ".java"; + fil = new File(out_name); + try { + parser_class_file = new PrintWriter( + new BufferedOutputStream(new FileOutputStream(fil), 4096)); + } catch(Exception e) { + System.err.println("Can't open \"" + out_name + "\" for output"); + System.exit(3); + } + + /* symbol constants class */ + out_name = emit.symbol_const_class_name + ".java"; + fil = new File(out_name); + try { + symbol_class_file = new PrintWriter( + new BufferedOutputStream(new FileOutputStream(fil), 4096)); + } catch(Exception e) { + System.err.println("Can't open \"" + out_name + "\" for output"); + System.exit(4); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Close various files used by the system. */ + protected static void close_files() throws java.io.IOException + { + if (input_file != null) input_file.close(); + if (parser_class_file != null) parser_class_file.close(); + if (symbol_class_file != null) symbol_class_file.close(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Parse the grammar specification from standard input. This produces + * sets of terminal, non-terminals, and productions which can be accessed + * via static variables of the respective classes, as well as the setting + * of various variables (mostly in the emit class) for small user supplied + * items such as the code to scan with. + */ + protected static void parse_grammar_spec() throws java.lang.Exception + { + parser parser_obj; + + /* create a parser and parse with it */ + parser_obj = new parser(); + try { + if (opt_do_debug) + parser_obj.debug_parse(); + else + parser_obj.parse(); + } catch (Exception e) + { + /* something threw an exception. catch it and emit a message so we + have a line number to work with, then re-throw it */ + lexer.emit_error("Internal error: Unexpected exception"); + throw e; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Check for unused symbols. Unreduced productions get checked when + * tables are created. + */ + protected static void check_unused() + { + terminal term; + non_terminal nt; + + /* check for unused terminals */ + for (Enumeration t = terminal.all(); t.hasMoreElements(); ) + { + term = (terminal)t.nextElement(); + + /* don't issue a message for EOF */ + if (term == terminal.EOF) continue; + + /* or error */ + if (term == terminal.error) continue; + + /* is this one unused */ + if (term.use_count() == 0) + { + /* count it and warn if we are doing warnings */ + emit.unused_term++; + if (!emit.nowarn) + { + System.err.println("Warning: Terminal \"" + term.name() + + "\" was declared but never used"); + lexer.warning_count++; + } + } + } + + /* check for unused non terminals */ + for (Enumeration n = non_terminal.all(); n.hasMoreElements(); ) + { + nt = (non_terminal)n.nextElement(); + + /* is this one unused */ + if (nt.use_count() == 0) + { + /* count and warn if we are doing warnings */ + emit.unused_term++; + if (!emit.nowarn) + { + System.err.println("Warning: Non terminal \"" + nt.name() + + "\" was declared but never used"); + lexer.warning_count++; + } + } + } + + } + + /* . . . . . . . . . . . . . . . . . . . . . . . . .*/ + /* . . Internal Results of Generating the Parser . .*/ + /* . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Start state in the overall state machine. */ + protected static lalr_state start_state; + + /** Resulting parse action table. */ + protected static parse_action_table action_table; + + /** Resulting reduce-goto table. */ + protected static parse_reduce_table reduce_table; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Build the (internal) parser from the previously parsed specification. + * This includes:
    + *
  • Computing nullability of non-terminals. + *
  • Computing first sets of non-terminals and productions. + *
  • Building the viable prefix recognizer machine. + *
  • Filling in the (internal) parse tables. + *
  • Checking for unreduced productions. + *
+ */ + protected static void build_parser() throws internal_error + { + /* compute nullability of all non terminals */ + if (opt_do_debug || print_progress) + System.err.println(" Computing non-terminal nullability..."); + non_terminal.compute_nullability(); + + nullability_end = System.currentTimeMillis(); + + /* compute first sets of all non terminals */ + if (opt_do_debug || print_progress) + System.err.println(" Computing first sets..."); + non_terminal.compute_first_sets(); + + first_end = System.currentTimeMillis(); + + /* build the LR viable prefix recognition machine */ + if (opt_do_debug || print_progress) + System.err.println(" Building state machine..."); + start_state = lalr_state.build_machine(emit.start_production); + + machine_end = System.currentTimeMillis(); + + /* build the LR parser action and reduce-goto tables */ + if (opt_do_debug || print_progress) + System.err.println(" Filling in tables..."); + action_table = new parse_action_table(); + reduce_table = new parse_reduce_table(); + for (Enumeration st = lalr_state.all(); st.hasMoreElements(); ) + { + lalr_state lst = (lalr_state)st.nextElement(); + lst.build_table_entries( + action_table, reduce_table); + } + + table_end = System.currentTimeMillis(); + + /* check and warn for non-reduced productions */ + if (opt_do_debug || print_progress) + System.err.println(" Checking for non-reduced productions..."); + action_table.check_reductions(); + + reduce_check_end = System.currentTimeMillis(); + + /* if we have more conflicts than we expected issue a message and die */ + if (emit.num_conflicts > expect_conflicts) + { + System.err.println("*** More conflicts encountered than expected " + + "-- parser generation aborted"); + lexer.error_count++; // indicate the problem. + // we'll die on return, after clean up. + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Call the emit routines necessary to write out the generated parser. */ + protected static void emit_parser() throws internal_error + { + emit.symbols(symbol_class_file, include_non_terms, sym_interface); + emit.parser(parser_class_file, action_table, reduce_table, + start_state.index(), emit.start_production, opt_compact_red, + suppress_scanner); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to optionally return a plural or non-plural ending. + * @param val the numerical value determining plurality. + */ + protected static String plural(int val) + { + if (val == 1) + return ""; + else + return "s"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a long summary message to standard error (System.err) which + * summarizes what was found in the specification, how many states were + * produced, how many conflicts were found, etc. A detailed timing + * summary is also produced if it was requested by the user. + * @param output_produced did the system get far enough to generate code. + */ + protected static void emit_summary(boolean output_produced) + { + final_time = System.currentTimeMillis(); + + if (no_summary) return; + + System.err.println("------- " + version.title_str + + " Parser Generation Summary -------"); + + /* error and warning count */ + System.err.println(" " + lexer.error_count + " error" + + plural(lexer.error_count) + " and " + lexer.warning_count + + " warning" + plural(lexer.warning_count)); + + /* basic stats */ + System.err.print(" " + terminal.number() + " terminal" + + plural(terminal.number()) + ", "); + System.err.print(non_terminal.number() + " non-terminal" + + plural(non_terminal.number()) + ", and "); + System.err.println(production.number() + " production" + + plural(production.number()) + " declared, "); + System.err.println(" producing " + lalr_state.number() + + " unique parse states."); + + /* unused symbols */ + System.err.println(" " + emit.unused_term + " terminal" + + plural(emit.unused_term) + " declared but not used."); + System.err.println(" " + emit.unused_non_term + " non-terminal" + + plural(emit.unused_term) + " declared but not used."); + + /* productions that didn't reduce */ + System.err.println(" " + emit.not_reduced + " production" + + plural(emit.not_reduced) + " never reduced."); + + /* conflicts */ + System.err.println(" " + emit.num_conflicts + " conflict" + + plural(emit.num_conflicts) + " detected" + + " (" + expect_conflicts + " expected)."); + + /* code location */ + if (output_produced) + System.err.println(" Code written to \"" + emit.parser_class_name + + ".java\", and \"" + emit.symbol_const_class_name + ".java\"."); + else + System.err.println(" No code produced."); + + if (opt_show_timing) show_times(); + + System.err.println( + "---------------------------------------------------- (" + + version.version_str + ")"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce the optional timing summary as part of an overall summary. */ + protected static void show_times() + { + long total_time = final_time - start_time; + + System.err.println(". . . . . . . . . . . . . . . . . . . . . . . . . "); + System.err.println(" Timing Summary"); + System.err.println(" Total time " + + timestr(final_time-start_time, total_time)); + System.err.println(" Startup " + + timestr(prelim_end-start_time, total_time)); + System.err.println(" Parse " + + timestr(parse_end-prelim_end, total_time) ); + if (check_end != 0) + System.err.println(" Checking " + + timestr(check_end-parse_end, total_time)); + if (check_end != 0 && build_end != 0) + System.err.println(" Parser Build " + + timestr(build_end-check_end, total_time)); + if (nullability_end != 0 && check_end != 0) + System.err.println(" Nullability " + + timestr(nullability_end-check_end, total_time)); + if (first_end != 0 && nullability_end != 0) + System.err.println(" First sets " + + timestr(first_end-nullability_end, total_time)); + if (machine_end != 0 && first_end != 0) + System.err.println(" State build " + + timestr(machine_end-first_end, total_time)); + if (table_end != 0 && machine_end != 0) + System.err.println(" Table build " + + timestr(table_end-machine_end, total_time)); + if (reduce_check_end != 0 && table_end != 0) + System.err.println(" Checking " + + timestr(reduce_check_end-table_end, total_time)); + if (emit_end != 0 && build_end != 0) + System.err.println(" Code Output " + + timestr(emit_end-build_end, total_time)); + if (emit.symbols_time != 0) + System.err.println(" Symbols " + + timestr(emit.symbols_time, total_time)); + if (emit.parser_time != 0) + System.err.println(" Parser class " + + timestr(emit.parser_time, total_time)); + if (emit.action_code_time != 0) + System.err.println(" Actions " + + timestr(emit.action_code_time, total_time)); + if (emit.production_table_time != 0) + System.err.println(" Prod table " + + timestr(emit.production_table_time, total_time)); + if (emit.action_table_time != 0) + System.err.println(" Action tab " + + timestr(emit.action_table_time, total_time)); + if (emit.goto_table_time != 0) + System.err.println(" Reduce tab " + + timestr(emit.goto_table_time, total_time)); + + System.err.println(" Dump Output " + + timestr(dump_end-emit_end, total_time)); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to format a decimal based display of seconds and + * percentage of total time given counts of milliseconds. Note: this + * is broken for use with some instances of negative time (since we don't + * use any negative time here, we let if be for now). + * @param time_val the value being formatted (in ms). + * @param total_time total time percentages are calculated against (in ms). + */ + protected static String timestr(long time_val, long total_time) + { + boolean neg; + long ms = 0; + long sec = 0; + long percent10; + String pad; + + /* work with positives only */ + neg = time_val < 0; + if (neg) time_val = -time_val; + + /* pull out seconds and ms */ + ms = time_val % 1000; + sec = time_val / 1000; + + /* construct a pad to blank fill seconds out to 4 places */ + if (sec < 10) + pad = " "; + else if (sec < 100) + pad = " "; + else if (sec < 1000) + pad = " "; + else + pad = ""; + + /* calculate 10 times the percentage of total */ + percent10 = (time_val*1000)/total_time; + + /* build and return the output string */ + return (neg ? "-" : "") + pad + sec + "." + + ((ms%1000)/100) + ((ms%100)/10) + (ms%10) + "sec" + + " (" + percent10/10 + "." + percent10%10 + "%)"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a human readable dump of the grammar. */ + public static void dump_grammar() throws internal_error + { + System.err.println("===== Terminals ====="); + for (int tidx=0, cnt=0; tidx < terminal.number(); tidx++, cnt++) + { + System.err.print("["+tidx+"]"+terminal.find(tidx).name()+" "); + if ((cnt+1) % 5 == 0) System.err.println(); + } + System.err.println(); + System.err.println(); + + System.err.println("===== Non terminals ====="); + for (int nidx=0, cnt=0; nidx < non_terminal.number(); nidx++, cnt++) + { + System.err.print("["+nidx+"]"+non_terminal.find(nidx).name()+" "); + if ((cnt+1) % 5 == 0) System.err.println(); + } + System.err.println(); + System.err.println(); + + + System.err.println("===== Productions ====="); + for (int pidx=0; pidx < production.number(); pidx++) + { + production prod = production.find(pidx); + System.err.print("["+pidx+"] "+prod.lhs().the_symbol().name() + " ::= "); + for (int i=0; iN59bH8GT59tW%0trMUzEMW=!S{DbQ?PuwZGuG2Zwu z<{#M2E;La{G%=v(a}Q%id>5?;IL$jB3ZQ z_p7^ptj-{ATDIlhXULYuugfnO;#M&$QbNmH$m|Y#^b;I+kdaW@zJRyu1PA$>dW%$X=wAju`!b35^ZGH2n)=pZxS$ zvQrSq7LdRkt=c7mQ0GEmk^ULoCbZ9peLRJTey~KgaQeo4_=Xsv4{|G%JLi*gJq0>( z+F1M~!nsay8VXsSw-ItK>c3Fb^dW>JWc2~!8hryKjv&R45f`E?n?B1z$g&o)r1hT= zKOiBTX!;L`14w7Mpa~BlVH-(2A|!1^h_4ZztIcUc$o%Eskc49>fr#Y$GnSy%XOvC* p5~AxNdifiay&;WY2z7wT^c0zZVKO~U{s5_HgZGGHnYRg7{sAbB&MW`` literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/action_part.java b/Robust/cup/java_cup/action_part.java new file mode 100644 index 00000000..69e98f59 --- /dev/null +++ b/Robust/cup/java_cup/action_part.java @@ -0,0 +1,93 @@ + +package java_cup; + +/** + * This class represents a part of a production which contains an + * action. These are eventually eliminated from productions and converted + * to trailing actions by factoring out with a production that derives the + * empty string (and ends with this action). + * + * @see java_cup.production + * @version last update: 11/25/95 + * @author Scott Hudson + */ + +public class action_part extends production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructors ------------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + * @param code_str string containing the actual user code. + */ + public action_part(String code_str) + { + super(/* never have a label on code */null); + _code_string = code_str; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** String containing code for the action in question. */ + protected String _code_string; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** String containing code for the action in question. */ + public String code_string() {return _code_string;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Set the code string. */ + public void set_code_string(String new_str) {_code_string = new_str;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Override to report this object as an action. */ + public boolean is_action() { return true; } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison for properly typed object. */ + public boolean equals(action_part other) + { + /* compare the strings */ + return other != null && super.equals(other) && + other.code_string().equals(code_string()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof action_part)) + return false; + else + return equals((action_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return super.hashCode() ^ + (code_string()==null ? 0 : code_string().hashCode()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + return super.toString() + "{" + code_string() + "}"; + } + + /*-----------------------------------------------------------*/ +} diff --git a/Robust/cup/java_cup/action_production.class b/Robust/cup/java_cup/action_production.class new file mode 100644 index 0000000000000000000000000000000000000000..01329be9e7751318cb1193dcec03ea9c46c3cf5f GIT binary patch literal 604 zcmbtRO-sW-5Pcid#>Q%@wJnMjyhvL=s^^FoQ51@oiWiZvO_#Ez-Gpr-{wxJW@Zb;d zM~RalO`*Mc$n4CU*_U~5zkfcz0Gy&`!^C<4OW3ebwy?=i@_KwCyif=I*pFnO7%H71 zf8w4WhwTh@8S-aR$>^Nnv9WL>1682BNa(RteB?f4ct+=iTu1Ir+G>xu8nnBSmTKTO z?-|UCpf4Dlj#T0{9`}U462|L zsUCC-t>Mi^?8E>gWQ38gSF+jW?Ga(@g}fAIoiB=wk`5OL_!B@6XS^exGxif9VeWT$ qk2&q|KJ%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=TzwzZYgHz(~JQxR0h+T0^IH)8RFpM}IGK z&t&Jk`)IIx&Kinx?eH25p)fwYMryxjA+M6#sGwkfiRW%ADj9m|JyhV?kDV^Nn*t@n zyx0(vg?XxHO1M`)Car!#L)5D@QoROie1lF_Z_=6Sr?AGK(;D>)YEZwTsCpYwsslV-Z;NH={GNj6treG35^qal>2-^S_O zbwH8Odh|tm$LB;h*#Q3?Ea`uqf8Gu9U4zwBmM_>DKxR!ge$fs0y*%7YIk-^aZB$_c zzkCef@8^JVeeeoA1v&o*<&{13!}8#d+-rUez}%trC;3%|lvf2Z_?l^J-K$=AuX-cD zDribcv-VB1>ZhjtnQ4D++FzLVm!>_-v~QXASJGxB__pB3Iolki-*MreYhZEU0A0Uv zuXq1LH^l#7qKn>h4t_2$L+<--(BB)-KXlXNJ{S$?AKjpTGN6AR5VVW_ za)c(?iu$W83jWQsMwFN|FCwun`uh=>oWcGNGx|@{+VXM0|Ly|+Ab+Fqff+W%d$Fg7 zK9r#EMbQ6OE_A_FR=`1UVP{$7vph7!Dxi?%rRkQYS(cCH;D2z;vj)*JYcO4a=XPrt zU1SC6a_czyf^|IIYlY|=Rxus1M$z+D3B7BLruVHe^e5{C`iFHQkFX|ii8YbOS(A9O zRmM}Sa;`(geU4SdYpiPCU`^#lYZ_l+P3PU#Nqns}llNGs@Lp>cD)dwNKC1@R`D|3= zbNF#`8z)E9b{VjIHPyOI=~7a3m*?Y1^5*DaMgv+ zzwp_O&&~Keh>t6MuO_+fZATLAz%Ap2G?*?$TH1vgeK#(~uA>ua4~?f=X)@hG({Kiv rL7j9e?Wei)2+gN%T0~D$EiU`&=rEz^qE+;5T1(F(Nt^+^iWmJaGGz~A literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/emit.java b/Robust/cup/java_cup/emit.java new file mode 100644 index 00000000..9db9014a --- /dev/null +++ b/Robust/cup/java_cup/emit.java @@ -0,0 +1,897 @@ +package java_cup; + +import java.io.PrintWriter; +import java.util.Stack; +import java.util.Enumeration; +import java.util.Date; + +/** + * This class handles emitting generated code for the resulting parser. + * The various parse tables must be constructed, etc. before calling any + * routines in this class.

+ * + * Three classes are produced by this code: + *

+ *
symbol constant class + *
this contains constant declarations for each terminal (and + * optionally each non-terminal). + *
action class + *
this non-public class contains code to invoke all the user actions + * that were embedded in the parser specification. + *
parser class + *
the specialized parser class consisting primarily of some user + * supplied general and initialization code, and the parse tables. + *

+ * + * Three parse tables are created as part of the parser class: + *

+ *
production table + *
lists the LHS non terminal number, and the length of the RHS of + * each production. + *
action table + *
for each state of the parse machine, gives the action to be taken + * (shift, reduce, or error) under each lookahead symbol.
+ *
reduce-goto table + *
when a reduce on a given production is taken, the parse stack is + * popped back a number of elements corresponding to the RHS of the + * production. This reveals a prior state, which we transition out + * of under the LHS non terminal symbol for the production (as if we + * had seen the LHS symbol rather than all the symbols matching the + * RHS). This table is indexed by non terminal numbers and indicates + * how to make these transitions. + *

+ * + * In addition to the method interface, this class maintains a series of + * public global variables and flags indicating how misc. parts of the code + * and other output is to be produced, and counting things such as number of + * conflicts detected (see the source code and public variables below for + * more details).

+ * + * This class is "static" (contains only static data and methods).

+ * + * @see java_cup.main + * @version last update: 11/25/95 + * @author Scott Hudson + */ + +/* Major externally callable routines here include: + symbols - emit the symbol constant class + parser - emit the parser class + + In addition the following major internal routines are provided: + emit_package - emit a package declaration + emit_action_code - emit the class containing the user's actions + emit_production_table - emit declaration and init for the production table + do_action_table - emit declaration and init for the action table + do_reduce_table - emit declaration and init for the reduce-goto table + + Finally, this class uses a number of public instance variables to communicate + optional parameters and flags used to control how code is generated, + as well as to report counts of various things (such as number of conflicts + detected). These include: + + prefix - a prefix string used to prefix names that would + otherwise "pollute" someone else's name space. + package_name - name of the package emitted code is placed in + (or null for an unnamed package. + symbol_const_class_name - name of the class containing symbol constants. + parser_class_name - name of the class for the resulting parser. + action_code - user supplied declarations and other code to be + placed in action class. + parser_code - user supplied declarations and other code to be + placed in parser class. + init_code - user supplied code to be executed as the parser + is being initialized. + scan_code - user supplied code to get the next Symbol. + start_production - the start production for the grammar. + import_list - list of imports for use with action class. + num_conflicts - number of conflicts detected. + nowarn - true if we are not to issue warning messages. + not_reduced - count of number of productions that never reduce. + unused_term - count of unused terminal symbols. + unused_non_term - count of unused non terminal symbols. + *_time - a series of symbols indicating how long various + sub-parts of code generation took (used to produce + optional time reports in main). +*/ + +public class emit { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Only constructor is private so no instances can be created. */ + private emit() { } + + /*-----------------------------------------------------------*/ + /*--- Static (Class) Variables ------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The prefix placed on names that pollute someone else's name space. */ + public static String prefix = "CUP$"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Package that the resulting code goes into (null is used for unnamed). */ + public static String package_name = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the generated class for symbol constants. */ + public static String symbol_const_class_name = "sym"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the generated parser class. */ + public static String parser_class_name = "parser"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User declarations for direct inclusion in user action class. */ + public static String action_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User declarations for direct inclusion in parser class. */ + public static String parser_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User code for user_init() which is called during parser initialization. */ + public static String init_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User code for scan() which is called to get the next Symbol. */ + public static String scan_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The start production of the grammar. */ + public static production start_production = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** List of imports (Strings containing class names) to go with actions. */ + public static Stack import_list = new Stack(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Number of conflict found while building tables. */ + public static int num_conflicts = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do we skip warnings? */ + public static boolean nowarn = false; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of the number on non-reduced productions found. */ + public static int not_reduced = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of unused terminals. */ + public static int unused_term = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of unused non terminals. */ + public static int unused_non_term = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Timing values used to produce timing report in main.*/ + + /** Time to produce symbol constant class. */ + public static long symbols_time = 0; + + /** Time to produce parser class. */ + public static long parser_time = 0; + + /** Time to produce action code class. */ + public static long action_code_time = 0; + + /** Time to produce the production table. */ + public static long production_table_time = 0; + + /** Time to produce the action table. */ + public static long action_table_time = 0; + + /** Time to produce the reduce-goto table. */ + public static long goto_table_time = 0; + + /* frankf 6/18/96 */ + protected static boolean _lr_values; + + /** whether or not to emit code for left and right values */ + public static boolean lr_values() {return _lr_values;} + protected static void set_lr_values(boolean b) { _lr_values = b;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Build a string with the standard prefix. + * @param str string to prefix. + */ + protected static String pre(String str) { + return prefix + parser_class_name + "$" + str; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a package spec if the user wants one. + * @param out stream to produce output on. + */ + protected static void emit_package(PrintWriter out) + { + /* generate a package spec if we have a name for one */ + if (package_name != null) { + out.println("package " + package_name + ";"); out.println(); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit code for the symbol constant class, optionally including non terms, + * if they have been requested. + * @param out stream to produce output on. + * @param emit_non_terms do we emit constants for non terminals? + * @param sym_interface should we emit an interface, rather than a class? + */ + public static void symbols(PrintWriter out, + boolean emit_non_terms, boolean sym_interface) + { + terminal term; + non_terminal nt; + String class_or_interface = (sym_interface)?"interface":"class"; + + long start_time = System.currentTimeMillis(); + + /* top of file */ + out.println(); + out.println("//----------------------------------------------------"); + out.println("// The following code was generated by " + + version.title_str); + out.println("// " + new Date()); + out.println("//----------------------------------------------------"); + out.println(); + emit_package(out); + + /* class header */ + out.println("/** CUP generated " + class_or_interface + + " containing symbol constants. */"); + out.println("public " + class_or_interface + " " + + symbol_const_class_name + " {"); + + out.println(" /* terminals */"); + + /* walk over the terminals */ /* later might sort these */ + for (Enumeration e = terminal.all(); e.hasMoreElements(); ) + { + term = (terminal)e.nextElement(); + + /* output a constant decl for the terminal */ + out.println(" public static final int " + term.name() + " = " + + term.index() + ";"); + } + + /* do the non terminals if they want them (parser doesn't need them) */ + if (emit_non_terms) + { + out.println(); + out.println(" /* non terminals */"); + + /* walk over the non terminals */ /* later might sort these */ + for (Enumeration e = non_terminal.all(); e.hasMoreElements(); ) + { + nt = (non_terminal)e.nextElement(); + + /* output a constant decl for the terminal */ + out.println(" static final int " + nt.name() + " = " + + nt.index() + ";"); + } + } + + /* end of class */ + out.println("}"); + out.println(); + + symbols_time = System.currentTimeMillis() - start_time; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit code for the non-public class holding the actual action code. + * @param out stream to produce output on. + * @param start_prod the start production of the grammar. + */ + protected static void emit_action_code(PrintWriter out, production start_prod) + throws internal_error + { + production prod; + + long start_time = System.currentTimeMillis(); + + /* class header */ + out.println(); + out.println( + "/** Cup generated class to encapsulate user supplied action code.*/" + ); + out.println("class " + pre("actions") + " {"); + + /* user supplied code */ + if (action_code != null) + { + out.println(); + out.println(action_code); + } + + /* field for parser object */ + out.println(" private final "+parser_class_name+" parser;"); + + /* constructor */ + out.println(); + out.println(" /** Constructor */"); + out.println(" " + pre("actions") + "("+parser_class_name+" parser) {"); + out.println(" this.parser = parser;"); + out.println(" }"); + + /* action method head */ + out.println(); + out.println(" /** Method with the actual generated action code. */"); + out.println(" public final java_cup.runtime.Symbol " + + pre("do_action") + "("); + out.println(" int " + pre("act_num,")); + out.println(" java_cup.runtime.lr_parser " + pre("parser,")); + out.println(" java.util.Stack " + pre("stack,")); + out.println(" int " + pre("top)")); + out.println(" throws java.lang.Exception"); + out.println(" {"); + + /* declaration of result symbol */ + /* New declaration!! now return Symbol + 6/13/96 frankf */ + out.println(" /* Symbol object for return from actions */"); + out.println(" java_cup.runtime.Symbol " + pre("result") + ";"); + out.println(); + + /* switch top */ + out.println(" /* select the action based on the action number */"); + out.println(" switch (" + pre("act_num") + ")"); + out.println(" {"); + + /* emit action code for each production as a separate case */ + for (Enumeration p = production.all(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* case label */ + out.println(" /*. . . . . . . . . . . . . . . . . . . .*/"); + out.println(" case " + prod.index() + ": // " + + prod.to_simple_string()); + + /* give them their own block to work in */ + out.println(" {"); + + /* create the result symbol */ + /*make the variable RESULT which will point to the new Symbol (see below) + and be changed by action code + 6/13/96 frankf */ + out.println(" " + prod.lhs().the_symbol().stack_type() + + " RESULT = null;"); + + /* Add code to propagate RESULT assignments that occur in + * action code embedded in a production (ie, non-rightmost + * action code). 24-Mar-1998 CSA + */ + for (int i=0; ireduce_goto table. */"); + out.println(" protected static final short[][] _reduce_table = "); + out.print (" unpackFromStrings("); + do_table_as_string(out, reduce_goto_table); + out.println(");"); + + /* do the public accessor method */ + out.println(); + out.println(" /** Access to reduce_goto table. */"); + out.println(" public short[][] reduce_table() {return _reduce_table;}"); + out.println(); + + goto_table_time = System.currentTimeMillis() - start_time; + } + + // print a string array encoding the given short[][] array. + protected static void do_table_as_string(PrintWriter out, short[][] sa) { + out.println("new String[] {"); + out.print(" \""); + int nchar=0, nbytes=0; + nbytes+=do_escaped(out, (char)(sa.length>>16)); + nchar =do_newline(out, nchar, nbytes); + nbytes+=do_escaped(out, (char)(sa.length&0xFFFF)); + nchar =do_newline(out, nchar, nbytes); + for (int i=0; i>16)); + nchar =do_newline(out, nchar, nbytes); + nbytes+=do_escaped(out, (char)(sa[i].length&0xFFFF)); + nchar =do_newline(out, nchar, nbytes); + for (int j=0; j 65500) { out.println("\", "); out.print(" \""); } + else if (nchar > 11) { out.println("\" +"); out.print(" \""); } + else return nchar+1; + return 0; + } + // output an escape sequence for the given character code. + protected static int do_escaped(PrintWriter out, char c) { + StringBuffer escape = new StringBuffer(); + if (c <= 0xFF) { + escape.append(Integer.toOctalString(c)); + while(escape.length() < 3) escape.insert(0, '0'); + } else { + escape.append(Integer.toHexString(c)); + while(escape.length() < 4) escape.insert(0, '0'); + escape.insert(0, 'u'); + } + escape.insert(0, '\\'); + out.print(escape.toString()); + + // return number of bytes this takes up in UTF-8 encoding. + if (c == 0) return 2; + if (c >= 0x01 && c <= 0x7F) return 1; + if (c >= 0x80 && c <= 0x7FF) return 2; + return 3; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit the parser subclass with embedded tables. + * @param out stream to produce output on. + * @param action_table internal representation of the action table. + * @param reduce_table internal representation of the reduce-goto table. + * @param start_st start state of the parse machine. + * @param start_prod start production of the grammar. + * @param compact_reduces do we use most frequent reduce as default? + * @param suppress_scanner should scanner be suppressed for compatibility? + */ + public static void parser( + PrintWriter out, + parse_action_table action_table, + parse_reduce_table reduce_table, + int start_st, + production start_prod, + boolean compact_reduces, + boolean suppress_scanner) + throws internal_error + { + long start_time = System.currentTimeMillis(); + + /* top of file */ + out.println(); + out.println("//----------------------------------------------------"); + out.println("// The following code was generated by " + + version.title_str); + out.println("// " + new Date()); + out.println("//----------------------------------------------------"); + out.println(); + emit_package(out); + + /* user supplied imports */ + for (int i = 0; i < import_list.size(); i++) + out.println("import " + import_list.elementAt(i) + ";"); + + /* class header */ + out.println(); + out.println("/** "+version.title_str+" generated parser."); + out.println(" * @version " + new Date()); + out.println(" */"); + out.println("public class " + parser_class_name + + " extends java_cup.runtime.lr_parser {"); + + /* constructors [CSA/davidm, 24-jul-99] */ + out.println(); + out.println(" /** Default constructor. */"); + out.println(" public " + parser_class_name + "() {super();}"); + if (!suppress_scanner) { + out.println(); + out.println(" /** Constructor which sets the default scanner. */"); + out.println(" public " + parser_class_name + + "(java_cup.runtime.Scanner s) {super(s);}"); + } + + /* emit the various tables */ + emit_production_table(out); + do_action_table(out, action_table, compact_reduces); + do_reduce_table(out, reduce_table); + + /* instance of the action encapsulation class */ + out.println(" /** Instance of action encapsulation class. */"); + out.println(" protected " + pre("actions") + " action_obj;"); + out.println(); + + /* action object initializer */ + out.println(" /** Action encapsulation object initializer. */"); + out.println(" protected void init_actions()"); + out.println(" {"); + out.println(" action_obj = new " + pre("actions") + "(this);"); + out.println(" }"); + out.println(); + + /* access to action code */ + out.println(" /** Invoke a user supplied parse action. */"); + out.println(" public java_cup.runtime.Symbol do_action("); + out.println(" int act_num,"); + out.println(" java_cup.runtime.lr_parser parser,"); + out.println(" java.util.Stack stack,"); + out.println(" int top)"); + out.println(" throws java.lang.Exception"); + out.println(" {"); + out.println(" /* call code in generated class */"); + out.println(" return action_obj." + pre("do_action(") + + "act_num, parser, stack, top);"); + out.println(" }"); + out.println(""); + + + /* method to tell the parser about the start state */ + out.println(" /** Indicates start state. */"); + out.println(" public int start_state() {return " + start_st + ";}"); + + /* method to indicate start production */ + out.println(" /** Indicates start production. */"); + out.println(" public int start_production() {return " + + start_production.index() + ";}"); + out.println(); + + /* methods to indicate EOF and error symbol indexes */ + out.println(" /** EOF Symbol index. */"); + out.println(" public int EOF_sym() {return " + terminal.EOF.index() + + ";}"); + out.println(); + out.println(" /** error Symbol index. */"); + out.println(" public int error_sym() {return " + terminal.error.index() + + ";}"); + out.println(); + + /* user supplied code for user_init() */ + if (init_code != null) + { + out.println(); + out.println(" /** User initialization code. */"); + out.println(" public void user_init() throws java.lang.Exception"); + out.println(" {"); + out.println(init_code); + out.println(" }"); + } + + /* user supplied code for scan */ + if (scan_code != null) + { + out.println(); + out.println(" /** Scan to get the next Symbol. */"); + out.println(" public java_cup.runtime.Symbol scan()"); + out.println(" throws java.lang.Exception"); + out.println(" {"); + out.println(scan_code); + out.println(" }"); + } + + /* user supplied code */ + if (parser_code != null) + { + out.println(); + out.println(parser_code); + } + + /* end of class */ + out.println("}"); + + /* put out the action code class */ + emit_action_code(out, start_prod); + + parser_time = System.currentTimeMillis() - start_time; + } + + /*-----------------------------------------------------------*/ +} diff --git a/Robust/cup/java_cup/internal_error.class b/Robust/cup/java_cup/internal_error.class new file mode 100644 index 0000000000000000000000000000000000000000..77c69e14505a3fc2cc6a62aea0d9d92f59f0f33e GIT binary patch literal 580 zcmZWnT`vPc6g{*3*qScYZ{OB;OQP{y@lqrNkrb~o)})5*ZZn+sMtJXAH1+9AZf+5}ruO&m~NConw*S?baOkDYdBs?v;Hw>{#MB~k{r#-o^ zqEC4h7^wr{UrMb*y%`BR;7Hq;bufo{hLuCY8t13(zA(af4}J>Vy{N$5l}36-UfXaT zEFkS*5lar1k#VqsRfcjTdFk~!wZE;X_t3@OgC{#ig#p9(5N$qojcn7o>1<^C+qDX7 zr)1fXaVgsMUzxu!gWZWpJ_+)cG{>^r6)o~xs8s)79^Ki1-890xJJZ4=Vq88bL#c95 zy&zvHdZlPsAVH)lI<#A)y+t{>zVQO~L@S0-ihO`_BnHeeWPbRKK|L`23@aDwBTjj} ij|8nKC9PN3Ly;1d16gXFqnW2aqkt(CNot&M3)wGb@qC^D literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/internal_error.java b/Robust/cup/java_cup/internal_error.java new file mode 100644 index 00000000..4d3e7c2c --- /dev/null +++ b/Robust/cup/java_cup/internal_error.java @@ -0,0 +1,22 @@ + +package java_cup; + +/** Exception subclass for reporting internal errors in JavaCup. */ +public class internal_error extends Exception + { + /** Constructor with a message */ + public internal_error(String msg) + { + super(msg); + } + + /** Method called to do a forced error exit on an internal error + for cases when we can't actually throw the exception. */ + public void crash() + { + System.err.println("JavaCUP Fatal Internal Error Detected"); + System.err.println(getMessage()); + printStackTrace(); + System.exit(-1); + } + } diff --git a/Robust/cup/java_cup/lalr_item.class b/Robust/cup/java_cup/lalr_item.class new file mode 100644 index 0000000000000000000000000000000000000000..275e77eeb7fbaa4f632192c2049f8bd8e3d751ae GIT binary patch literal 3745 zcmaJ@{c~JZ8GcT7H@msLO`0@q8k)!kOHFo@rcG&qgj5syDQQa$G=zf7&F)S1wwv8$ z_ikw^h}epN0)C*9C@S@%Rid^^H%PRN=lyuz&$I9T@2#rH24sgLqZl)<1!h zJ0ZK2TujT74k9CztSpZPkqaTOp&7QE3$mOPsmEk@DumM-9>*D3p3v|lJ{81M8g9m? zH9U>a1aVe)&js;W4V&62?uA>V6yE6$>p<%>In}-V16K3u{VwXY#I!6ZYhCW@u&g!`iE>bgyv1WWWu$UWNC(7nb46nr z1HHS+Bd{z$fqc@Mv=!ESkyg|y)W?lf+?!`_7OK_V(ACB=oY+Y#Z#fC@b#_T^%|{DH ziXd;`67}j%B-oizJ7=Y*7>T7wIzlBXD@+^B z6moHMuO$^wU-oi~6t0e8d_%`w7-VXM;K_pAeN)FSd{oEBFeJyj32eoB*YPU8rQ_Q; zs^b7YuH!p+O~*YL(QzKfbbJ@zQ)nuSmOUXkb(C5~g5m*oK+58{{t+z6FQqLkg?f|W{` zIUR4}7aSV|_z)gesOb*#bVkQpf_VYI)bT4^)p1QOmE1ka`E=<1k&*Do;luX~?cX!B zyQ70-URUz#Hd!p5$+2)+J^kbzL(+n*M6Uj9A)i#(yi(;lO;T0N3IR#!X-c!zKd4_> z_5Qr|I5E_jDRbIP+e2*Kb)5%FQ|3CYS|Ve|3_Hf+5GIddw;=>-y`3~=y12ts8qqVd zDi`dYpyIsjM)tyK>2VEM=yrZ2IowL7{yKn)57Fn4S8d$_*tsmWL#sR-j|KWpQMiqB{8B5NWlZoGYb_d53YOtH9-3}+v7KygaLq&S7peC{a-}pTIR}hGB zsl7}-g*{x?BfxbFYSD{T*vj)ZY(yXSlIkZTt9uh^KHh{PQD65wf)za)IY4|t zBCM9(@5)AKNqFihyMPek)UBXlFIHn;l?F~!Vi3>T`Q<2}4{xC65;r9mY8~Pct{k~s zuV)Qh&pJ*fPDPism#73+1GNUCMQCH!g{a$9!ks@@SR}Z$$LKB`D^hA8jfp1qk@9K+aIFF68YcFEWA{s@Yh^BKs zb>aQLR|33+=>ZC~cZx|ljdgeet$2!m($1m>&oE`ru_&I$5q`(;LRAQl;1e$1hnXO8 zb_cDjox$n_G>U@>; z^BT7Eo%3dX6!*DC|H1&)(&$;Q(TydeP8}R98Fd2EQbgN%jFQsAfVB7fTm40RXchyl z{zcqeM7TfD8YrTJq3&)CEaH|TK0MZa$=Poz;#P)wOz7Nio<*Shk`u^_-I4?H5k{$M zhOvhGB3+oL3k!_pRsJ7d#18z1CHyvv@ORAfyBNpsaSVTC?%zWme_{r%;tc+Zr}4Kc zckjnh*WG9Nm72J>%`#QqZl{q| z18UV8@{iH~Qb+ZvC$-HkZaQ>+fLFtEA7p@(s4V ziS6gnCp>LM+%|&_4<9dg6tR=cO}D!e=W5uIfAH`$-QnI`K#P}rr%U$I`dyl*iFToZ z#n=O%+J+X@haR;ZL+Uo{S3B{Lx*evv16g$^UgZ8|)sKs60I#b-TvNO7p4!J?eUe$M GLG1sVg?~T* literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/lalr_item.java b/Robust/cup/java_cup/lalr_item.java new file mode 100644 index 00000000..fe920544 --- /dev/null +++ b/Robust/cup/java_cup/lalr_item.java @@ -0,0 +1,330 @@ +package java_cup; + +import java.util.Stack; +import java.util.Enumeration; + +/** This class represents an LALR item. Each LALR item consists of + * a production, a "dot" at a position within that production, and + * a set of lookahead symbols (terminal). (The first two of these parts + * are provide by the super class). An item is designed to represent a + * configuration that the parser may be in. For example, an item of the + * form:

+ *    [A ::= B * C d E  , {a,b,c}]
+ *  
+ * indicates that the parser is in the middle of parsing the production
+ *    A ::= B C d E
+ *  
+ * that B has already been parsed, and that we will expect to see a lookahead + * of either a, b, or c once the complete RHS of this production has been + * found.

+ * + * Items may initially be missing some items from their lookahead sets. + * Links are maintained from each item to the set of items that would need + * to be updated if symbols are added to its lookahead set. During + * "lookahead propagation", we add symbols to various lookahead sets and + * propagate these changes across these dependency links as needed. + * + * @see java_cup.lalr_item_set + * @see java_cup.lalr_state + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class lalr_item extends lr_item_core { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param prod the production for the item. + * @param pos the position of the "dot" within the production. + * @param look the set of lookahead symbols. + */ + public lalr_item(production prod, int pos, terminal_set look) + throws internal_error + { + super(prod, pos); + _lookahead = look; + _propagate_items = new Stack(); + needs_propagation = true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default position (dot at start). + * @param prod the production for the item. + * @param look the set of lookahead symbols. + */ + public lalr_item(production prod, terminal_set look) throws internal_error + { + this(prod,0,look); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default position and empty lookahead set. + * @param prod the production for the item. + */ + public lalr_item(production prod) throws internal_error + { + this(prod,0,new terminal_set()); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The lookahead symbols of the item. */ + protected terminal_set _lookahead; + + /** The lookahead symbols of the item. */ + public terminal_set lookahead() {return _lookahead;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Links to items that the lookahead needs to be propagated to. */ + protected Stack _propagate_items; + + /** Links to items that the lookahead needs to be propagated to */ + public Stack propagate_items() {return _propagate_items;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Flag to indicate that this item needs to propagate its lookahead + * (whether it has changed or not). + */ + protected boolean needs_propagation; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a new item to the set of items we propagate to. */ + public void add_propagate(lalr_item prop_to) + { + _propagate_items.push(prop_to); + needs_propagation = true; + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Propagate incoming lookaheads through this item to others need to + * be changed. + * @params incoming symbols to potentially be added to lookahead of this item. + */ + public void propagate_lookaheads(terminal_set incoming) throws internal_error + { + boolean change = false; + + /* if we don't need to propagate, then bail out now */ + if (!needs_propagation && (incoming == null || incoming.empty())) + return; + + /* if we have null incoming, treat as an empty set */ + if (incoming != null) + { + /* add the incoming to the lookahead of this item */ + change = lookahead().add(incoming); + } + + /* if we changed or need it anyway, propagate across our links */ + if (change || needs_propagation) + { + /* don't need to propagate again */ + needs_propagation = false; + + /* propagate our lookahead into each item we are linked to */ + for (int i = 0; i < propagate_items().size(); i++) + ((lalr_item)propagate_items().elementAt(i)) + .propagate_lookaheads(lookahead()); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce the new lalr_item that results from shifting the dot one position + * to the right. + */ + public lalr_item shift() throws internal_error + { + lalr_item result; + + /* can't shift if we have dot already at the end */ + if (dot_at_end()) + throw new internal_error("Attempt to shift past end of an lalr_item"); + + /* create the new item w/ the dot shifted by one */ + result = new lalr_item(the_production(), dot_pos()+1, + new terminal_set(lookahead())); + + /* change in our lookahead needs to be propagated to this item */ + add_propagate(result); + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Calculate lookahead representing symbols that could appear after the + * symbol that the dot is currently in front of. Note: this routine must + * not be invoked before first sets and nullability has been calculated + * for all non terminals. + */ + public terminal_set calc_lookahead(terminal_set lookahead_after) + throws internal_error + { + terminal_set result; + int pos; + production_part part; + symbol sym; + + /* sanity check */ + if (dot_at_end()) + throw new internal_error( + "Attempt to calculate a lookahead set with a completed item"); + + /* start with an empty result */ + result = new terminal_set(); + + /* consider all nullable symbols after the one to the right of the dot */ + for (pos = dot_pos()+1; pos < the_production().rhs_length(); pos++) + { + part = the_production().rhs(pos); + + /* consider what kind of production part it is -- skip actions */ + if (!part.is_action()) + { + sym = ((symbol_part)part).the_symbol(); + + /* if its a terminal add it in and we are done */ + if (!sym.is_non_term()) + { + result.add((terminal)sym); + return result; + } + else + { + /* otherwise add in first set of the non terminal */ + result.add(((non_terminal)sym).first_set()); + + /* if its nullable we continue adding, if not, we are done */ + if (!((non_terminal)sym).nullable()) + return result; + } + } + } + + /* if we get here everything past the dot was nullable + we add in the lookahead for after the production and we are done */ + result.add(lookahead_after); + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if everything from the symbol one beyond the dot all the + * way to the end of the right hand side is nullable. This would indicate + * that the lookahead of this item must be included in the lookaheads of + * all items produced as a closure of this item. Note: this routine should + * not be invoked until after first sets and nullability have been + * calculated for all non terminals. + */ + public boolean lookahead_visible() throws internal_error + { + production_part part; + symbol sym; + + /* if the dot is at the end, we have a problem, but the cleanest thing + to do is just return true. */ + if (dot_at_end()) return true; + + /* walk down the rhs and bail if we get a non-nullable symbol */ + for (int pos = dot_pos() + 1; pos < the_production().rhs_length(); pos++) + { + part = the_production().rhs(pos); + + /* skip actions */ + if (!part.is_action()) + { + sym = ((symbol_part)part).the_symbol(); + + /* if its a terminal we fail */ + if (!sym.is_non_term()) return false; + + /* if its not nullable we fail */ + if (!((non_terminal)sym).nullable()) return false; + } + } + + /* if we get here its all nullable */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison -- here we only require the cores to be equal since + * we need to do sets of items based only on core equality (ignoring + * lookahead sets). + */ + public boolean equals(lalr_item other) + { + if (other == null) return false; + return super.equals(other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_item)) + return false; + else + return equals((lalr_item)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return a hash code -- here we only hash the core since we only test core + * matching in LALR items. + */ + public int hashCode() + { + return super.hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() + { + String result = ""; + + // additional output for debugging: + // result += "(" + obj_hash() + ")"; + result += "["; + result += super.toString(); + result += ", "; + if (lookahead() != null) + { + result += "{"; + for (int t = 0; t < terminal.number(); t++) + if (lookahead().contains(t)) + result += terminal.find(t).name() + " "; + result += "}"; + } + else + result += "NULL LOOKAHEAD!!"; + result += "]"; + + // additional output for debugging: + // result += " -> "; + // for (int i = 0; iZjTP5tQcgFXHU9^-RoX0x+t@c1G3H#>7* zo_p_e?@a#ipAUWkU>k1u(T|f}=zdgSyb7&|i5eX5eyf`fi$!g3X zB_b_9XGNUxLqo=o4rE0&Cn7Ho&Wd=#i*r7l_oD?*dhwLpdRhd1x8j1Ben!MIB0lTK zMO^aYSudUwf1i_^&x?3L>|Yd<&&$u3ym;A<2*yQx!HZY?*n*Qjyej7xz4($J+vWF{ z<@}0>uln#cIbZYPby0fFi?1uVV|p^F&^UZbKdblVbBSc{K|MR2)5nuWze3G4f5g)h zMl7z!rwxUAOEIaZrh11`Ib+JmP_1%zB9+MPQE+v2AEVQKv{0xWPNa;{{LHwKd06}@ zw04>1v3P#AH>oExu|&?8iDivkznJ+4&&7?|Tq2#y(vyiR*wyVoHkiuK7#UqO7}T9j zJV~DnIi%o=r&BpSA(qXn1?lfTPK(JzYC<8ry22{Z7)48DW7+&TF~-u9|1$#ys4U<&`_+q8Ns?s2>zq# zd?s$}Pe?NZWgXli1k&(H>?KK7A(K4%hKAkvxQ0FWgoa}n({LGAG<*{WG#tc`hHv4x zhHv94or{a|5@^_u175tL;X8O!!*|8>K|G{k6o)i?58u~t7(dYP7Unb@!BzP=B3DOQ z_+@tqk~WjllQAQcNoN$=M_JKO+N@zHpEV{ziByQ~3#HjclWKzehwRI;i?Y1s=>r-b z#-}y>2ybh62lEEci+>{1Wrq3QHDdCz4&h)r3$uwdqhA2arN~dB) zC`4Ej*OT#>Bb}{xgj`x>MSF9}l0M7kv9pP6!d%KFB02-IjwQCTg?FwG)97^|DOvU3 z0fw147h{a7v-*^tBZoZk4EGR8!}&a>C-btp^x0WM_H~c5?#1Fc3h(4Q>$Lg*R5!W5 zQr~8svx!CbmOk3~3hw83LJ-7?--b4ih zlzgv4B`rH0zBdy7CUm0PoKU;}1ARSEtL&`7*LmP7|Y`++m@#Y9Yyu^xQ&SPXPheCQv~ASkE<+D`x(@ z*Dw|-<$pJP^l_eXo+fRcK_f1bo0kavMK<>(e(Akj7N74yJN_;keuEWX*l1U{ajZlg zivmf?EoDg4N&h4&^)*F;Y$BZ4)4?d4Ho8uGXH#K+Xa!vNCNHbjypgkbOL^8`J& zmj2ZvY$_nsSILX^d#i$;0`Bhf2EA5}OMjFrGs%1Ue2dVcLCTJ3uyO&N3)nas-dsRa zpS!W@GOBul+%TJh?#*v4{W>D|+0Gj!_z!ZC0sm%2mN;=0XjC4oQ$B=L6*`rMUR8^o zDuDf}0Y_9b48?z@R2$By4R}Jexb1s8eM@%&kzb+p ziskbrS_|kdO}5z}H2|;LhblElOMa5s_8GQK*7$&HH)qLno5L-0;M!B%KP|0}NeExs z{hUk9E&YSc5KSu)h%N48I iSE9THXA(X&P0A$DrcPr(B{8UGFs#x9@;CuhAogER1!(gC literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/lalr_item_set.java b/Robust/cup/java_cup/lalr_item_set.java new file mode 100644 index 00000000..233a68f3 --- /dev/null +++ b/Robust/cup/java_cup/lalr_item_set.java @@ -0,0 +1,371 @@ + +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a set of LALR items. For purposes of building + * these sets, items are considered unique only if they have unique cores + * (i.e., ignoring differences in their lookahead sets).

+ * + * This class provides fairly conventional set oriented operations (union, + * sub/super-set tests, etc.), as well as an LALR "closure" operation (see + * compute_closure()). + * + * @see java_cup.lalr_item + * @see java_cup.lalr_state + * @version last updated: 3/6/96 + * @author Scott Hudson + */ + +public class lalr_item_set { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for an empty set. */ + public lalr_item_set() { } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for cloning from another set. + * @param other indicates set we should copy from. + */ + public lalr_item_set(lalr_item_set other) + throws internal_error + { + not_null(other); + _all = (Hashtable)other._all.clone(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** A hash table to implement the set. We store the items using themselves + * as keys. + */ + protected Hashtable _all = new Hashtable(11); + + /** Access to all elements of the set. */ + public Enumeration all() {return _all.elements();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Cached hashcode for this set. */ + protected Integer hashcode_cache = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Size of the set */ + public int size() {return _all.size();} + + /*-----------------------------------------------------------*/ + /*--- Set Operation Methods ---------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Does the set contain a particular item? + * @param itm the item in question. + */ + public boolean contains(lalr_item itm) {return _all.containsKey(itm);} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return the item in the set matching a particular item (or null if not + * found) + * @param itm the item we are looking for. + */ + public lalr_item find(lalr_item itm) {return (lalr_item)_all.get(itm);} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is this set an (improper) subset of another? + * @param other the other set in question. + */ + public boolean is_subset_of(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down our set and make sure every element is in the other */ + for (Enumeration e = all(); e.hasMoreElements(); ) + if (!other.contains((lalr_item)e.nextElement())) + return false; + + /* they were all there */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is this set an (improper) superset of another? + * @param other the other set in question. + */ + public boolean is_superset_of(lalr_item_set other) throws internal_error + { + not_null(other); + return other.is_subset_of(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a singleton item, merging lookahead sets if the item is already + * part of the set. returns the element of the set that was added or + * merged into. + * @param itm the item being added. + */ + public lalr_item add(lalr_item itm) throws internal_error + { + lalr_item other; + + not_null(itm); + + /* see if an item with a matching core is already there */ + other = (lalr_item)_all.get(itm); + + /* if so, merge this lookahead into the original and leave it */ + if (other != null) + { + other.lookahead().add(itm.lookahead()); + return other; + } + /* otherwise we just go in the set */ + else + { + /* invalidate cached hashcode */ + hashcode_cache = null; + + _all.put(itm,itm); + return itm; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove a single item if it is in the set. + * @param itm the item to remove. + */ + public void remove(lalr_item itm) throws internal_error + { + not_null(itm); + + /* invalidate cached hashcode */ + hashcode_cache = null; + + /* remove it from hash table implementing set */ + _all.remove(itm); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a complete set, merging lookaheads where items are already in + * the set + * @param other the set to be added. + */ + public void add(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down the other set and do the adds individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + add((lalr_item)e.nextElement()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove (set subtract) a complete set. + * @param other the set to remove. + */ + public void remove(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down the other set and do the removes individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + remove((lalr_item)e.nextElement()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove and return one item from the set (done in hash order). */ + public lalr_item get_one() throws internal_error + { + Enumeration the_set; + lalr_item result; + + the_set = all(); + if (the_set.hasMoreElements()) + { + result = (lalr_item)the_set.nextElement(); + remove(result); + return result; + } + else + return null; + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper function for null test. Throws an interal_error exception if its + * parameter is null. + * @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"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute the closure of the set using the LALR closure rules. Basically + * for every item of the form:

+   *    [L ::= a *N alpha, l] 
+   *  
+ * (where N is a a non terminal and alpha is a string of symbols) make + * sure there are also items of the form:
+   *    [N ::= *beta, first(alpha l)] 
+   *  
+ * corresponding to each production of N. Items with identical cores but + * differing lookahead sets are merged by creating a new item with the same + * core and the union of the lookahead sets (the LA in LALR stands for + * "lookahead merged" and this is where the merger is). This routine + * assumes that nullability and first sets have been computed for all + * productions before it is called. + */ + public void compute_closure() + throws internal_error + { + lalr_item_set consider; + lalr_item itm, new_itm, add_itm; + non_terminal nt; + terminal_set new_lookaheads; + Enumeration p; + production prod; + boolean need_prop; + + + + /* invalidate cached hashcode */ + hashcode_cache = null; + + /* each current element needs to be considered */ + consider = new lalr_item_set(this); + + /* repeat this until there is nothing else to consider */ + while (consider.size() > 0) + { + /* get one item to consider */ + itm = consider.get_one(); + + /* do we have a dot before a non terminal */ + nt = itm.dot_before_nt(); + if (nt != null) + { + /* create the lookahead set based on first after dot */ + new_lookaheads = itm.calc_lookahead(itm.lookahead()); + + /* are we going to need to propagate our lookahead to new item */ + need_prop = itm.lookahead_visible(); + + /* create items for each production of that non term */ + for (p = nt.productions(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* create new item with dot at start and that lookahead */ + new_itm = new lalr_item(prod, + new terminal_set(new_lookaheads)); + + /* add/merge item into the set */ + add_itm = add(new_itm); + /* if propagation is needed link to that item */ + if (need_prop) + itm.add_propagate(add_itm); + + /* was this was a new item*/ + if (add_itm == new_itm) + { + /* that may need further closure, consider it also */ + consider.add(new_itm); + } + } + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(lalr_item_set other) + { + if (other == null || other.size() != size()) return false; + + /* once we know they are the same size, then improper subset does test */ + try { + return is_subset_of(other); + } catch (internal_error e) { + /* can't throw error from here (because superclass doesn't) so crash */ + e.crash(); + return false; + } + + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_item_set)) + return false; + else + return equals((lalr_item_set)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return hash code. */ + public int hashCode() + { + int result = 0; + Enumeration e; + int cnt; + + /* only compute a new one if we don't have it cached */ + if (hashcode_cache == null) + { + /* hash together codes from at most first 5 elements */ + // CSA fix! we'd *like* to hash just a few elements, but + // that means equal sets will have inequal hashcodes, which + // we're not allowed (by contract) to do. So hash them all. + for (e = all(), cnt=0 ; e.hasMoreElements() /*&& cnt<5*/; cnt++) + result ^= ((lalr_item)e.nextElement()).hashCode(); + + hashcode_cache = new Integer(result); + } + + return hashcode_cache.intValue(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() + { + StringBuffer result = new StringBuffer(); + + result.append("{\n"); + for (Enumeration e=all(); e.hasMoreElements(); ) + { + result.append(" " + (lalr_item)e.nextElement() + "\n"); + } + result.append("}"); + + return result.toString(); + } + /*-----------------------------------------------------------*/ +} + diff --git a/Robust/cup/java_cup/lalr_state.class b/Robust/cup/java_cup/lalr_state.class new file mode 100644 index 0000000000000000000000000000000000000000..79705a2547ca604441e5f1621e15be251f73520b GIT binary patch literal 9712 zcmb7J34B!5x&MFnPBN3pO$Z4AMnOjeBpWCS>aZvxC>Vk@3WDM|Boi_)nTazKKvC3+ zwJx-p}F0B^2T5GHAYwc$BRjsYBeXp-}bKd{E_fF;}LEn4)e%y2B zobP=5c22(Y!B?LF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`R6uZqS*Nl2%YsCZyl7X)D4pmAG&Vb>_geHMcy7a^Kvt=9UKvzhSZC zp`X>4?JT^)`2r$YkjJ*2g@cXF{C)XA;TdzTzus@>v`|w$b5nFD+y7>rUBP$$fx?>u zg-j_-m!p;{eI9kjH*tjV9ZWO6j~T{Gm}k6}Ga5 z{p4yklDhJ7XN6)GSFYiTIoDV3vqe0WunX#GRZ2NimEq2(Ot#zG?X^4X_O{HYwDk-V z+O=HT;iD#=Q3~3!>i7w+5*Zuo4&u>aw>HSzYp>JxRy*G9wV$+Muh$FK^?PxHjyIH4 zd5(5<#``dgzf+a}z;xrEIM(4fK*26{{%wwqB`n4v?v$LT~)v6My*`VY%Kzw9*uQtYdQ0uEKXc%qaEzyT>W{odUOUF`c+L}ykI)HlB0nN;~ym=@5z5)0=xzWxC<{3Q4Kk2xqXS=6s zo4$^kew3Me8k^Wh=ke)MPPO}fb0z%d*{Cqj;Yq%@yXV6kh13I%_HQYja;ROvUH-Mt zg}#~8G*_)Jn$>$*yj4xiTWub<)!yzXzLi+JRx}^LZ1(_Vn?V1)jX~AwSsH@pUTVca z;U!OldYJl>xdAiGjX2Is;&iiz+TMtZ&0glQAF#!9^mwwZMZQrC;xjBipM4yaL$f6& b-yBMz;9P`O@s**AL2)?|yhNc4{P2GO*1r + * [A ::= B * C d E , {a,b,c}] + * + * this indicates that when the parser is in this state it is currently + * looking for an A of the given form, has already seen the B, and would + * expect to see an a, b, or c after this sequence is complete. Note that + * the parser is normally looking for several things at once (represented + * by several items). In our example above, the state would also include + * items such as:
+ *    [C ::= * X e Z, {d}]
+ *    [X ::= * f, {e}]
+ *  
+ * to indicate that it was currently looking for a C followed by a d (which + * would be reduced into a C, matching the first symbol in our production + * above), and the terminal f followed by e.

+ * + * At runtime, the parser uses a viable prefix recognition machine made up + * of these states to parse. The parser has two operations, shift and reduce. + * In a shift, it consumes one Symbol and makes a transition to a new state. + * This corresponds to "moving the dot past" a terminal in one or more items + * in the state (these new shifted items will then be found in the state at + * the end of the transition). For a reduce operation, the parser is + * signifying that it is recognizing the RHS of some production. To do this + * it first "backs up" by popping a stack of previously saved states. It + * pops off the same number of states as are found in the RHS of the + * production. This leaves the machine in the same state is was in when the + * parser first attempted to find the RHS. From this state it makes a + * transition based on the non-terminal on the LHS of the production. This + * corresponds to placing the parse in a configuration equivalent to having + * replaced all the symbols from the the input corresponding to the RHS with + * the symbol on the LHS. + * + * @see java_cup.lalr_item + * @see java_cup.lalr_item_set + * @see java_cup.lalr_transition + * @version last updated: 7/3/96 + * @author Frank Flannery + * + */ + +public class lalr_state { + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for building a state from a set of items. + * @param itms the set of items that makes up this state. + */ + public lalr_state(lalr_item_set itms) throws internal_error + { + /* don't allow null or duplicate item sets */ + if (itms == null) + throw new internal_error( + "Attempt to construct an LALR state from a null item set"); + + if (find_state(itms) != null) + throw new internal_error( + "Attempt to construct a duplicate LALR state"); + + /* assign a unique index */ + _index = next_index++; + + /* store the items */ + _items = itms; + + /* add to the global collection, keyed with its item set */ + _all.put(_items,this); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Collection of all states. */ + protected static Hashtable _all = new Hashtable(); + + /** Collection of all states. */ + public static Enumeration all() {return _all.elements();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Indicate total number of states there are. */ + public static int number() {return _all.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Hash table to find states by their kernels (i.e, the original, + * unclosed, set of items -- which uniquely define the state). This table + * stores state objects using (a copy of) their kernel item sets as keys. + */ + protected static Hashtable _all_kernels = new Hashtable(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Find and return state with a given a kernel item set (or null if not + * found). The kernel item set is the subset of items that were used to + * originally create the state. These items are formed by "shifting the + * dot" within items of other states that have a transition to this one. + * The remaining elements of this state's item set are added during closure. + * @param itms the kernel set of the state we are looking for. + */ + public static lalr_state find_state(lalr_item_set itms) + { + if (itms == null) + return null; + else + return (lalr_state)_all.get(itms); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter for assigning unique state indexes. */ + protected static int next_index = 0; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The item set for this state. */ + protected lalr_item_set _items; + + /** The item set for this state. */ + public lalr_item_set items() {return _items;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** List of transitions out of this state. */ + protected lalr_transition _transitions = null; + + /** List of transitions out of this state. */ + public lalr_transition transitions() {return _transitions;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Index of this state in the parse tables */ + protected int _index; + + /** Index of this state in the parse tables */ + public int index() {return _index;} + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper routine for debugging -- produces a dump of the given state + * onto System.out. + */ + protected static void dump_state(lalr_state st) throws internal_error + { + lalr_item_set itms; + lalr_item itm; + production_part part; + + if (st == null) + { + System.out.println("NULL lalr_state"); + return; + } + + System.out.println("lalr_state [" + st.index() + "] {"); + itms = st.items(); + for (Enumeration e = itms.all(); e.hasMoreElements(); ) + { + itm = (lalr_item)e.nextElement(); + System.out.print(" ["); + System.out.print(itm.the_production().lhs().the_symbol().name()); + System.out.print(" ::= "); + for (int i = 0; i + * [A ::= a b * X c, {d,e}] + * [B ::= a b * X d, {a,b}] + * + * in some state, then we would be making a transition under X to a new + * state. This new state would be formed by a "kernel" of items + * corresponding to moving the dot past the X. In this case:

+   *    [A ::= a b X * c, {d,e}]
+   *    [B ::= a b X * Y, {a,b}]
+   *  
+ * The full state would then be formed by "closing" this kernel set of + * items so that it included items that represented productions of things + * the parser was now looking for. In this case we would items + * corresponding to productions of Y, since various forms of Y are expected + * next when in this state (see lalr_item_set.compute_closure() for details + * on closure).

+ * + * The process of building the viable prefix recognizer terminates when no + * new states can be added. However, in order to build a smaller number of + * states (i.e., corresponding to LALR rather than canonical LR) the state + * building process does not maintain full loookaheads in all items. + * Consequently, after the machine is built, we go back and propagate + * lookaheads through the constructed machine using a call to + * propagate_all_lookaheads(). This makes use of propagation links + * constructed during the closure and transition process. + * + * @param start_prod the start production of the grammar + * @see java_cup.lalr_item_set#compute_closure + * @see java_cup.lalr_state#propagate_all_lookaheads + */ + + public static lalr_state build_machine(production start_prod) + throws internal_error + { + lalr_state start_state; + lalr_item_set start_items; + lalr_item_set new_items; + lalr_item_set linked_items; + lalr_item_set kernel; + Stack work_stack = new Stack(); + lalr_state st, new_st; + symbol_set outgoing; + lalr_item itm, new_itm, existing, fix_itm; + symbol sym, sym2; + Enumeration i, s, fix; + + /* sanity check */ + if (start_prod == null) + throw new internal_error( + "Attempt to build viable prefix recognizer using a null production"); + + /* build item with dot at front of start production and EOF lookahead */ + start_items = new lalr_item_set(); + + itm = new lalr_item(start_prod); + itm.lookahead().add(terminal.EOF); + + start_items.add(itm); + + /* create copy the item set to form the kernel */ + kernel = new lalr_item_set(start_items); + + /* create the closure from that item set */ + start_items.compute_closure(); + + /* build a state out of that item set and put it in our work set */ + start_state = new lalr_state(start_items); + work_stack.push(start_state); + + /* enter the state using the kernel as the key */ + _all_kernels.put(kernel, start_state); + + /* continue looking at new states until we have no more work to do */ + while (!work_stack.empty()) + { + /* remove a state from the work set */ + st = (lalr_state)work_stack.pop(); + + /* gather up all the symbols that appear before dots */ + outgoing = new symbol_set(); + for (i = st.items().all(); i.hasMoreElements(); ) + { + itm = (lalr_item)i.nextElement(); + + /* add the symbol before the dot (if any) to our collection */ + sym = itm.symbol_after_dot(); + if (sym != null) outgoing.add(sym); + } + + /* now create a transition out for each individual symbol */ + for (s = outgoing.all(); s.hasMoreElements(); ) + { + sym = (symbol)s.nextElement(); + + /* will be keeping the set of items with propagate links */ + linked_items = new lalr_item_set(); + + /* gather up shifted versions of all the items that have this + symbol before the dot */ + new_items = new lalr_item_set(); + for (i = st.items().all(); i.hasMoreElements();) + { + itm = (lalr_item)i.nextElement(); + + /* if this is the symbol we are working on now, add to set */ + sym2 = itm.symbol_after_dot(); + if (sym.equals(sym2)) + { + /* add to the kernel of the new state */ + new_items.add(itm.shift()); + + /* remember that itm has propagate link to it */ + linked_items.add(itm); + } + } + + /* use new items as state kernel */ + kernel = new lalr_item_set(new_items); + + /* have we seen this one already? */ + new_st = (lalr_state)_all_kernels.get(kernel); + + /* if we haven't, build a new state out of the item set */ + if (new_st == null) + { + /* compute closure of the kernel for the full item set */ + new_items.compute_closure(); + + /* build the new state */ + new_st = new lalr_state(new_items); + + /* add the new state to our work set */ + work_stack.push(new_st); + + /* put it in our kernel table */ + _all_kernels.put(kernel, new_st); + } + /* otherwise relink propagation to items in existing state */ + else + { + /* walk through the items that have links to the new state */ + for (fix = linked_items.all(); fix.hasMoreElements(); ) + { + fix_itm = (lalr_item)fix.nextElement(); + + /* look at each propagate link out of that item */ + for (int l =0; l < fix_itm.propagate_items().size(); l++) + { + /* pull out item linked to in the new state */ + new_itm = + (lalr_item)fix_itm.propagate_items().elementAt(l); + + /* find corresponding item in the existing state */ + existing = new_st.items().find(new_itm); + + /* fix up the item so it points to the existing set */ + if (existing != null) + fix_itm.propagate_items().setElementAt(existing ,l); + } + } + } + + /* add a transition from current state to that state */ + st.add_transition(sym, new_st); + } + } + + /* all done building states */ + + /* propagate complete lookahead sets throughout the states */ + propagate_all_lookaheads(); + + return start_state; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Propagate lookahead sets out of this state. This recursively + * propagates to all items that have propagation links from some item + * in this state. + */ + protected void propagate_lookaheads() throws internal_error + { + /* recursively propagate out from each item in the state */ + for (Enumeration itm = items().all(); itm.hasMoreElements(); ) + ((lalr_item)itm.nextElement()).propagate_lookaheads(null); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Fill in the parse table entries for this state. There are two + * parse tables that encode the viable prefix recognition machine, an + * action table and a reduce-goto table. The rows in each table + * correspond to states of the machine. The columns of the action table + * are indexed by terminal symbols and correspond to either transitions + * out of the state (shift entries) or reductions from the state to some + * previous state saved on the stack (reduce entries). All entries in the + * action table that are not shifts or reduces, represent errors. The + * reduce-goto table is indexed by non terminals and represents transitions + * out of a state on that non-terminal.

+ * Conflicts occur if more than one action needs to go in one entry of the + * action table (this cannot happen with the reduce-goto table). Conflicts + * are resolved by always shifting for shift/reduce conflicts and choosing + * the lowest numbered production (hence the one that appeared first in + * the specification) in reduce/reduce conflicts. All conflicts are + * reported and if more conflicts are detected than were declared by the + * user, code generation is aborted. + * + * @param act_table the action table to put entries in. + * @param reduce_table the reduce-goto table to put entries in. + */ + public void build_table_entries( + parse_action_table act_table, + parse_reduce_table reduce_table) + throws internal_error + { + parse_action_row our_act_row; + parse_reduce_row our_red_row; + lalr_item itm; + parse_action act, other_act; + symbol sym; + terminal_set conflict_set = new terminal_set(); + + /* pull out our rows from the tables */ + our_act_row = act_table.under_state[index()]; + our_red_row = reduce_table.under_state[index()]; + + /* consider each item in our state */ + for (Enumeration i = items().all(); i.hasMoreElements(); ) + { + itm = (lalr_item)i.nextElement(); + + + /* if its completed (dot at end) then reduce under the lookahead */ + if (itm.dot_at_end()) + { + act = new reduce_action(itm.the_production()); + + /* consider each lookahead symbol */ + for (int t = 0; t < terminal.number(); t++) + { + /* skip over the ones not in the lookahead */ + if (!itm.lookahead().contains(t)) continue; + + /* if we don't already have an action put this one in */ + if (our_act_row.under_term[t].kind() == + parse_action.ERROR) + { + our_act_row.under_term[t] = act; + } + else + { + /* we now have at least one conflict */ + terminal term = terminal.find(t); + other_act = our_act_row.under_term[t]; + + /* if the other act was not a shift */ + if ((other_act.kind() != parse_action.SHIFT) && + (other_act.kind() != parse_action.NONASSOC)) + { + /* if we have lower index hence priority, replace it*/ + if (itm.the_production().index() < + ((reduce_action)other_act).reduce_with().index()) + { + /* replace the action */ + our_act_row.under_term[t] = act; + } + } else { + /* Check precedences,see if problem is correctable */ + if(fix_with_precedence(itm.the_production(), + t, our_act_row, act)) { + term = null; + } + } + if(term!=null) { + + conflict_set.add(term); + } + } + } + } + } + + /* consider each outgoing transition */ + for (lalr_transition trans=transitions(); trans!=null; trans=trans.next()) + { + /* if its on an terminal add a shift entry */ + sym = trans.on_symbol(); + if (!sym.is_non_term()) + { + act = new shift_action(trans.to_state()); + + /* if we don't already have an action put this one in */ + if ( our_act_row.under_term[sym.index()].kind() == + parse_action.ERROR) + { + our_act_row.under_term[sym.index()] = act; + } + else + { + /* we now have at least one conflict */ + production p = ((reduce_action)our_act_row.under_term[sym.index()]).reduce_with(); + + /* shift always wins */ + if (!fix_with_precedence(p, sym.index(), our_act_row, act)) { + our_act_row.under_term[sym.index()] = act; + conflict_set.add(terminal.find(sym.index())); + } + } + } + else + { + /* for non terminals add an entry to the reduce-goto table */ + our_red_row.under_non_term[sym.index()] = trans.to_state(); + } + } + + /* if we end up with conflict(s), report them */ + if (!conflict_set.empty()) + report_conflicts(conflict_set); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + + /** Procedure that attempts to fix a shift/reduce error by using + * precedences. --frankf 6/26/96 + * + * if a production (also called rule) or the lookahead terminal + * has a precedence, then the table can be fixed. if the rule + * has greater precedence than the terminal, a reduce by that rule + * in inserted in the table. If the terminal has a higher precedence, + * it is shifted. if they have equal precedence, then the associativity + * of the precedence is used to determine what to put in the table: + * if the precedence is left associative, the action is to reduce. + * if the precedence is right associative, the action is to shift. + * if the precedence is non associative, then it is a syntax error. + * + * @param p the production + * @param term_index the index of the lokahead terminal + * @param parse_action_row a row of the action table + * @param act the rule in conflict with the table entry + */ + + protected boolean fix_with_precedence( + production p, + int term_index, + parse_action_row table_row, + parse_action act) + + throws internal_error { + + terminal term = terminal.find(term_index); + + /* if the production has a precedence number, it can be fixed */ + if (p.precedence_num() > assoc.no_prec) { + + /* if production precedes terminal, put reduce in table */ + if (p.precedence_num() > term.precedence_num()) { + table_row.under_term[term_index] = + insert_reduce(table_row.under_term[term_index],act); + return true; + } + + /* if terminal precedes rule, put shift in table */ + else if (p.precedence_num() < term.precedence_num()) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + else { /* they are == precedence */ + + /* equal precedences have equal sides, so only need to + look at one: if it is right, put shift in table */ + if (term.precedence_side() == assoc.right) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + + /* if it is left, put reduce in table */ + else if (term.precedence_side() == assoc.left) { + table_row.under_term[term_index] = + insert_reduce(table_row.under_term[term_index],act); + return true; + } + + /* if it is nonassoc, we're not allowed to have two nonassocs + of equal precedence in a row, so put in NONASSOC */ + else if (term.precedence_side() == assoc.nonassoc) { + table_row.under_term[term_index] = new nonassoc_action(); + return true; + } else { + /* something really went wrong */ + throw new internal_error("Unable to resolve conflict correctly"); + } + } + } + /* check if terminal has precedence, if so, shift, since + rule does not have precedence */ + else if (term.precedence_num() > assoc.no_prec) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + + /* otherwise, neither the rule nor the terminal has a precedence, + so it can't be fixed. */ + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + + /* given two actions, and an action type, return the + action of that action type. give an error if they are of + the same action, because that should never have tried + to be fixed + + */ + protected parse_action insert_action( + parse_action a1, + parse_action a2, + int act_type) + throws internal_error + { + if ((a1.kind() == act_type) && (a2.kind() == act_type)) { + throw new internal_error("Conflict resolution of bogus actions"); + } else if (a1.kind() == act_type) { + return a1; + } else if (a2.kind() == act_type) { + return a2; + } else { + throw new internal_error("Conflict resolution of bogus actions"); + } + } + + /* find the shift in the two actions */ + protected parse_action insert_shift( + parse_action a1, + parse_action a2) + throws internal_error + { + return insert_action(a1, a2, parse_action.SHIFT); + } + + /* find the reduce in the two actions */ + protected parse_action insert_reduce( + parse_action a1, + parse_action a2) + throws internal_error + { + return insert_action(a1, a2, parse_action.REDUCE); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce warning messages for all conflicts found in this state. */ + protected void report_conflicts(terminal_set conflict_set) + throws internal_error + { + lalr_item itm, compare; + symbol shift_sym; + + boolean after_itm; + + /* consider each element */ + for (Enumeration itms = items().all(); itms.hasMoreElements(); ) + { + itm = (lalr_item)itms.nextElement(); + + /* clear the S/R conflict set for this item */ + + /* if it results in a reduce, it could be a conflict */ + if (itm.dot_at_end()) + { + /* not yet after itm */ + after_itm = false; + + /* compare this item against all others looking for conflicts */ + for (Enumeration comps = items().all(); comps.hasMoreElements(); ) + { + compare = (lalr_item)comps.nextElement(); + + /* if this is the item, next one is after it */ + if (itm == compare) after_itm = true; + + /* only look at it if its not the same item */ + if (itm != compare) + { + /* is it a reduce */ + if (compare.dot_at_end()) + { + /* only look at reduces after itm */ + if (after_itm) + /* does the comparison item conflict? */ + if (compare.lookahead().intersects(itm.lookahead())) + /* report a reduce/reduce conflict */ + report_reduce_reduce(itm, compare); + } + } + } + /* report S/R conflicts under all the symbols we conflict under */ + for (int t = 0; t < terminal.number(); t++) + if (conflict_set.contains(t)) + report_shift_reduce(itm,t); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a warning message for one reduce/reduce conflict. + * + * @param itm1 first item in conflict. + * @param itm2 second item in conflict. + */ + protected void report_reduce_reduce(lalr_item itm1, lalr_item itm2) + throws internal_error + { + boolean comma_flag = false; + + System.err.println("*** Reduce/Reduce conflict found in state #"+index()); + System.err.print (" between "); + System.err.println(itm1.to_simple_string()); + System.err.print (" and "); + System.err.println(itm2.to_simple_string()); + System.err.print(" under symbols: {" ); + for (int t = 0; t < terminal.number(); t++) + { + if (itm1.lookahead().contains(t) && itm2.lookahead().contains(t)) + { + if (comma_flag) System.err.print(", "); else comma_flag = true; + System.err.print(terminal.find(t).name()); + } + } + System.err.println("}"); + System.err.print(" Resolved in favor of "); + if (itm1.the_production().index() < itm2.the_production().index()) + System.err.println("the first production.\n"); + else + System.err.println("the second production.\n"); + + /* count the conflict */ + emit.num_conflicts++; + lexer.warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a warning message for one shift/reduce conflict. + * + * @param red_itm the item with the reduce. + * @param conflict_sym the index of the symbol conflict occurs under. + */ + protected void report_shift_reduce( + lalr_item red_itm, + int conflict_sym) + throws internal_error + { + lalr_item itm; + symbol shift_sym; + + /* emit top part of message including the reduce item */ + System.err.println("*** Shift/Reduce conflict found in state #"+index()); + System.err.print (" between "); + System.err.println(red_itm.to_simple_string()); + + /* find and report on all items that shift under our conflict symbol */ + for (Enumeration itms = items().all(); itms.hasMoreElements(); ) + { + itm = (lalr_item)itms.nextElement(); + + /* only look if its not the same item and not a reduce */ + if (itm != red_itm && !itm.dot_at_end()) + { + /* is it a shift on our conflicting terminal */ + shift_sym = itm.symbol_after_dot(); + if (!shift_sym.is_non_term() && shift_sym.index() == conflict_sym) + { + /* yes, report on it */ + System.err.println(" and " + itm.to_simple_string()); + } + } + } + System.err.println(" under symbol "+ terminal.find(conflict_sym).name()); + System.err.println(" Resolved in favor of shifting.\n"); + + /* count the conflict */ + emit.num_conflicts++; + lexer.warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(lalr_state other) + { + /* we are equal if our item sets are equal */ + return other != null && items().equals(other.items()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_state)) + return false; + else + return equals((lalr_state)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + /* just use the item set hash code */ + return items().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + String result; + lalr_transition tr; + + /* dump the item set */ + result = "lalr_state [" + index() + "]: " + _items + "\n"; + + /* do the transitions */ + for (tr = transitions(); tr != null; tr = tr.next()) + { + result += tr; + result += "\n"; + } + + return result; + } + + /*-----------------------------------------------------------*/ +} diff --git a/Robust/cup/java_cup/lalr_transition.class b/Robust/cup/java_cup/lalr_transition.class new file mode 100644 index 0000000000000000000000000000000000000000..4d33e8dd2c4afa700fdeccd96d247936894f2fa0 GIT binary patch literal 1508 zcma)6ZBNrs6n-unYgfvP<5e755OM1^2EL*o3J3~L{D5MJF-x~KSkkpi*BSg*n!uJw zq90BCQO0xEx|T_dU(UTf=Q+=L?fv=d>o)+4*p)DboPc=|c?msO5V07?C~k3an~OUV ziMs;sNsy2eai5<{T=_u4LoAC};hIMhR`HnMo`_fzur6SOK`Po-vHq!AvQ36dg(K~w zRxCGac~7;>5HGrRvF>WF&M+F-P0e&XHDP*-mVWFqOm^8_N3-gNYuFZnVk?GaxT_2s zsQ~7O2^1mTE@g-;z0VNcuq%|(V8O8T-A1*fJFm5pNg8SMxUAQB&^kliLe{gwtB) z`j}R$=~jgycM+hy0bw7%6dKN8Ckd~6eC%441~uF<1WQ3bh+$Rq<90UN49V2Cw_O); zW14>4G5Yl*i1G&0Ey{b`KB>)g#=v;5=`pxQUmw~?U_otxWqzRl3_S;lNDI;L**{;s z{7cQ8BBo|fA*i`ih+oK;K_NMZILS$hlY~gj3F00jZUr;AK?71Ti#*+?2^A%uo_72h zKmIJ~B4iQOOqR6}4|w@=1@aWIaL$)TP7FNvDLNUQz3K^KpXuTy#0vyHU5tXxk?e*F z-OzOc-9+jFsMrnNArLK=4|OO-p5*Qsq=Odv5^@v$Y7+xZ4ALzzM50OWqHoS{>j{J= j5={(u84@EtI1|K7P;-DcRKY%$@D>FeP~;5hdXW7M!RcE{ literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/lalr_transition.java b/Robust/cup/java_cup/lalr_transition.java new file mode 100644 index 00000000..1c941bd9 --- /dev/null +++ b/Robust/cup/java_cup/lalr_transition.java @@ -0,0 +1,93 @@ +package java_cup; + +/** This class represents a transition in an LALR viable prefix recognition + * machine. Transitions can be under terminals for non-terminals. They are + * internally linked together into singly linked lists containing all the + * transitions out of a single state via the _next field. + * + * @see java_cup.lalr_state + * @version last updated: 11/25/95 + * @author Scott Hudson + * + */ +public class lalr_transition { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param on_sym symbol we are transitioning on. + * @param to_st state we transition to. + * @param nxt next transition in linked list. + */ + public lalr_transition(symbol on_sym, lalr_state to_st, lalr_transition nxt) + throws internal_error + { + /* sanity checks */ + if (on_sym == null) + throw new internal_error("Attempt to create transition on null symbol"); + if (to_st == null) + throw new internal_error("Attempt to create transition to null state"); + + /* initialize */ + _on_symbol = on_sym; + _to_state = to_st; + _next = nxt; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with null next. + * @param on_sym symbol we are transitioning on. + * @param to_st state we transition to. + */ + public lalr_transition(symbol on_sym, lalr_state to_st) throws internal_error + { + this(on_sym, to_st, null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The symbol we make the transition on. */ + protected symbol _on_symbol; + + /** The symbol we make the transition on. */ + public symbol on_symbol() {return _on_symbol;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The state we transition to. */ + protected lalr_state _to_state; + + /** The state we transition to. */ + public lalr_state to_state() {return _to_state;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Next transition in linked list of transitions out of a state */ + protected lalr_transition _next; + + /** Next transition in linked list of transitions out of a state */ + public lalr_transition next() {return _next;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Convert to a string. */ + public String toString() + { + String result; + + result = "transition on " + on_symbol().name() + " to state ["; + result += _to_state.index(); + result += "]"; + + return result; + } + + /*-----------------------------------------------------------*/ +} diff --git a/Robust/cup/java_cup/lexer.class b/Robust/cup/java_cup/lexer.class new file mode 100644 index 0000000000000000000000000000000000000000..e633ff282a6d27e856a76e888110dfa377d78340 GIT binary patch literal 5298 zcma)A34D{~8UMd&+I$J24J}tg!6*WyP%0n_Euc_AJ4#_zz=B%SkBK+l zir2uSLDA~e4T>w(;(g8oPu$db%yZjs+i&~ra)+}2^CoG&)?>EKdpytkKKJpaFMRdz zqX4Gka~FPybDUU?a}E5+f%9CjW3vklIN!hp1}-#kk%5a1Tw>r-16vHV8o12B15b)nPZ@aH zz%v4R)`90ln9UA6@4znI8pcZPMQoHft2z!n8TD zsl6o{<}r7mBOW&+$>wk_K~+Qj^Ub^bOU7^YpU4N@0Lnr&uW&b{cyOL$qKAk-d< z#;J&1wBX(!NPDy(=8q>#MxK#0S}iYZi14JKC;_BP&e;9WO< zjdgCEjz;RVDjl8aJAUEOj))uY;e9tg5UD~4D3mwG%s{9$6!43Ye693=&x`~UzEC6) z3YtE@FB2GUoPl);l}r8M)@Z!l3}z8L=}QbCQd#K>wMC+FlVLIP>ngRjibhkv2V?Tj z24P8#PAxN;K23Z5Lovl~GN${62$jhANX~rhMpX3Qh@=~zh_y?``*eV&L%DpiZ{B=b z@>8)?3}-5gUCcZW`dG2z{)idvNcdtVgEW%#C8(YoaS6?Ykm~@0VDyRzBP7}u37sXz z$qMP4B-}q!uuY=3+>?Dd>$njXlcrT0Sh1LfqOev-rvq~;XMtrcXP5!9Oy3MetLm2Z z7ZV09Gn)k>FV?{$v#sSLeXqt+P%@Bof>-I3%76wiY}}Mcn(fpf#Kg#ySYaC>4@Ro# zZ)YXQNs|Lp8e$m-tck2Pc`RyH0?S!pas&$eu^3~IL1q;?oe4Eo5eFm(IhRpmi&BHp zMlzZPDGbllvb3rh(iYJz0!hUY@xoL&ug#<_CtAh&F3TCbru&mPqgI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dd+MUJAb7ODq! zwHH3sYoV;aSfq{1N-y;rs*&dN_&UJ`RqAneO7+#Hv_xixE~A2>oXW)R0q%NnT#c8} zTtwT8_1GJa*(IkKL-Qntsu}PZoM)IIwUfM_c`1}|nMD=%n_nLi3KLRTpbwXNVkt}) zV)2wz#4#Q-g+tjMJb{!*AVkuC+JB>kRPiFlt59K%vOhDOwe&h?nR$!54(c{>c1qd= zrDVP8#qlCJE73ODoFE&9J|9ulO?heY(sjFz_8yQ1KPXQhA6kdx}S z_>uY}w$N4As=u+3{~deOKhdMUz(eX^*vCfwnEDU@WA!EWvsr(}X8k)`0sdff;lH*a z{2o-OhT4Xyv9{rAsjXBkw|On0V6cH@-?XRd_5xJ)p`ppcm)WvCu<145e_W4bH`N`L u^VmFgCVnh^V;mfe>g6n}t1+7YGALtV_3>43IBR}6zk4daSmX(Q_WuCZOb8 + * Symbols currently returned include:

+ *    Symbol        Constant Returned     Symbol        Constant Returned
+ *    ------        -----------------     ------        -----------------
+ *    "package"     PACKAGE               "import"      IMPORT 
+ *    "code"        CODE                  "action"      ACTION 
+ *    "parser"      PARSER                "terminal"    TERMINAL
+ *    "non"         NON                   "init"        INIT 
+ *    "scan"        SCAN                  "with"        WITH
+ *    "start"       START                 "precedence"  PRECEDENCE
+ *    "left"        LEFT		  "right"       RIGHT
+ *    "nonassoc"    NONASSOC		  "%prec        PRECENT_PREC  
+ *      [           LBRACK                  ]           RBRACK
+ *      ;           SEMI 
+ *      ,           COMMA                   *           STAR 
+ *      .           DOT                     :           COLON
+ *      ::=         COLON_COLON_EQUALS      |           BAR
+ *    identifier    ID                    {:...:}       CODE_STRING
+ *    "nonterminal" NONTERMINAL
+ *  
+ * All symbol constants are defined in sym.java which is generated by + * JavaCup from parser.cup.

+ * + * In addition to the scanner proper (called first via init() then with + * next_token() to get each Symbol) this class provides simple error and + * warning routines and keeps a count of errors and warnings that is + * publicly accessible.

+ * + * This class is "static" (i.e., it has only static members and methods). + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ +public class lexer { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The only constructor is private, so no instances can be created. */ + private lexer() { } + + /*-----------------------------------------------------------*/ + /*--- Static (Class) Variables ------------------------------*/ + /*-----------------------------------------------------------*/ + + /** First character of lookahead. */ + protected static int next_char; + + /** Second character of lookahead. */ + protected static int next_char2; + + /** Second character of lookahead. */ + protected static int next_char3; + + /** Second character of lookahead. */ + protected static int next_char4; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** EOF constant. */ + protected static final int EOF_CHAR = -1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of keywords. Keywords are initially treated as identifiers. + * Just before they are returned we look them up in this table to see if + * they match one of the keywords. The string of the name is the key here, + * which indexes Integer objects holding the symbol number. + */ + protected static Hashtable keywords = new Hashtable(23); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of single character symbols. For ease of implementation, we + * store all unambiguous single character Symbols in this table of Integer + * objects keyed by Integer objects with the numerical value of the + * appropriate char (currently Character objects have a bug which precludes + * their use in tables). + */ + protected static Hashtable char_symbols = new Hashtable(11); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Current line number for use in error messages. */ + protected static int current_line = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Character position in current line. */ + protected static int current_position = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Character position in current line. */ + protected static int absolute_position = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of total errors detected so far. */ + public static int error_count = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of warnings issued so far */ + public static int warning_count = 0; + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Initialize the scanner. This sets up the keywords and char_symbols + * tables and reads the first two characters of lookahead. + */ + public static void init() throws java.io.IOException + { + /* set up the keyword table */ + keywords.put("package", new Integer(sym.PACKAGE)); + keywords.put("import", new Integer(sym.IMPORT)); + keywords.put("code", new Integer(sym.CODE)); + keywords.put("action", new Integer(sym.ACTION)); + keywords.put("parser", new Integer(sym.PARSER)); + keywords.put("terminal", new Integer(sym.TERMINAL)); + keywords.put("non", new Integer(sym.NON)); + keywords.put("nonterminal",new Integer(sym.NONTERMINAL));// [CSA] + keywords.put("init", new Integer(sym.INIT)); + keywords.put("scan", new Integer(sym.SCAN)); + keywords.put("with", new Integer(sym.WITH)); + keywords.put("start", new Integer(sym.START)); + keywords.put("precedence", new Integer(sym.PRECEDENCE)); + keywords.put("left", new Integer(sym.LEFT)); + keywords.put("right", new Integer(sym.RIGHT)); + keywords.put("nonassoc", new Integer(sym.NONASSOC)); + + /* set up the table of single character symbols */ + char_symbols.put(new Integer(';'), new Integer(sym.SEMI)); + char_symbols.put(new Integer(','), new Integer(sym.COMMA)); + char_symbols.put(new Integer('*'), new Integer(sym.STAR)); + char_symbols.put(new Integer('.'), new Integer(sym.DOT)); + char_symbols.put(new Integer('|'), new Integer(sym.BAR)); + char_symbols.put(new Integer('['), new Integer(sym.LBRACK)); + char_symbols.put(new Integer(']'), new Integer(sym.RBRACK)); + + /* read two characters of lookahead */ + next_char = System.in.read(); + if (next_char == EOF_CHAR) { + next_char2 = EOF_CHAR; + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char2 = System.in.read(); + if (next_char2 == EOF_CHAR) { + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char3 = System.in.read(); + if (next_char3 == EOF_CHAR) { + next_char4 = EOF_CHAR; + } else { + next_char4 = System.in.read(); + } + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Advance the scanner one character in the input stream. This moves + * next_char2 to next_char and then reads a new next_char2. + */ + protected static void advance() throws java.io.IOException + { + int old_char; + + old_char = next_char; + next_char = next_char2; + if (next_char == EOF_CHAR) { + next_char2 = EOF_CHAR; + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char2 = next_char3; + if (next_char2 == EOF_CHAR) { + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char3 = next_char4; + if (next_char3 == EOF_CHAR) { + next_char4 = EOF_CHAR; + } else { + next_char4 = System.in.read(); + } + } + } + + /* count this */ + absolute_position++; + current_position++; + if (old_char == '\n' || (old_char == '\r' && next_char!='\n')) + { + current_line++; + current_position = 1; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit an error message. The message will be marked with both the + * current line number and the position in the line. Error messages + * are printed on standard error (System.err). + * @param message the message to print. + */ + public static void emit_error(String message) + { + System.err.println("Error at " + current_line + "(" + current_position + + "): " + message); + error_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a warning message. The message will be marked with both the + * current line number and the position in the line. Messages are + * printed on standard error (System.err). + * @param message the message to print. + */ + public static void emit_warn(String message) + { + System.err.println("Warning at " + current_line + "(" + current_position + + "): " + message); + warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character is ok to start an id. + * @param ch the character in question. + */ + protected static boolean id_start_char(int ch) + { + /* allow for % in identifiers. a hack to allow my + %prec in. Should eventually make lex spec for this + frankf */ + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || + (ch == '_'); + + // later need to deal with non-8-bit chars here + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character is ok for the middle of an id. + * @param ch the character in question. + */ + protected static boolean id_char(int ch) + { + return id_start_char(ch) || (ch >= '0' && ch <= '9'); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Try to look up a single character symbol, returns -1 for not found. + * @param ch the character in question. + */ + protected static int find_single_char(int ch) + { + Integer result; + + result = (Integer)char_symbols.get(new Integer((char)ch)); + if (result == null) + return -1; + else + return result.intValue(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Handle swallowing up a comment. Both old style C and new style C++ + * comments are handled. + */ + protected static void swallow_comment() throws java.io.IOException + { + /* next_char == '/' at this point */ + + /* is it a traditional comment */ + if (next_char2 == '*') + { + /* swallow the opener */ + advance(); advance(); + + /* swallow the comment until end of comment or EOF */ + for (;;) + { + /* if its EOF we have an error */ + if (next_char == EOF_CHAR) + { + emit_error("Specification file ends inside a comment"); + return; + } + + /* if we can see the closer we are done */ + if (next_char == '*' && next_char2 == '/') + { + advance(); + advance(); + return; + } + + /* otherwise swallow char and move on */ + advance(); + } + } + + /* is its a new style comment */ + if (next_char2 == '/') + { + /* swallow the opener */ + advance(); advance(); + + /* swallow to '\n', '\r', '\f', or EOF */ + while (next_char != '\n' && next_char != '\r' && + next_char != '\f' && next_char!=EOF_CHAR) + advance(); + + return; + + } + + /* shouldn't get here, but... if we get here we have an error */ + emit_error("Malformed comment in specification -- ignored"); + advance(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Swallow up a code string. Code strings begin with "{:" and include + all characters up to the first occurrence of ":}" (there is no way to + include ":}" inside a code string). The routine returns a String + object suitable for return by the scanner. + */ + protected static Symbol do_code_string() throws java.io.IOException + { + StringBuffer result = new StringBuffer(); + + /* at this point we have lookahead of "{:" -- swallow that */ + advance(); advance(); + + /* save chars until we see ":}" */ + while (!(next_char == ':' && next_char2 == '}')) + { + /* if we have run off the end issue a message and break out of loop */ + if (next_char == EOF_CHAR) + { + emit_error("Specification file ends inside a code string"); + break; + } + + /* otherwise record the char and move on */ + result.append(new Character((char)next_char)); + advance(); + } + + /* advance past the closer and build a return Symbol */ + advance(); advance(); + return new Symbol(sym.CODE_STRING, result.toString()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Process an identifier. Identifiers begin with a letter, underscore, + * or dollar sign, which is followed by zero or more letters, numbers, + * underscores or dollar signs. This routine returns a String suitable + * for return by the scanner. + */ + protected static Symbol do_id() throws java.io.IOException + { + StringBuffer result = new StringBuffer(); + String result_str; + Integer keyword_num; + char buffer[] = new char[1]; + + /* next_char holds first character of id */ + buffer[0] = (char)next_char; + result.append(buffer,0,1); + advance(); + + /* collect up characters while they fit in id */ + while(id_char(next_char)) + { + buffer[0] = (char)next_char; + result.append(buffer,0,1); + advance(); + } + + /* extract a string and try to look it up as a keyword */ + result_str = result.toString(); + keyword_num = (Integer)keywords.get(result_str); + + /* if we found something, return that keyword */ + if (keyword_num != null) + return new Symbol(keyword_num.intValue()); + + /* otherwise build and return an id Symbol with an attached string */ + return new Symbol(sym.ID, result_str); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return one Symbol. This is the main external interface to the scanner. + * It consumes sufficient characters to determine the next input Symbol + * and returns it. To help with debugging, this routine actually calls + * real_next_token() which does the work. If you need to debug the + * parser, this can be changed to call debug_next_token() which prints + * a debugging message before returning the Symbol. + */ + public static Symbol next_token() throws java.io.IOException + { + return real_next_token(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Debugging version of next_token(). This routine calls the real scanning + * routine, prints a message on System.out indicating what the Symbol is, + * then returns it. + */ + public static Symbol debug_next_token() throws java.io.IOException + { + Symbol result = real_next_token(); + System.out.println("# next_Symbol() => " + result.sym); + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The actual routine to return one Symbol. This is normally called from + * next_token(), but for debugging purposes can be called indirectly from + * debug_next_token(). + */ + protected static Symbol real_next_token() throws java.io.IOException + { + int sym_num; + + for (;;) + { + /* look for white space */ + if (next_char == ' ' || next_char == '\t' || next_char == '\n' || + next_char == '\f' || next_char == '\r') + { + /* advance past it and try the next character */ + advance(); + continue; + } + + /* look for a single character symbol */ + sym_num = find_single_char(next_char); + if (sym_num != -1) + { + /* found one -- advance past it and return a Symbol for it */ + advance(); + return new Symbol(sym_num); + } + + /* look for : or ::= */ + if (next_char == ':') + { + /* if we don't have a second ':' return COLON */ + if (next_char2 != ':') + { + advance(); + return new Symbol(sym.COLON); + } + + /* move forward and look for the '=' */ + advance(); + if (next_char2 == '=') + { + advance(); advance(); + return new Symbol(sym.COLON_COLON_EQUALS); + } + else + { + /* return just the colon (already consumed) */ + return new Symbol(sym.COLON); + } + } + + /* find a "%prec" string and return it. otherwise, a '%' was found, + which has no right being in the specification otherwise */ + if (next_char == '%') { + advance(); + if ((next_char == 'p') && (next_char2 == 'r') && (next_char3 == 'e') && + (next_char4 == 'c')) { + advance(); + advance(); + advance(); + advance(); + return new Symbol(sym.PERCENT_PREC); + } else { + emit_error("Found extraneous percent sign"); + } + } + + /* look for a comment */ + if (next_char == '/' && (next_char2 == '*' || next_char2 == '/')) + { + /* swallow then continue the scan */ + swallow_comment(); + continue; + } + + /* look for start of code string */ + if (next_char == '{' && next_char2 == ':') + return do_code_string(); + + /* look for an id or keyword */ + if (id_start_char(next_char)) return do_id(); + + /* look for EOF */ + if (next_char == EOF_CHAR) return new Symbol(sym.EOF); + + /* if we get here, we have an unrecognized character */ + emit_warn("Unrecognized character '" + + new Character((char)next_char) + "'(" + next_char + + ") -- ignored"); + + /* advance past it */ + advance(); + } + } + + /*-----------------------------------------------------------*/ +} + diff --git a/Robust/cup/java_cup/lr_item_core.class b/Robust/cup/java_cup/lr_item_core.class new file mode 100644 index 0000000000000000000000000000000000000000..e5988e7fe2a1abd5975bf4523a4001d325911ac4 GIT binary patch literal 3162 zcma)8TWl0%6#oA1c6Ym-UMQ4OY;mAf+TALm$faNrD`;hDRW4dohUs?NUEJ<0yHf@6 zeiwZ-8t?@#Nnd!tDBDC5ga>P4eDKi+O^h)lnix&I#u)WGv(w#aDT&$SzkcWZ=klF1 z``JGqod>WMuSU_0p&Bg3-C^7l!M#xguv_+fqS%Xl5!@%6`(-mMtNpT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HuND#3wP0^>zi<;uQ+- zXG;aXX8ZYu{oq^H?{^r&CI0pP9;5gHNAM%R)<2QpKa=3U;9dNRDg1`>_#L0%4}66` zdHR=X!QU#5OKPoBYOAVJyH#*bIq>W0(M7tBFjHfttv-`ra=KWjQhPzxpfojUl5V}K VdQ__hgj6G + * 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; + } + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/Robust/cup/java_cup/non_terminal.class b/Robust/cup/java_cup/non_terminal.class new file mode 100644 index 0000000000000000000000000000000000000000..88d8183d47aabd1996554613763d8ed4bf167b1c GIT binary patch literal 3771 zcmaJ@ZE#dq8Ga7gWH*~jQZ@-BX=pa`(PWo2P$@-1p-|Em8v=#2F;LuYb}z|=&F*&h zE`{0;ty({-)oQf{tF=<3S}Zh>U1+o)jzdRBopHv|{^+mjIOFt>Gx|gS7@zlk?A|QV zo!N8lIp;mk`@Em`{`x;}ya`|fei6iNn5su7(tc!us6kd15BZS`q7Hdkm@*XP?6@Bf z`*9)&4fz00%KS(GpOX2}AR6$P43CTW6Eb{ShR^u%WDqNm4RSFhD4&(#bAEhY=BEPq zf{1-lK)xh01nI<=Wq7&)U%^*pct)0Ali}+k{A>^rJnhFfWd5cM&&k=h8N@cRM07{Ct#cu6SGlphM}X+K_8@WtY(ltSy!(fILrf59|T z{ddRnlV*H8r4J}9mE+j>$(WH&>L(O}Y5j!hF4S%XzqOGz6#@rFcI+RC$>RzOEtV)` z`_q|p%+zyJMmnA%UdYJD^r>+@nbec9c)~O?X$5sqL5pQ`nPkD*$t%>y(uGt?NKj|& zh>^>ivAn(z+J%(^Lf36I(uTQB;l>`@m{dGH(SN|q8R?0EYj=9@r}1}Wl2p(%WTf@s z0%_$&Y?ZBxK*)s}%USI`y&iWBrVCSgE-t2!h3^PGr4U^V;D36hqi45`xR}f8h)-rz z-qTBm2NO9xZtAhL{xBDVClY#ARMTfJt;Il^6Pc-OL9SVDHByFo(n6$BA@{88W`Z>= z2uBk+EDTU%Jela~qz%j#H-QuyQ<=;$Zj=)v zU}o&_DzvyE@dllmwG%Tg%I8fi*XT};pAG7P76((mEBvtXo>66m&F zg>1@5Fv?-_>~ocbdo;X)AJcukVLJ(u8YW?g;(Z!^BHDLgr-oN$xLueovn;W6?56q& zJ*VLu_G|blUh~@Fb%%!Y7-en@kF3^khd{l83mQIw5e@fZzaOt_m_b6rMO@M_E>9CO z>@K^mDhD*o%6Snb4WAU{m!WI8f;TkG$?!A$+>bXkyoI+FcJ44ueJX2)%}kgn7B^NP(a<8*RJ@IT-mln|H#cx{JKeUjNS0BdmBx0<_w+FOW-^}Nlga6WW%Uix z5_Z##lC}o?G?bFwS5Z#H_>x!7S4q(&hqoqlp;DV z@X=;aXC3UM@BxfC!W#%8;>#lMqE=nt71F-`ZFE+yHIe}6UGa4tJFZ;6&$+(dA=e^y zchKk|`hZ?qh+s3lk2gp8zn`NWmxWAMo~vSd7y)U7WGF!#q;g@}OQv<98}6AyryCnm zZkj=t6^E`O!d7&;D;C)LAA=u{V~h|!0yS9R2OaR07BuLB%lJs;qOI{M&!u`C!UN8w zS2;^s9r6uyOk-osz-6r3v+fF3D@@P-oeygi=*c1aW9_N=zj3;8dj5kb6RyWMaCZK^ z%jk8*(e8>zhWq-8pzONQv-5wcM0*>WsOlN2e2$KIp6pMd6)!M>Uc_3wgg%_c&3G9b zaR#^YrL>E0ongF2U!TW8Tv%Yj;j#&*iC0%PVbn5VDC(NP2it^UQtETL&VNwmy2aP- zE8?atwe7Wimk=nT|J3~Zz5#h|uPtIdP55oagiTmVRadC;9V-1LO?a0k{E8<0hV*}j z&G(PoX1a)DEr$b&0PUQke1U!7*}>Qqowu zSw4Mk(9z-sox9QL`44^PYAP_6Y3h13s+Cx&Za|mnUSJx(j|eKJ4G~&MY;@XZq=b#q zJa6GZ

+ * + * I addition to construction and manipulation operations, productions provide + * methods for factoring out actions (see remove_embedded_actions()), for + * computing the nullability of the production (i.e., can it derive the empty + * string, see check_nullable()), and operations for computing its first + * set (i.e., the set of terminals that could appear at the beginning of some + * string derived from the production, see check_first_set()). + * + * @see java_cup.production_part + * @see java_cup.symbol_part + * @see java_cup.action_part + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class production { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. This constructor accepts a LHS non terminal, + * an array of RHS parts (including terminals, non terminals, and + * actions), and a string for a final reduce action. It does several + * manipulations in the process of creating a production object. + * After some validity checking it translates labels that appear in + * actions into code for accessing objects on the runtime parse stack. + * It them merges adjacent actions if they appear and moves any trailing + * action into the final reduce actions string. Next it removes any + * embedded actions by factoring them out with new action productions. + * Finally it assigns a unique index to the production.

+ * + * Factoring out of actions is accomplished by creating new "hidden" + * non terminals. For example if the production was originally:

+   *    A ::= B {action} C D
+   *  
+ * then it is factored into two productions:
+   *    A ::= B X C D
+   *    X ::= {action}
+   *  
+ * (where X is a unique new non terminal). This has the effect of placing + * all actions at the end where they can be handled as part of a reduce by + * the parser. + */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + String action_str) + throws internal_error + { + int i; + action_part tail_action; + String declare_str; + int rightlen = rhs_l; + + /* remember the length */ + if (rhs_l >= 0) + _rhs_length = rhs_l; + else if (rhs_parts != null) + _rhs_length = rhs_parts.length; + else + _rhs_length = 0; + + /* make sure we have a valid left-hand-side */ + if (lhs_sym == null) + throw new internal_error( + "Attempt to construct a production with a null LHS"); + + /* I'm not translating labels anymore, I'm adding code to declare + labels as valid variables. This way, the users code string is + untouched + 6/96 frankf */ + + /* check if the last part of the right hand side is an action. If + it is, it won't be on the stack, so we don't want to count it + in the rightlen. Then when we search down the stack for a + Symbol, we don't try to search past action */ + + if (rhs_l > 0) { + if (rhs_parts[rhs_l - 1].is_action()) { + rightlen = rhs_l - 1; + } else { + rightlen = rhs_l; + } + } + + /* get the generated declaration code for the necessary labels. */ + declare_str = declare_labels( + rhs_parts, rightlen, action_str); + + if (action_str == null) + action_str = declare_str; + else + action_str = declare_str + action_str; + + /* count use of lhs */ + lhs_sym.note_use(); + + /* create the part for left-hand-side */ + _lhs = new symbol_part(lhs_sym); + + /* merge adjacent actions (if any) */ + _rhs_length = merge_adjacent_actions(rhs_parts, _rhs_length); + + /* strip off any trailing action */ + tail_action = strip_trailing_action(rhs_parts, _rhs_length); + if (tail_action != null) _rhs_length--; + + /* Why does this run through the right hand side happen + over and over? here a quick combination of two + prior runs plus one I wanted of my own + frankf 6/25/96 */ + /* allocate and copy over the right-hand-side */ + /* count use of each rhs symbol */ + _rhs = new production_part[_rhs_length]; + for (i=0; i<_rhs_length; i++) { + _rhs[i] = rhs_parts[i]; + if (!_rhs[i].is_action()) { + ((symbol_part)_rhs[i]).the_symbol().note_use(); + if (((symbol_part)_rhs[i]).the_symbol() instanceof terminal) { + _rhs_prec = + ((terminal)((symbol_part)_rhs[i]).the_symbol()).precedence_num(); + _rhs_assoc = + ((terminal)((symbol_part)_rhs[i]).the_symbol()).precedence_side(); + } + } + } + + /*now action string is really declaration string, so put it in front! + 6/14/96 frankf */ + if (action_str == null) action_str = ""; + if (tail_action != null && tail_action.code_string() != null) + action_str = action_str + "\t\t" + tail_action.code_string(); + + /* stash the action */ + _action = new action_part(action_str); + + /* rewrite production to remove any embedded actions */ + remove_embedded_actions(); + + /* assign an index */ + _index = next_index++; + + /* put us in the global collection of productions */ + _all.put(new Integer(_index),this); + + /* put us in the production list of the lhs non terminal */ + lhs_sym.add_production(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with no action string. */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,null); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Constructor with precedence and associativity of production + contextually define */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + String action_str, + int prec_num, + int prec_side) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,action_str); + + /* set the precedence */ + set_precedence_num(prec_num); + set_precedence_side(prec_side); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Constructor w/ no action string and contextual precedence + defined */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + int prec_num, + int prec_side) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,null); + /* set the precedence */ + set_precedence_num(prec_num); + set_precedence_side(prec_side); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + + /** Table of all productions. Elements are stored using their index as + * the key. + */ + protected static Hashtable _all = new Hashtable(); + + /** Access to all productions. */ + public static Enumeration all() {return _all.elements();} + + /** Lookup a production by index. */ + public static production find(int indx) { + return (production) _all.get(new Integer(indx)); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of productions. */ + public static int number() {return _all.size();} + + /** Static counter for assigning unique index numbers. */ + protected static int next_index; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The left hand side non-terminal. */ + protected symbol_part _lhs; + + /** The left hand side non-terminal. */ + public symbol_part lhs() {return _lhs;} + + + /** The precedence of the rule */ + protected int _rhs_prec = -1; + protected int _rhs_assoc = -1; + + /** Access to the precedence of the rule */ + public int precedence_num() { return _rhs_prec; } + public int precedence_side() { return _rhs_assoc; } + + /** Setting the precedence of a rule */ + public void set_precedence_num(int prec_num) { + _rhs_prec = prec_num; + } + public void set_precedence_side(int prec_side) { + _rhs_assoc = prec_side; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** A collection of parts for the right hand side. */ + protected production_part _rhs[]; + + /** Access to the collection of parts for the right hand side. */ + public production_part rhs(int indx) throws internal_error + { + if (indx >= 0 && indx < _rhs_length) + return _rhs[indx]; + else + throw new internal_error( + "Index out of range for right hand side of production"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** How much of the right hand side array we are presently using. */ + protected int _rhs_length; + + /** How much of the right hand side array we are presently using. */ + public int rhs_length() {return _rhs_length;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** An action_part containing code for the action to be performed when we + * reduce with this production. + */ + protected action_part _action; + + /** An action_part containing code for the action to be performed when we + * reduce with this production. + */ + public action_part action() {return _action;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Index number of the production. */ + protected int _index; + + /** Index number of the production. */ + public int index() {return _index;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of number of reductions using this production. */ + protected int _num_reductions = 0; + + /** Count of number of reductions using this production. */ + public int num_reductions() {return _num_reductions;} + + /** Increment the count of reductions with this non-terminal */ + public void note_reduction_use() {_num_reductions++;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is the nullability of the production known or unknown? */ + protected boolean _nullable_known = false; + + /** Is the nullability of the production known or unknown? */ + public boolean nullable_known() {return _nullable_known;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Nullability of the production (can it derive the empty string). */ + protected boolean _nullable = false; + + /** Nullability of the production (can it derive the empty string). */ + public boolean nullable() {return _nullable;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** First set of the production. This is the set of terminals that + * could appear at the front of some string derived from this production. + */ + protected terminal_set _first_set = new terminal_set(); + + /** First set of the production. This is the set of terminals that + * could appear at the front of some string derived from this production. + */ + public terminal_set first_set() {return _first_set;} + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Determine if a given character can be a label id starter. + * @param c the character in question. + */ + protected static boolean is_id_start(char c) + { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_'); + + //later need to handle non-8-bit chars here + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character can be in a label id. + * @param c the character in question. + */ + protected static boolean is_id_char(char c) + { + return is_id_start(c) || (c >= '0' && c <= '9'); + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + + /** Return label declaration code + * @param labelname the label name + * @param stack_type the stack type of label? + * @author frankf + */ + protected String make_declaration( + String labelname, + String stack_type, + int offset) + { + String ret; + + /* Put in the left/right value labels */ + if (emit.lr_values()) + ret = "\t\tint " + labelname + "left = ((java_cup.runtime.Symbol)" + + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).left;\n" + + "\t\tint " + labelname + "right = ((java_cup.runtime.Symbol)" + + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).right;\n"; + else ret = ""; + + /* otherwise, just declare label. */ + return ret + "\t\t" + stack_type + " " + labelname + " = (" + stack_type + + ")((" + "java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).value;\n"; + + } + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Declare label names as valid variables within the action string + * @param rhs array of RHS parts. + * @param rhs_len how much of rhs to consider valid. + * @param final_action the final action string of the production. + * @param lhs_type the object type associated with the LHS symbol. + */ + protected String declare_labels( + production_part rhs[], + int rhs_len, + String final_action) + { + String declaration = ""; + + symbol_part part; + action_part act_part; + int pos; + + /* walk down the parts and extract the labels */ + for (pos = 0; pos < rhs_len; pos++) + { + if (!rhs[pos].is_action()) + { + part = (symbol_part)rhs[pos]; + + /* if it has a label, make declaration! */ + if (part.label() != null) + { + declaration = declaration + + make_declaration(part.label(), part.the_symbol().stack_type(), + rhs_len-pos-1); + } + } + } + return declaration; + } + + + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to merge adjacent actions in a set of RHS parts + * @param rhs_parts array of RHS parts. + * @param len amount of that array that is valid. + * @return remaining valid length. + */ + protected int merge_adjacent_actions(production_part rhs_parts[], int len) + { + int from_loc, to_loc, merge_cnt; + + /* bail out early if we have no work to do */ + if (rhs_parts == null || len == 0) return 0; + + merge_cnt = 0; + to_loc = -1; + for (from_loc=0; from_loc + * A ::= B {action1} C {action2} D + * + * then it will be factored into:
+   *    A ::= B NT$1 C NT$2 D
+   *    NT$1 ::= {action1}
+   *    NT$2 ::= {action2}
+   *  
+ * where NT$1 and NT$2 are new system created non terminals. + */ + + /* the declarations added to the parent production are also passed along, + as they should be perfectly valid in this code string, since it + was originally a code string in the parent, not on its own. + frank 6/20/96 */ + protected void remove_embedded_actions( + + ) throws internal_error + { + non_terminal new_nt; + production new_prod; + String declare_str; + + /* walk over the production and process each action */ + for (int act_loc = 0; act_loc < rhs_length(); act_loc++) + if (rhs(act_loc).is_action()) + { + + + declare_str = declare_labels( + _rhs, act_loc, ""); + /* create a new non terminal for the action production */ + new_nt = non_terminal.create_new(); + new_nt.is_embedded_action = true; /* 24-Mar-1998, CSA */ + + /* create a new production with just the action */ + new_prod = new action_production(this, new_nt, null, 0, + declare_str + ((action_part)rhs(act_loc)).code_string()); + + /* replace the action with the generated non terminal */ + _rhs[act_loc] = new symbol_part(new_nt); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Check to see if the production (now) appears to be nullable. + * A production is nullable if its RHS could derive the empty string. + * This results when the RHS is empty or contains only non terminals + * which themselves are nullable. + */ + public boolean check_nullable() throws internal_error + { + production_part part; + symbol sym; + int pos; + + /* if we already know bail out early */ + if (nullable_known()) return nullable(); + + /* if we have a zero size RHS we are directly nullable */ + if (rhs_length() == 0) + { + /* stash and return the result */ + return set_nullable(true); + } + + /* otherwise we need to test all of our parts */ + for (pos=0; pospJlxou_2$g+Fxz2|=4`ObIx>-U#$0Pf(fiX!R-NVulba$Us@EXi2r zhnxJ+kkM43pw1UVfyv`71uHUE8S)+1>e?=YzIkB1w_2{{?X|X}(DC-#lzrrQPV|_e z(wIy)cNoNVzi%^?HXYC2ir;qa@Rikd=|;+E%Z=tFlA+)XI#w@oe2+nBG~ZAu`(13g z1BO~!s?&>uRuKCAIC<6ytT1ZxhyO`=**&m(>AkXV4fazx#Q2;+iTtz?26fwy!=An2 zaB1Z;tgF0n4KrwIC}CPd1yvchHC)6chIyVnPYlm5Xt<0T!`xZ#p2m*bw?mBvw8p?5 zYPf*I0iG!&&YjDUYBVtLZG!m$SMk$BLw-8;c65aWhLVia!03-d~&%Yk`b6s zZpoSq@**p>Y@R?8hQP@CT&jgTL6q^+z|^UtW24MNhiGQ3HVw=&D6P + * + * This is an abstract class. + * + * @see java_cup.production + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public abstract class production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. */ + public production_part(String lab) + { + _label = lab; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Optional label for referring to the part within an action (null for + * no label). + */ + protected String _label; + + /** Optional label for referring to the part within an action (null for + * no label). + */ + public String label() {return _label;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Indicate if this is an action (rather than a symbol). Here in the + * base class, we don't this know yet, so its an abstract method. + */ + public abstract boolean is_action(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(production_part other) + { + if (other == null) return false; + + /* compare the labels */ + if (label() != null) + return label().equals(other.label()); + else + return other.label() == null; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof production_part)) + return false; + else + return equals((production_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return label()==null ? 0 : label().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + if (label() != null) + return label() + ":"; + else + return " "; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/Robust/cup/java_cup/reduce_action.class b/Robust/cup/java_cup/reduce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p_!qM$h@i6(G;98V@)mm8{0^lB^*Dy>B_)7G(q{>M zSSBRxON5s^vPD&vY@xfo+A95}&4{w+11*5@Q)t^KxRBLb=n0X%Eo8ENbZw!(U6l=j KU!x)kT>lHxJofVd literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/shift_action.java b/Robust/cup/java_cup/shift_action.java new file mode 100644 index 00000000..33fc17a6 --- /dev/null +++ b/Robust/cup/java_cup/shift_action.java @@ -0,0 +1,82 @@ + +package java_cup; + +/** This class represents a shift action within the parse table. + * The action simply stores the state that it shifts to and responds + * to queries about its type. + * + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class shift_action extends parse_action { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + * @param shft_to the state that this action shifts to. + */ + public shift_action(lalr_state shft_to) throws internal_error + { + /* sanity check */ + if (shft_to == null) + throw new internal_error( + "Attempt to create a shift_action to a null state"); + + _shift_to = shft_to; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The state we shift to. */ + protected lalr_state _shift_to; + + /** The state we shift to. */ + public lalr_state shift_to() {return _shift_to;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Quick access to type of action. */ + public int kind() {return SHIFT;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality test. */ + public boolean equals(shift_action other) + { + return other != null && other.shift_to() == shift_to(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality test. */ + public boolean equals(Object other) + { + if (other instanceof shift_action) + return equals((shift_action)other); + else + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + /* use the hash code of the state we are shifting to */ + return shift_to().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() {return "SHIFT(to state " + shift_to().index() + ")";} + + /*-----------------------------------------------------------*/ + +} diff --git a/Robust/cup/java_cup/sym.class b/Robust/cup/java_cup/sym.class new file mode 100644 index 0000000000000000000000000000000000000000..97397bd85e853aab6ac28150fabea7f344c4ad5e GIT binary patch literal 1111 zcmYk)S#J_i6bJBg*~?NWUFoKEZL1dRzSQb4TwpBB;LKPb3E;%gP%sos{8&Dj_}~Zd zLmB^PNX&V;bAI=pbJzLv_t$SCI;OKUMX8Y_D@pGaMQz7cq%1`_b3D45c1P3m?r;`F zk(*MK!LYC0mSr1F?%Glm^L)eQIM1Isc}e(QkcQ;JjZ0OBdw`x zKF6zyl5N90GwNYgL{Z#ynvTt5OUV0V`3;UUiV{|YnFmR;vrc93u~7!9VUDB3?b#{tao=Ri@uIT!`@?6Mb3{BCcE zp0qcfP5MD?z(`$vzdX9=e(PqbLMFDyai>4~TE>8)0<%2qj=q$g-bK)#(jG;S#(lyajIy@4&ml z*Wl~Id+-h6oA52++wdLXyYRm70emQY556z_06r2f!w-dz;YY%c;U~gR;b+3n;TOU$ z;a9@1;S=FE@Tu@y_?@tUmsR{vpsn%`7Mdu2_>?XwW6j7`K;Ny1H~iyFhE)|Kx)v z!zDiWYT_Sd{N7s<2#_Y{oZf!V=X~$!-+#Y;1GtZl2@7{hFmbntdqr%?vLQp$WN>8F zl2yBa?E-cL@^0h}0)a~R*!$vj`d)O@*-M6Dbo5Zbaz}~he|D486G}`s9R;o*r%@sx zUJ4j)7##**Sv(4(FnKJn)mX$Vo;2SJ=uhKAGFQ4`6ue0Xy-BkZWeGwxWIk6L z%|#%+%^EGu_{=q$bXtt!B#`z6c);=biE}F)xltUsNiZC!ZwC}7akc?s_u_Qu2hT(4 z%o?2zdU1b8F3Ls)8#Y!@762Ep+dB^Y#D6Qz0QpGdE#2;lmXJ&wb#xyiqZ4}Hsf!1m`4wn6VTKf8{athQMdl@auFap88{+Gm2e^b)(1lm~z znkj0QJ;P3M*XGh)-`vr&u0FD@?QOf132j**Vi(+Mn50YKLXAW+T_{;u{gJ^{HMy;F z5)ECMFHsnObUf9V#XJ2jaeTNi!J zBS=4>QyHj0s3)lZj=)ANSV7HCMg5A0d_eKBSrh)KsC&IVdR)Wz0i~slOqA zLMV8ssJ|eWQForb!D;6cNLZ#WJ*7xmPcMFi;+buSQbClnpFj#8K;~;1^&ihs+*;G* zO^fSAzwn|b+5H&Z-_fv9K_g)`mC@{C#L8$nx@d^Cl9knG4RR^IB8so6l^KHXCtCo@ EKjXbBF8}}l literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/symbol_part.java b/Robust/cup/java_cup/symbol_part.java new file mode 100644 index 00000000..9142b5fc --- /dev/null +++ b/Robust/cup/java_cup/symbol_part.java @@ -0,0 +1,100 @@ +package java_cup; + +/** This class represents a part of a production which is a symbol (terminal + * or non terminal). This simply maintains a reference to the symbol in + * question. + * + * @see java_cup.production + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class symbol_part extends production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param sym the symbol that this part is made up of. + * @param lab an optional label string for the part. + */ + public symbol_part(symbol sym, String lab) throws internal_error + { + super(lab); + + if (sym == null) + throw new internal_error( + "Attempt to construct a symbol_part with a null symbol"); + _the_symbol = sym; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with no label. + * @param sym the symbol that this part is made up of. + */ + public symbol_part(symbol sym) throws internal_error + { + this(sym,null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The symbol that this part is made up of. */ + protected symbol _the_symbol; + + /** The symbol that this part is made up of. */ + public symbol the_symbol() {return _the_symbol;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Respond that we are not an action part. */ + public boolean is_action() { return false; } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(symbol_part other) + { + return other != null && super.equals(other) && + the_symbol().equals(other.the_symbol()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof symbol_part)) + return false; + else + return equals((symbol_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return super.hashCode() ^ + (the_symbol()==null ? 0 : the_symbol().hashCode()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + if (the_symbol() != null) + return super.toString() + the_symbol(); + else + return super.toString() + "$$MISSING-SYMBOL$$"; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/Robust/cup/java_cup/symbol_set.class b/Robust/cup/java_cup/symbol_set.class new file mode 100644 index 0000000000000000000000000000000000000000..f26071a1cd2d99d8926c85b0d4d61e61c3f3675f GIT binary patch literal 2612 zcmZ`)-*XdX6g``yO`0xkNogsi)F1`gBs7YsEonu-B84WEAA&_NZqub~O?E@FVfdjh zj^j9^ydAA|?bw4fIgL7D^N^I2gI3Nz`)p#TmC(SoTU)*>kmQ^Ik&70=;_ zFh~73CQgnE^Sp34A1wK! zn^gi7`mxw0({*ABoafXB*(}C zO`jKNjtW*u_9+Dj9y3aXjCw#5y0+KE92Omtu^odFIvaFL{7aRw729Nv-cA{3F)!mB zhGoR@h=lbb#%hqJn`%KJn)urv*qit1cg)5DY?Y)}fTF9KVWv4A}? zUcs1*9T@f_D1WaM#P#wZFhM#R}DcFQPM>sU23G7=(Y zTyU1IIK1t)+ZydFY1uiIU?xfuJh8Bhr?7|4uSw{zgmKLX2WoIqjA2tIYv@)F-Ksl- z#1^SpHK*$4>MlBMv4&q)as+6t4BTP$5?fyDglmo|2V0&r3hG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C*0eWM=Oj@B^Jc{;Y$!`o+-4(ll~TdTWo$KkSYdcfM*-}*d3-o$DIRU; zcpo1~#8n+8ZtJ)NIu%7+5HT*|BH|i4oz-;8C5a^O7Ai^XTROhLlnx7J&+o)=bl8~X z>Oa;|!K^@d&bKx0Y=dprF@c1RNhG*=N4=M~x3WcE5Pzv+YnZCts^#pa%GtF`>{-0s zau9naUW81kq-3!!)#mUnLT!X=@+g&?l(Tptnc(o+1-NgVWmpx|mNIR2?$0ZN8?8_d<3pfwd(-$m;l+G5>-J+#LL_t3F}&I3eKv0uvsJvg3--?E^Um|garz!62JSI+9$nbx QCHxxa@eK>y5n_@22WgqTQvd(} literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/terminal.java b/Robust/cup/java_cup/terminal.java new file mode 100644 index 00000000..e1a40aa3 --- /dev/null +++ b/Robust/cup/java_cup/terminal.java @@ -0,0 +1,169 @@ +package java_cup; + +import java_cup.assoc; +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a terminal symbol in the grammar. Each terminal + * has a textual name, an index, and a string which indicates the type of + * object it will be implemented with at runtime (i.e. the class of object + * that will be returned by the scanner and pushed on the parse stack to + * represent it). + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ +public class terminal extends symbol { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param nm the name of the terminal. + * @param tp the type of the terminal. + */ + public terminal(String nm, String tp, int precedence_side, int precedence_num) + { + /* superclass does most of the work */ + super(nm, tp); + + /* add to set of all terminals and check for duplicates */ + Object conflict = _all.put(nm,this); + if (conflict != null) + // can't throw an execption here because this is used in static + // initializers, so we do a crash instead + // was: + // throw new internal_error("Duplicate terminal (" + nm + ") created"); + (new internal_error("Duplicate terminal (" + nm + ") created")).crash(); + + /* assign a unique index */ + _index = next_index++; + + /* set the precedence */ + _precedence_num = precedence_num; + _precedence_side = precedence_side; + + /* add to by_index set */ + _all_by_index.put(new Integer(_index), this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for non-precedented terminal + */ + + public terminal(String nm, String tp) + { + this(nm, tp, assoc.no_prec, -1); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default type. + * @param nm the name of the terminal. + */ + public terminal(String nm) + { + this(nm, null); + } + + /*-----------------------------------------------------------*/ + /*------------------- Class Variables ---------------------*/ + /*-----------------------------------------------------------*/ + + private int _precedence_num; + private int _precedence_side; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Table of all terminals. Elements are stored using name strings as + * the key + */ + protected static Hashtable _all = new Hashtable(); + + /** Access to all terminals. */ + public static Enumeration all() {return _all.elements();} + + /** Lookup a terminal by name string. */ + public static terminal find(String with_name) + { + if (with_name == null) + return null; + else + return (terminal)_all.get(with_name); + } + + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of all terminals indexed by their index number. */ + protected static Hashtable _all_by_index = new Hashtable(); + + /** Lookup a terminal by index. */ + public static terminal find(int indx) + { + Integer the_indx = new Integer(indx); + + return (terminal)_all_by_index.get(the_indx); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of terminals. */ + public static int number() {return _all.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter to assign unique index. */ + protected static int next_index = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Special terminal for end of input. */ + public static final terminal EOF = new terminal("EOF"); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** special terminal used for error recovery */ + public static final terminal error = new terminal("error"); + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Report this symbol as not being a non-terminal. */ + public boolean is_non_term() + { + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + return super.toString() + "[" + index() + "]"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** get the precedence of a terminal */ + public int precedence_num() { + return _precedence_num; + } + public int precedence_side() { + return _precedence_side; + } + + /** set the precedence of a terminal */ + public void set_precedence(int p, int new_prec) { + _precedence_side = p; + _precedence_num = new_prec; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/Robust/cup/java_cup/terminal_set.class b/Robust/cup/java_cup/terminal_set.class new file mode 100644 index 0000000000000000000000000000000000000000..fd0453e1d1d309ea5638fb6c7df5465d1e9f9539 GIT binary patch literal 2459 zcmaJ>TWnNS6kWIT?DW#dz|aB(rl8VJ3nNd(wuptItu0gwXz?*lr>Et%GxrYDI|MZT z`C($B@smdV@TW00QBkJGMy)Z?#1D<18vm6TjWIF)scYYRJC6d+$3Az?*?X_G*WTxR z^Uo)r0oad11aTY>;h_iya3X>_oUBI-gAtlj^7r8o9tmS8f-r{Vsmz1k-o)NwcN(aD*P&Bers-PnWQ$t-(Tt_eZ zbXdsixP(52y|`9()vQpWTTs{$)0sa)A_tI*@L~+lfIV!mSOO8;7s_Z2`n=>_u z-Ia4Qol|T}j4uxOIBby?@yjpG=h_TSW`%YS{~hGM#&u(28CqfmbrT=Mw+#Oc1U}%l zhECc>_-Lba-9#I65_B=OB$F(fttuC4^Q{SCd8JfgQ9vQBQKMB$nWg z5D3$9EWMmb;z`b??ys?71>uQk{W2n-uP4;Ypgxl8uS!Ebv5yIbTAWFwws7J)8cNWY z`0W-HboNiuCULI^x|gefwj`V)SOeD$B{WvT~aFMN?LmSK*E{Dp=_jp_y+~kQ8 zS}JMWQm!)1^EKgz%X$oZ+;*+kqrZItjl$2>C)!@gx|#WamuX)?3tr`@yv8oPUW0H1 z_j%Rt_Xw_6eB=5?zrloWvf8(55*;pAI_6RBDN}XFZ`5JwDk+~mB{VM}HEdl$>%=nJI09RuTWLzzHnNC-zrX5$k?kcg$T@w< zr!D?_qv|-i!#nAIpK$KQ+=m8!|IADA3#Gcr%l#`Ku-~v9zvB@8z!Ch(`*#!P@D~jH k&3B`}{FLn`arrf@AVzLGKSV=iklfqXNtk1Fsl$W+0oH%eJOBUy literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/terminal_set.java b/Robust/cup/java_cup/terminal_set.java new file mode 100644 index 00000000..e921cb59 --- /dev/null +++ b/Robust/cup/java_cup/terminal_set.java @@ -0,0 +1,253 @@ + +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; + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/Robust/cup/java_cup/version.class b/Robust/cup/java_cup/version.class new file mode 100644 index 0000000000000000000000000000000000000000..336e0997176334ef550e9474e7d98897d114baae GIT binary patch literal 549 zcmYk2-)>St5XQfOQVs|D$6B>oX}5Z#rU824mBz%JNNPf?2`#r|fekJ_XO}E{NPH}> zn)IR%;6oW_ff8wW-86N+4WAF@uvuCf0$33tK=%Q?D1+aQA5vm^H$@c#pA@u%}?LWE=QGOvJ{QuAMA8sT-B%-xmWB{Ldg2TPUN%t1OKhRU z>)d84EI8WW3g=@~*ZCUr4tCeP$GpG6PnZuj_$l+@20!CU3Jc)#h#l(-21+09Kz}$u QTmWu{_zdD#d>3&1AKbBM>i_@% literal 0 HcmV?d00001 diff --git a/Robust/cup/java_cup/version.java b/Robust/cup/java_cup/version.java new file mode 100644 index 00000000..06600b59 --- /dev/null +++ b/Robust/cup/java_cup/version.java @@ -0,0 +1,55 @@ + +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.. (e.g. v0.10a). + * Major numbers will change at the time of major reworking of some + * part of the system. Minor numbers for each public release or + * change big enough to cause incompatibilities. Finally update + * letter will be incremented for small bug fixes and changes that + * probably wouldn't be noticed by a user. + * + * @version last updated: 12/22/97 [CSA] + * @author Frank Flannery + */ + +public class version { + /** The major version number. */ + public static final int major = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The minor version number. */ + public static final int minor = 10; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The update letter. */ + public static final char update = 'k'; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** String for the current version. */ + public static final String version_str = "v" + major + "." + minor + update; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Full title of the system */ + public static final String title_str = "CUP " + version_str; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the author */ + public static final String author_str = + "Scott E. Hudson, Frank Flannery, and C. Scott Ananian"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The command name normally used to invoke this program */ + public static final String program_name = "java_cup"; +} diff --git a/Robust/cup/winnt/README b/Robust/cup/winnt/README new file mode 100644 index 00000000..99a64716 --- /dev/null +++ b/Robust/cup/winnt/README @@ -0,0 +1,17 @@ +From toddk@MICROSOFT.com Tue Mar 24 22:07:19 1998 +Date: Fri, 30 Jan 1998 07:54:26 -0800 +From: Todd Knoblock +To: "'cananian@alumni.princeton.edu'" +Subject: Java cup under Windows NT. + +I wanted to try java cup under Windows NT. Rather than transliterating the +csh shell script, I put together a little makefile for it. I thought you +might want to include it in the distribution so that it is available for the +next person that wants to use java cup under Windows NT. + +Todd Knoblock + +To use, place this file in the root javacup directory (where the "java_cup" +directory lives), and type "nmake" from that directory. + +[The makefile has been included in this directory. -- CSA 24-Mar-1998 ] diff --git a/Robust/cup/winnt/makefile b/Robust/cup/winnt/makefile new file mode 100644 index 00000000..653f2075 --- /dev/null +++ b/Robust/cup/winnt/makefile @@ -0,0 +1,51 @@ +# +# Windows NT makefile for java_cup +# by Todd Knoblock, 28 January 1998. +# +# To run, type "nmake all" from the directory containing the make file. +# Tested under nmake version 1.62.7022 + +JVC=jvc +# -x means disable extensions +# -g means include debug information +# -w2 means warning level 2. +# Unfornately, anything above warning level 2 is noisy +JVCFLAGS= -x -g -w2 +JVIEW=jview + +.SUFFIXES: .java .class + +.java.class: + $(JVC) $(JVCFLAGS) $< + +all: runtime simple_calc java_cup test + +java_cup: java_cup\*.class + +runtime: java_cup\runtime\*.class + +simple_calc: java_cup\simple_calc\sym.java \ + java_cup\simple_calc\parser.java \ + java_cup\simple_calc\*.class + + +java_cup\simple_calc\sym.java: java_cup java_cup\simple_calc\parser.cup + $(JVIEW) java_cup.Main < java_cup\simple_calc\parser.cup + @del -f -q java_cup\simple_calc\sym.java >nul 2>nul + @del -f -q java_cup\simple_calc\parser.java >nul 2>nul + move sym.java java_cup\simple_calc\ + move parser.java java_cup\simple_calc\ + +java_cup\simple_calc\parser.java: java_cup\simple_calc\sym.java + +clean: + @del -f -q java_cup\simple_calc\sym.java >nul 2>nul + @del -f -q java_cup\simple_calc\parser.java >nul 2>nul + @for %d in (java_cup java_cup\runtime java_cup\simple_calc) do \ + @pushd %d \ + & del -f -q *.class >nul 2>nul \ + & popd + +test: simple_calc + @echo Executing the demo program. Answer should be 5050. + echo 101*100/2; | $(JVIEW) java_cup.simple_calc.Main diff --git a/Robust/src/Makefile b/Robust/src/Makefile new file mode 100644 index 00000000..112b04a5 --- /dev/null +++ b/Robust/src/Makefile @@ -0,0 +1,21 @@ +CLASSFILES=Main/Main.class Lex/BooleanLiteral.class \ +Lex/CharacterLiteral.class Lex/Comment.class \ +Lex/DocumentationComment.class Lex/EndOfLineComment.class \ +Lex/EOF.class Lex/EscapedUnicodeReader.class Lex/FIFO.class \ +Lex/FloatLiteral.class Lex/Identifier.class Lex/InputElement.class \ +Lex/IntegerLiteral.class Lex/Keyword.class Lex/Lexer.class \ +Lex/Literal.class Lex/LongLiteral.class Lex/NullLiteral.class \ +Lex/NumericLiteral.class Lex/Operator.class Lex/Separator.class \ +Lex/StringLiteral.class Lex/Token.class Lex/TraditionalComment.class \ +Lex/WhiteSpace.class Tree/ParseNode.class \ +Tree/ParseNodeDOTVisitor.class Tree/ParseNodeVector.class \ +Tree/Walkable.class + +all: Parse/Sym.class Parse/Parser.class $(CLASSFILES) + +Parse/Parser.java Parse/Sym.java: Parse/java14.cup + cd Parse && \ + java java_cup.Main -parser Parser -symbols Sym < java14.cup + +%.class: %.java + javac $< \ No newline at end of file -- 2.34.1