Question 1: =========== Consider the following program and the input and output. Find the UNKNOWNs in program output (you must understand the program to do this). Find the UNKNOWNs in program (for ClassName printing). You basically write a program. Print list of classes involved in the traversal in alphabetical order. (Basically the set of classes that your project would highlight.) Find UNKNOWNs in the program to change the Exps-object. You basically write a program. Find UNKNOWNs in the displayed object (1 point per UNKNOWN, 10 UNKNOWNs). (This is easy). The final task is to improve the class dictionary. Eliminate the duplication. 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() { // cg.traverse(es,"from Exps to-stop Exp", 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 +++++++++++++ "); } ;}); cg.traverse(es,"from Exps via Sequential to ClassName", new Visitor() { public void start() { System.out.println("start with ClassName printing");}; public void before(ClassName host){ host.print(); System.out.println(); } public void finish() { System.out.println("done with ClassName printing");}; }); TraversalGraph tg = new TraversalGraph("from Exps via Sequential to ClassName", cg); System.out.println("TraversalGraph"); System.out.println(); System.out.println(tg); cg.traverse(es,"from Exps to {Forward, Backward}", new Visitor() { public void before(Forward host){ if (host.steps == null) host.set_steps(new Unlimited()); } public void before(Backward host){ if (host.steps == null) host.set_steps(new Unlimited()); } }); 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 ===================== ClassName A ClassName B ->A 3 B new Exp ===================== ClassName A ->B 2 C new Exp ===================== ClassName B exists( X ) join( ->A X, <-X B ) new Exp ===================== join( ->A X, <-X B ) new Exp ===================== ClassName A ClassName X ClassName B ->A X new Exp ===================== ClassName A <-X B new Exp ===================== ClassName X ClassName B ->X<-A*B new Exp ===================== ClassName A ClassName B =>X<=A B new Exp ===================== ClassName B seq A( B, C ) new Exp ===================== exists( R1 ) join( =>X<=A edge e R1, =>X<=R1 B ) new Exp ===================== join( =>X<=A edge e R1, =>X<=R1 B ) new Exp ===================== ClassName R1 ClassName B =>X<=A edge e R1 new Exp ===================== ClassName R1 =>X<=R1 B new Exp ===================== ClassName B start of Equation-object +++++++++++++ ->A B new Exp ===================== ClassName A =>X<=A B new Exp ===================== ClassName B start of Equation-object +++++++++++++ seq A( Q, C ) 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 Start set: [Exps: {0}] Copy 0: Nodes: Exps Exp_CommaList Nonempty_Exp_CommaList Exp Simple QuantifierCompound Exists Compound Equation_CommaList Nonempty_Equation_CommaList Equation Edges: -> Exps,exps,Exp_CommaList -> Exp_CommaList,first,Nonempty_Exp_CommaList -> Nonempty_Exp_CommaList,it,Exp => Exp,Simple => Exp,QuantifierCompound => QuantifierCompound,Exists -> Exists,exp,Exp => Exp,Compound -> Compound,args,Exp_CommaList -> Nonempty_Exp_CommaList,next,Nonempty_Exp_CommaList -> Exps,eqs,Equation_CommaList -> Equation_CommaList,first,Nonempty_Equation_CommaList -> Nonempty_Equation_CommaList,it,Equation -> Equation,left,Exp -> Equation,right,Exp -> Nonempty_Equation_CommaList,next,Nonempty_Equation_CommaList Edges to other copies: 1: => Simple,Sequential Copy 1: Nodes: Exp Simple ClassName Sequential ClassName_CommaList Nonempty_ClassName_CommaList Edges: -> Sequential,source,ClassName -> Sequential,classname_commalist,ClassName_CommaList -> ClassName_CommaList,first,Nonempty_ClassName_CommaList -> Nonempty_ClassName_CommaList,it,ClassName -> Nonempty_ClassName_CommaList,next,Nonempty_ClassName_CommaList Edges to other copies: Finish set: [ClassName: {1}] 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 ( : Exp_CommaList { : Nonempty_Exp_CommaList ( : Compound ( : Join ( ) : Exp_CommaList { : Nonempty_Exp_CommaList ( : Forward ( : ClassName ( : Ident "A" ) : Limited ( : Integer "3" ) : ClassName ( : Ident "B" ) ) : Nonempty_Exp_CommaList ( : Forward ( : ClassName ( : Ident "B" ) : Limited ( : Integer "2" ) : ClassName ( : Ident "C" ) ) ) ) } ) : Nonempty_Exp_CommaList ( : Exists ( : ClassName_CommaList { : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "X" ) ) } : Compound ( : Join ( ) : Exp_CommaList { : Nonempty_Exp_CommaList ( : Forward ( : ClassName ( : Ident "A" ) : Unlimited ( ) : ClassName ( : Ident "X" ) ) : Nonempty_Exp_CommaList ( : Backward ( : ClassName ( : Ident "X" ) : Unlimited ( ) : ClassName ( : Ident "B" ) ) ) ) } ) ) : Nonempty_Exp_CommaList ( : Later ( : ClassName ( : Ident "A" ) : Unlimited ( ) : ClassName ( : Ident "B" ) ) : Nonempty_Exp_CommaList ( : UpOverDown ( : ClassName ( : Ident "A" ) : ClassName ( : Ident "B" ) ) : Nonempty_Exp_CommaList ( : Sequential ( : ClassName ( : Ident "A" ) : ClassName_CommaList { : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "B" ) : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "C" ) ) ) } ) : Nonempty_Exp_CommaList ( : Exists ( : ClassName_CommaList { : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "R1" ) ) } : Compound ( : Join ( ) : Exp_CommaList { : Nonempty_Exp_CommaList ( : UpOverDown ( : ClassName ( : Ident "A" ) : EdgeName ( : Ident "e" ) : ClassName ( : Ident "R1" ) ) : Nonempty_Exp_CommaList ( : UpOverDown ( : ClassName ( : Ident "R1" ) : ClassName ( : Ident "B" ) ) ) ) } ) ) ) ) ) ) ) ) } : Equation_CommaList { : Nonempty_Equation_CommaList ( : Equation ( : Forward ( : ClassName ( : Ident "A" ) : Unlimited ( ) : ClassName ( : Ident "B" ) ) : UpOverDown ( : ClassName ( : Ident "A" ) : ClassName ( : Ident "B" ) ) ) : Nonempty_Equation_CommaList ( : Equation ( : Sequential ( : ClassName ( : Ident "A" ) : ClassName_CommaList { : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "Q" ) : Nonempty_ClassName_CommaList ( : ClassName ( : Ident "C" ) ) ) } ) : Compound ( : Join ( ) : Exp_CommaList { : Nonempty_Exp_CommaList ( : Forward ( : ClassName ( : Ident "A" ) : Unlimited ( ) : ClassName ( : Ident "Q" ) ) : Nonempty_Exp_CommaList ( : Later ( : ClassName ( : Ident "Q" ) : ClassName ( : Ident "C" ) ) ) ) } ) ) ) ) } ) done