//--------------------------------- // Printing Visitor for g_print. //--------------------------------- Program{ (@ public static void main(String args[]) throws Exception { Program p = parse(System.in); p.print_the_start(); p.print_the_rest(); System.out.println(" } "); } @) //----------------------------------------------------------------- // print_the_start: Prints the hardcode in the beh file. // This also involves traversing to ClassDef to retrieve // the first class definition in the cd file. // // print_the_rest: Prints the before and after statements required to // print the syntax and terminal classes for an object. // //------------------------------------------------------------------------- (@ public void print_the_start() { ParamClassName pcn = new ParamClassName(); BooleanVisitor bv1 = new BooleanVisitor(); PrintingVisitor v = new PrintingVisitor(pcn, bv1); this.Hc(v, bv1); } @) (@ public void print_the_rest() { BooleanVisitor bv = new BooleanVisitor(); ParamClassName pcn1 = new ParamClassName(); AltVisitor av = new AltVisitor(pcn1, bv); MNameTranspVisitor mntv = new MNameTranspVisitor(); this.toPartOrSyntax(mntv, bv, av); return; } @) traversal toPartOrSyntax(MNameTranspVisitor mntv, BooleanVisitor bv, AltVisitor av) {to {Part, PlainSyntax}; } traversal Hc(PrintingVisitor v, BooleanVisitor bv1) { to ClassDef; } } //--------------------------------------------------------------- // // V I S I T O R C O D E // // MNameTranspVisitor - Stores classname for printing in before and // after statements. // MNameRetVisitor - Retrieves stored classname when its time to // print the classname in the before and after // statements. // BooleanVisitor - Misnomer (General purpose flag) // AltVisitor - Does most of the printing work. // (Prints before and after statements) // PrintVisitor - Used to print the first classname in the // hardcode when necessary // ClassNameRetVisitor - Does same as MNameTranspVisitor for different // situation. // PrintingVisitor - Prints most of the hardcode // // //----------------------------------------------------------------------- MNameTranspVisitor { before ClassDef (@ this.set_pcn(host.get_paramclassname()); @) } MNameRetVisitor { before ClassName (@ this.set_cn(host); @) } //------------------------------------------------------------ // bool = 0 and 1 determine when to close the parentheses // on a before statement and when to start an after // statement. // bool = 2 => Alternation (ignore syntax after *common* //------------------------------------------------------------ BooleanVisitor{ before ClassGraph (@ bool = new Integer(1); @) before RepeatedPart_Sandwich (@ bool = new Integer(1); @) before ConstructionClass (@ bool = new Integer(1) ; @) after Part (@ if (bool.intValue() != 2) bool = new Integer(bool.intValue() - 1) ; @) after ClassDef (@ bool = new Integer(bool.intValue() - 1) ; @) before AlternationClass (@ bool = new Integer(2); @) } AltVisitor { traversal MtoClassName (MNameRetVisitor mnrv) { bypassing -> *,parameters,* to ClassName;} (@ public ClassName mdig_out() { MNameRetVisitor mnrv = new MNameRetVisitor(); this.MtoClassName(mnrv); return mnrv.get_cn(); } @) //------------------------------------------------------------ // printing - print the code for terminal/buffer classes. // //------------------------------------------------------------ (@ public void printing(Part pt) { Ident i1 = new Ident("Integer"); Ident i2 = new Ident("Ident"); Ident i3 = new Ident("String"); Ident i4 = new Ident("Text"); Ident ic = pt.get_classspec().get_classname().get_name(); if (i1.equals(ic)) { System.out.print(" \" + host.get_"); try { System.out.print(pt.get_partname().get_name());} catch (NullPointerException n) { System.out.print("integer");} System.out.print("().intValue() + \" "); } else if (i2.equals(ic)) { System.out.print(" \" + host.get_"); try { System.out.print(pt.get_partname().get_name()); } catch (NullPointerException n) { System.out.print("ident"); } System.out.print("() + \" "); } else if (i3.equals(ic)) { System.out.print(" \" + host.get_"); try { System.out.print(pt.get_partname().get_name()); } catch (NullPointerException n) { System.out.print("string"); } System.out.print("() + \" "); } else if (i4.equals(ic)) { System.out.print(" \" + " + "\"(\" + " + "\"@\" + " ); System.out.print(" host.get_"); try { System.out.print(pt.get_partname().get_name()); } catch (NullPointerException n) { System.out.print("text"); } System.out.print("() + " + "\"@\" + " + "\")\"" + " + \" "); } System.out.println(" \"); " + "@" + ")"); System.out.print( "after " + this.mdig_out().get_name() + " (@ System.out.print(\" " ); } @) before ClassDef (@ this.set_pcn1(host.get_paramclassname()); @) after PartOrSyntax_List (@ if (bv.get_bool().intValue() != 2 ) System.out.println(" \"); " + "@" + ")"); @) before PlainSyntax (@ if (bv.get_bool().intValue() != 2 ) System.out.print(host.get_string()); @) after PlainSyntax (@ if (bv.get_bool().intValue() != 2 ) System.out.print(" "); @) before ConstructionClass (@ System.out.print( "before " + this.mdig_out().get_name() + " (@ System.out.print(\" " ); @) after RepeatedPart_Sandwich (@ System.out.println(" \"); " + "@" + ")"); @) before RepeatedPart_Sandwich (@ System.out.print( "before " + this.mdig_out().get_name() + " (@ System.out.print(\" " ); @) before RepeatedPart (@ if (bv.get_bool().intValue() == 1) { System.out.println(" \"); " + "@" + ")"); System.out.print( "after " + this.mdig_out().get_name() + " (@ System.out.print(\" " ); } @) before Part (@ if (bv.get_bool().intValue() == 1) { this.printing(host); } @) } PrintVisitor { before ParamClassName (@ System.out.print(host.get_classname().get_name()); @) } ClassNameRetVisitor{ before ClassName (@ this.set_cn(host) ; @) } //------------------------------------------------------- // PrintingVisitor - prints the hardcode for the beh. // //------------------------------------------------------- PrintingVisitor { traversal toParamClassName(PrintVisitor pv1) { to ParamClassName;} (@ public void first_def() { PrintVisitor pv1 = new PrintVisitor(); this.toParamClassName(pv1); return; } @) before ClassDef (@ if (bv1.get_bool().intValue() == 1) { this.set_pcn(host.get_paramclassname()); this.first_def(); System.out.println(" {"); System.out.println(" (" + "@" + " void g_print() {"); System.out.println(" PrintingVisitor pv = new PrintingVisitor(); " ); System.out.println(" this.t(pv); "); System.out.println("}"); System.out.print("@"); System.out.println(")"); System.out.println("traversal t(PrintingVisitor pv) {to *;}"); System.out.println("}"); System.out.println("Main {"); System.out.print("("); System.out.println("@"); System.out.println(" static public void main(String args[])"); System.out.println("throws Exception {"); this.first_def(); System.out.print(" a = "); this.first_def(); System.out.println(".parse(System.in);"); System.out.println(" a.g_print(); "); System.out.println(" System.out.println(\" \"); "); System.out.println("}"); System.out.print(" @"); System.out.println(")"); System.out.println(" }"); System.out.println("PrintingVisitor{"); } @) }