// Mihran Shahinian & Genci Xhaxhka COM 1205 // Checking that all Alternatives of Alternation class are correctly defined // Checking that all alternatives are defined as either construction // classes or alternation classes that will eventually be defined by construction classes ... ClassGraph { (@ void visit_cgraph() { AltCheckVisitor acv = new AltCheckVisitor(); this.through_alt(acv); } @) traversal through_alt(AltCheckVisitor acv) { bypassing { ConstructionClass, RepetitionClass } to ClassName ; } (@ NameContainer findAlternatives(){ RightSide_ClassVisitor rcv = new RightSide_ClassVisitor(new NameContainer()); this.all_alternatives( rcv ); return rcv.get_right_side(); } @) (@ NameContainer findDemClasses(){ LeftSide_ClassVisitor lcv = new LeftSide_ClassVisitor (new NameContainer()); this.allClassDefinitions( lcv ); return lcv.get_left_side(); } @) (@ void check_alternatives( NameContainer DemClasses, NameContainer Alternatives) { // Checking that a left side i.e Consruction classes contain // Alternatives of alternation class. First we make a new copy // of a vector which contains alternatives. Every time we match // alternative in the DemClasses vector we remove that element // from our copy. At the end temp vector contains alternatives // which are not defined as construction classes. Vector temp = (Vector)Alternatives.clone(); // Make a copy for (int i = Alternatives.size()-1 ; i >=0; i--) { for (int j = 0 ; j " + temp.elementAt(i)+"()... "); } } @) traversal all_alternatives( RightSide_ClassVisitor rcv ) { // P2 bypassing {ConstructionClass , RepetitionClass} to ClassName; } traversal allClassDefinitions( LeftSide_ClassVisitor lcv ) { // P2 bypassing {Subclass_Barlist, RepetitionClass} to ClassName; } } LeftSide_ClassVisitor { // P2 before -> ClassDef, *, ParamClassName (@ this.get_left_side(). addElement( dest.get_classname().get_name()); @) } RightSide_ClassVisitor { // P2 before Subclass (@ // Law of Demeter violated by principle of anarchy this.get_right_side().addElement( host.get_classspec().get_classname().get_name()); @) } ParamClassName { // Extended to visit Left Side of Alternation statement (@ ParamContainer goleft() { // Returns Vector containing left side parameters NameCollector pp = new NameCollector(new ParamContainer()); this.allParams(pp); return pp.get_cparams(); } @) traversal allParams(NameCollector pp) {to ClassName;} } Subclass { // Extended to visit Right Side of Alternation statement (@ ParamContainer goright() { NameCollector rs = new NameCollector(new ParamContainer()); this.actParams(rs); return rs.get_cparams(); } @) traversal actParams(NameCollector rs) {to ClassName;} } NameCollector { // visitor which adds the specified class names to vector before ClassName (@ this.get_cparams().addElement(host.get_name()); @) } AltCheckVisitor { // Main Visitor which goes through alternation class before ParamClassName (@ lside = host.goleft(); // might be 1 (just the classname) or more. @) before Subclass (@ rside = host.goright(); // get them // might be 1 (just the classname) or more. System.out.println ("Alternatives" +rside.toString()); if (lside.size() != rside.size()) { System.out.println ( " Error: Check the number of arguments => " +lside.firstElement().toString() +"()" + " : " + rside.firstElement().toString() + "()..."); } else { // we know they're the same size Boolean passarg = new Boolean(true); for (int j = 1; j < lside.size(); j++) { // start from second element. if (! lside.elementAt(j).toString().equals(rside.elementAt(j).toString())) passarg = Boolean.valueOf("False"); } if (passarg.booleanValue()) System.out.print(" "+ lside.firstElement().toString() + "() : " + rside.firstElement().toString() + "() passed ...\n"); else System.out.println(" Error: Icorrect Order of arguments => " + lside.firstElement().toString() +"()" + " : " + rside.firstElement().toString() + "() ..." ); } @) } Main { (@ static public void main(String args[]) throws Exception { System.out.println("\n\t J - S E M - C H E C K 2 \n"); ClassGraph a = ClassGraph.parse(System.in); System.out.println("\n Checking that every alternative of a \n " +"parameterized alternation class has \n " +"all its formal parameters in the same order ... \n"); a.visit_cgraph (); System.out.println("\n Checking that all alternatives are defined as \n " +"either construction classes or alternation classes that \n " +"will eventually be defined by construction classes ... \n" +"but can't defined as repetition classes \n"); a.check_alternatives(a.findDemClasses(),a.findAlternatives()); // P2 System.out.println("\n "); } @) }