/** 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); }
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
out.println("//----------------------------------------------------"); out.println(); emit_package(out); emit_production_table(out); do_action_table(out, action_table, compact_reduces); do_reduce_table(out, reduce_table); out.println(" protected " + pre("actions") + " action_obj;"); out.println(); out.println(" protected void init_actions()"); out.println(" {"); out.println(" action_obj = new " + pre("actions") + "();"); out.println(" }"); out.println(); out.println(" {"); out.println(" /* call code in generated class */"); out.println(" return action_obj." + pre("do_action(") + "act_num, parser, stack, top);"); out.println(" }"); emit_action_code(out, start_prod);
emit_production_table(out); do_action_table(out, action_table, compact_reduces); do_reduce_table(out, reduce_table); emit_action_code(out, start_prod); else emit_xmlaction_code(out, start_prod);
out.println(" protected static final short[][] _reduce_table = "); out.print (" unpackFromStrings("); do_table_as_string(out, reduce_goto_table); out.println(");");
out.println("class " + pre("actions") + typeArgument() + " {"); out.println(" private final "+parser_class_name + typeArgument() + " parser;"); out.println(" " + pre("actions") + "("+parser_class_name+typeArgument()+" parser) {"); out.println(" this.parser = parser;"); 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(" {"); out.println(" java_cup.runtime.Symbol " + pre("result") + ";"); out.println(); out.println(" switch (" + pre("act_num") + ")"); out.println(" {"); if (lastResult!=-1) { result = "(" + prod.lhs().the_symbol().stack_type() + ") " + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ((lastResult==1)?".peek()":(".elementAt(" + emit.pre("top") + "-" + (lastResult-1) + ")"))+
out.println("//----------------------------------------------------"); out.println(); emit_package(out);
if (emit.lr_values()) { int loffset; String leftstring, rightstring;
out.println("//----------------------------------------------------"); out.println(); emit_package(out); emit_production_table(out); do_action_table(out, action_table, compact_reduces); do_reduce_table(out, reduce_table); out.println(" protected " + pre("actions") + " action_obj;"); out.println(); out.println(" protected void init_actions()"); out.println(" {"); out.println(" action_obj = new " + pre("actions") + "(this);"); out.println(" }"); out.println(); out.println(" {"); out.println(" /* call code in generated class */"); out.println(" return action_obj." + pre("do_action(") + "act_num, parser, stack, top);"); out.println(" }"); emit_action_code(out, start_prod);
out.println(" protected static final short[][] _reduce_table = "); out.print (" unpackFromStrings("); do_table_as_string(out, reduce_goto_table); out.println(");");
out.println("//----------------------------------------------------"); out.println(); emit_package(out);
"/** Cup generated class to encapsulate user supplied action code.*/" ); out.println("class " + pre("actions") + " {"); out.println(" " + pre("actions") + "() { }"); 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(" {"); out.println(" java_cup.runtime.symbol " + pre("result") + ";"); out.println(); out.println(" switch (" + pre("act_num") + ")"); out.println(" {"); out.println(" " + pre("result") + " = new " + prod.lhs().the_symbol().stack_type() + "(/*" + prod.lhs().the_symbol().name() + "*/" + out.println(" " + pre("parser") + ".done_parsing();"); out.println(" return " + pre("result") + ";");
out.println("//----------------------------------------------------"); out.println(); emit_package(out); emit_production_table(out); do_action_table(out, action_table, compact_reduces); do_reduce_table(out, reduce_table); out.println(" protected " + pre("actions") + " action_obj;"); out.println(); out.println(" protected void init_actions()"); out.println(" {"); out.println(" action_obj = new " + pre("actions") + "(this);"); out.println(" }"); out.println(); out.println(" {"); out.println(" /* call code in generated class */"); out.println(" return action_obj." + pre("do_action(") + "act_num, parser, stack, top);"); out.println(" }"); emit_action_code(out, start_prod);
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** 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); }
out.println(" protected static final short[][] _reduce_table = "); out.print (" unpackFromStrings("); do_table_as_string(out, reduce_goto_table); out.println(");");
out.println("//----------------------------------------------------"); out.println(); emit_package(out);
out.println("//----------------------------------------------------"); out.println(); emit_package(out); out.println(" */"); out.println("public class " + parser_class_name + typeArgument() + " extends java_cup.runtime.lr_parser {"); emit_production_table(out); do_action_table(out, action_table, compact_reduces); do_reduce_table(out, reduce_table); out.println(" protected " + pre("actions") + " action_obj;"); out.println(); out.println(" action_obj = new " + pre("actions") + typeArgument() +"(this);"); out.println(" }"); out.println(); out.println(" {"); out.println(" /* call code in generated class */"); out.println(" return action_obj." + pre("do_action(") + "act_num, parser, stack, top);"); out.println(" }"); emit_action_code(out, start_prod);
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/