Question 1: =========== 60 + 20 + 15 + 20 + 21 + 10 = 146 Consider the following program (program.cd and program.beh file) and the input and output. Find all UNKNOWNs: Find the UNKNOWNs in program output (you must understand the program to do this). UNKNOWN 6 - 25: 3 points each: 60 Find the UNKNOWNs in program (for ClassName printing). You basically write a program. UNKNOWN 1 - 2: 10 points each: 20 Print list of classes involved in the traversal in alphabetical order. (Basically the set of classes that your project would highlight.) UNKNOWN 3: 15 points Find UNKNOWNs in the program to change the Exps-object. You basically write a program. UNKNOWN 4 - 5: 10 points each: 20 Find UNKNOWNs in the displayed object (1 point per UNKNOWN). (This is easy: parsing skill). UNKNOWN 26 - 46: 1 point per UNKNOWN: 21 points The final task is to improve the class dictionary. Eliminate the duplication in classes Forward , Backward , Later , UpOverDown. Put your answer into UNKNOWN 47: 10 points. Here is the class dictionary Exps: ====================================================== import edu.neu.ccs.demeter.dj.*; import java.util.*; Exps = CommaList(Exp) [*l "equations" CommaList(Equation)]. Exp : Simple | Compound | QuantifierCompound. Simple : Forward | Backward | Sequential | Later | UpOverDown . Forward = "->" ClassName ["edge" EdgeName] [ Steps] ClassName. Backward = "<-" ClassName ["edge" EdgeName] [ Steps] ClassName. Sequential = "seq" ClassName CommaList(ClassName). Later = "->X<-" ClassName ["edge" EdgeName] [ Steps] ClassName. UpOverDown = "=>X<=" ClassName ["edge" EdgeName] [ Steps] ClassName. Exists = "exists" CommaList(ClassName) *l Exp. Steps: Unlimited | Limited. // if steps is absent, the default meaning is unlimited Unlimited = "*". Limited = Integer. Compound = Op CommaList(Exp). Op : Join | Union. Join = "join". Union = "union". QuantifierCompound : Exists. Equation = *l Exp "=" *l Exp. ClassName = Ident. EdgeName = Ident. CommaList(S) ~ "(" *l + S {"," *l S *s} - *l ")" . Main = String. Program input: ======================================== (join (-> A 3 B, -> B 2 C) , exists (X) join (-> A X, <- X B) // B before A one hill , ->X<- A * B // B before A, several hills , =>X<= A B // up, over and down: class graph: // special kind of meta graph , seq A (B, C) , // reachability formula "from A to B", B concrete exists (R1) join ( =>X<= A edge e R1, =>X<= R1 B) ) equations ( -> A B = =>X<= A B // if B is concrete , seq A (Q, C) = join( -> A Q, ->X<- Q C) ) Program: ======================================== Main { {{ static ClassGraph cg; public static void main(String args[]) throws Exception { Exps es = Exps.parse(System.in); ClassGraph g = new ClassGraph(true,false); cg = new ClassGraph(true, false); cg = new ClassGraph(cg, "from Exps bypassing -> *,tail,* to *"); cg.traverse(es,"from Exps to Simple", new Visitor() { public void start() {System.out.println("Testing the evaluator");}; public void before(Exp host){ host.print(); System.out.println(" new Exp ===================== "); List l = host.eval(); for(Iterator i = l.iterator(); i.hasNext();) { System.out.print(" ClassName "); ((ClassName)i.next()).print(); System.out.println(); }; } public void before(Equation host){ System.out.println(" start of Equation-object +++++++++++++ "); } ;}); /////////////////////////////////////////////////// // print all ClassName-objects that are contained in // Sequential-objects that are contained in Exps-object // See the output for an example. /////////////////////////////////////////////////// cg.traverse(es,UNKNOWN1, UNKNOWN2 ); TraversalGraph tg = new TraversalGraph("from Exps via Sequential to ClassName", cg); System.out.println("TraversalGraph"); System.out.println(); // Put into UNKNOWN3 a sorted list of all classes // touched by the traversal System.out.println(tg); // The purpose of the following traversal is // to modify the "steps" data member of // Forward- and Backward-objects using the rule: // if steps is null then set steps to an Unlimited-object. // See the output for an example cg.traverse(es, "UNKNOWN4", UNKNOWN5 ); System.out.println(" modified Exps-object "); es.print(); System.out.println(); System.out.println(" displayed object "); es.display(); System.out.println(" done "); } }} } ClassName { void print() to * (PrintVisitor); } Exp { void print() to * (PrintVisitor); } Exps { void print() to * (PrintVisitor); void display() to * (DisplayVisitor); } Exp { {{ abstract List eval(); }} } Simple { {{ abstract List eval(); }} } Forward { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); return t; }; }} } Backward { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); t.add(target); return t; }; }} } Sequential { {{ List eval(){ return new ArrayList();}; }} } Later { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); t.add(target); return t; }; }} } UpOverDown { {{ List eval(){ ArrayList t = new ArrayList(); t.add(target); return t; }; }} } Exists { {{ List eval(){ return new ArrayList();}; }} } Op { {{ abstract List apply(List t); }} } Union { {{ List apply(List args){ List r = new ArrayList(); for(Iterator i = args.iterator(); i.hasNext();) r.addAll((List)i.next()); return r; } }} } Join { {{ List apply(List args){ List r = new ArrayList(); for(Iterator i = args.iterator(); i.hasNext();) r.addAll((List)i.next()); return r; } }} } Compound { {{ List eval(){ List t = new ArrayList(); for(Enumeration e = args.elements();e.hasMoreElements();) t.add(((Exp)e.nextElement()).eval()); return op.apply(t); } }} } Program output: ======================================== Reading project file program.prj... Running the test... Testing the evaluator join( ->A 3 B, ->B 2 C ) new Exp ===================== UNKNOWN6 UNKNOWN7 ->A 3 B new Exp ===================== UNKNOWN8 ->B 2 C new Exp ===================== UNKNOWN9 exists( X ) join( ->A X, <-X B ) new Exp ===================== join( ->A X, <-X B ) new Exp ===================== UNKNOWN10 UNKNOWN11 UNKNOWN12 ->A X new Exp ===================== UNKNOWN13 <-X B new Exp ===================== UNKNOWN14 UNKNOWN15 ->X<-A*B new Exp ===================== UNKNOWN16 UNKNOWN17 =>X<=A B new Exp ===================== ClassName B seq A( B, C ) new Exp ===================== UNKNOWN18 ) new Exp ===================== join( =>X<=A edge e R1, =>X<=R1 B ) new Exp ===================== UNKNOWN19 UNKNOWN20 =>X<=A edge e R1 new Exp ===================== UNKNOWN21 =>X<=R1 B new Exp ===================== UNKNOWN22 start of Equation-object +++++++++++++ ->A B new Exp ===================== UNKNOWN23 =>X<=A B new Exp ===================== UNKNOWN24 start of Equation-object +++++++++++++ UNKNOWN25 ) new Exp ===================== join( ->A Q, ->X<-Q C ) new Exp ===================== ClassName A ClassName Q ClassName C ->A Q new Exp ===================== ClassName A ->X<-Q C new Exp ===================== ClassName Q ClassName C start with ClassName printing A B C A Q C done with ClassName printing TraversalGraph UNKNOWN3 (not the entire TraversalGraph, only the classes sorted alphabetically) modified Exps-object ( join( ->A 3 B, ->B 2 C ), exists( X ) join( ->A*X, <-X*B ), ->X<-A*B, =>X<=A B, seq A( B, C ), exists( R1 ) join( =>X<=A edge e R1, =>X<=R1 B ) ) equations( ->A*B= =>X<=A B, seq A( Q, C )= join( ->A*Q, ->X<-Q C ) ) displayed object : Exps ( : UNKNOWN26 { : Nonempty_Exp_CommaList ( : UNKNOWN27 ( : UNKNOWN28 ( ) : UNKNOWN29 { : Nonempty_Exp_CommaList ( : UNKNOWN30 ( : UNKNOWN31 ( : Ident "UNKNOWN32" ) : UNKNOWN33 ( : Integer "UNKNOWN34" ) : UNKNOWN35 ( : Ident "UNKNOWN36" ) ) : Nonempty_Exp_CommaList ( : Forward ( : UNKNOWN37 ( : Ident "UNKNOWN38" ) : Limited ( : Integer "UNKNOWN39" ) : ClassName ( : Ident "UNKNOWN40" ) ) ) ) } ) : Nonempty_Exp_CommaList ( : UNKNOWN41 ( : ClassName_CommaList { : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "UNKNOWN42" ) ) } : Compound ( : UNKNOWN43 ( ) : Exp_CommaList { : Nonempty_Exp_CommaList ( : UNKNOWN44 ( : ClassName ( : Ident "UNKNOWN45" ) : Unlimited ( ) : ClassName ( : Ident "UNKNOWN46" ) ) etc.