/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** 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"; } /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").left;\n" + "\t\tint " + labelname + "right = ((java_cup.runtime.Symbol)" + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").right;\n"; else ret = ""; ")((" + "java_cup.runtime.Symbol) " + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").value;\n";
if (!emit.locations()) ret = "\t\tint " + labelname + "left = ((java_cup.runtime.Symbol)" + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").left;\n" + "\t\tint " + labelname + "right = ((java_cup.runtime.Symbol)" + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").right;\n"; else ret = "\t\tLocation " + labelname + "xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)" + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").xleft;\n" + "\t\tLocation " + labelname + "xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)" + emit.pre("stack") + ((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+ ").xright;\n";} else ret = "";
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(" }");
"/** 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(" 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(" }");
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(" }");
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(" }");
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(" }");
out.println(" protected " + pre("actions") + " action_obj;"); out.println(); 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(" }");
out.println("class " + pre("actions") + typeArgument() + " {"); out.println(" " + pre("actions") + "("+parser_class_name+typeArgument()+" parser) {"); out.println(" this.parser = parser;"); out.println(" }"); out.println(" /** Method "+instancecounter+" with the actual generated action code for actions "+(instancecounter*UPPERLIMIT)+" to "+((instancecounter+1)*UPPERLIMIT) +". */"); out.println(" public final java_cup.runtime.Symbol " + pre("do_action_part")+ String.format("%08d",new Integer(instancecounter)) +"("); out.println(" int " + pre("act_num,")); out.println(" java_cup.runtime.lr_parser " + pre("parser,")); out.println(" {"); out.println(" /* Symbol object for return from actions */"); out.println(" java_cup.runtime.Symbol " + pre("result") + ";"); out.println(); out.println(" /* select the action based on the action number */"); out.println(" switch (" + pre("act_num") + ")"); out.println(" {"); "((java_cup.runtime.Symbol) " + emit.pre("stack") + ((index==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + index + ")"))+ ").value;"); break; rightstring = "((java_cup.runtime.Symbol)" + emit.pre("stack") + else {
"/** Cup generated class to encapsulate user supplied action code.*/" ); out.println("class " + pre("actions") + " {"); out.println(" " + pre("actions") + "("+parser_class_name+" 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(" {"); s.name()); out.println(" " + "if ( " + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + "-" + index + ")).value != null )"); out.println(" " + "RESULT = " +
"/** Cup generated class to encapsulate user supplied action code.*/" ); out.println("class " + pre("actions") + " {"); out.println(" " + pre("actions") + "("+parser_class_name+" 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(" {"); s.name()); out.println(" " + "if ( " + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + "-" + index + ")).value != null )"); out.println(" " + "RESULT = " +
"/** Cup generated class to encapsulate user supplied action code.*/" ); out.println("class " + pre("actions") + " {"); out.println(" " + pre("actions") + "("+parser_class_name+" 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(" {"); s.name()); out.println(" " + "if ( " + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + "-" + index + ")).value != null )"); out.println(" " + "RESULT = " +
"/** Cup generated class to encapsulate user supplied action code.*/" ); out.println("class " + pre("actions") + " {"); out.println(" " + pre("actions") + "("+parser_class_name+" 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(" {"); s.name()); out.println(" " + "if ( " + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + "-" + index + ")).value != null )"); out.println(" " + "RESULT = " +
out.println("class " + pre("actions") + typeArgument() + " {"); 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) + ")"))+ ").value";