MIDTERM COM 1205 Winter 2003 Tuesday, February 11 Karl Lieberherr Open book and open notes. Question 1: 71 Question 2: 20 Question 3. 40 131 points Question 1: =========== 28 UNKNOWNs: 24 - 28: 5 points each: 25 1 - 23: 2 points each: 46 -- 71 Consider the following program.cd, program.beh and program.input file and the output. Find the UNKNOWNS. program.cd: =============================================================== import edu.neu.ccs.demeter.dj.*; Main = String. Aspect = "aspect" TraversalAspectName SList(Decl). Decl = "declare" Item. Item : NamedStrat | Trav. NamedStrat = "strategy" ":" StrategyName ":" Strat. Trav = "traversal" ":" MethodSignature ":" StrategyName "(" ClassName ")". MethodSignature = "void" MethodName "(" FormalArgument ")". FormalArgument = ClassName VariableName. TraversalAspectName = Ident. StrategyName = Ident. ClassName = Ident. MethodName = Ident. Strat = String. VariableName = Ident. SList(S) ~ "{" S {";" S } "}". program.beh: =============================================================== Main { {{ static ClassGraph cg; public static void main(String args[]) throws Exception { Aspect m = Aspect.parse(System.in); System.out.println("input ===================== "); m.display(); System.out.println(); System.out.println(" processing starts "); cg = new ClassGraph(true, false); cg.traverse(m, "from Aspect to ClassName", new Visitor() { void before (ClassName host) { System.out.println(host.get_ident().toString()); } }); System.out.println("done: from Aspect to ClassName"); cg.traverse(m, "from Aspect via MethodSignature to ClassName", new Visitor() { void before (ClassName host) { System.out.println(host.get_ident().toString()); } }); System.out.println("done: from Aspect via MethodSignature to ClassName"); } }} } program.input: =============================================================== aspect Traversals { declare strategy: eachCommand: "from Commands to Command"; declare traversal: void interpret(CompoundFile cd): eachCommand(Interpreter) } OUTPUT: ============================================================== input ===================== : Aspect ( : UNKNOWN1 ( : UNKNOWN2 "UNKNOWN3" ) : Decl_SList { : Nonempty_Decl_SList ( : UNKNOWN4 ( : UNKNOWN6 ( : UNKNOWN8 ( : Ident "UNKNOWN9" ) : Strat ( : String UNKNOWN10 ) ) ) : Nonempty_Decl_SList ( : Decl ( : Trav ( : MethodSignature ( : MethodName ( : Ident "UNKNOWN11" ) : FormalArgument ( : ClassName ( : Ident "UNKNOWN12" ) : VariableName ( : Ident "UNKNOWN13" ) ) ) : UNKNOWN15 ( : UNKNOWN17 "UNKNOWN18" ) : UNKNOWN20 ( : UNKNOWN22 "UNKNOWN23" ) ) ) ) ) } ) processing starts UNKNOWN24 UNKNOWN25 UNKNOWN26 UNKNOWN27 UNKNOWN28 Question 2: ========================================================================= 20 points The following lines from the above *.beh file contain significant duplication. Rewrite the program so that the duplication is minimized and the behavior stays the same. cg.traverse(m, "from Aspect to ClassName", new Visitor() { void before (ClassName host) { System.out.println(host.get_ident().toString()); } }); cg.traverse(m, "from Aspect via MethodSignature to ClassName", new Visitor() { void before (ClassName host) { System.out.println(host.get_ident().toString()); } }); Put your result into UNKNOWN1. Question 3: ========================================================================== 40 points Is the following a legal sentence with respect to the above class dictionary in question 1? Explain. aspect Traversals { declare strategy: eachCommand: "from Commands to Command"; declare traversal: void listAll(): eachFile(FileLister); declare traversal: void listAll(X x, Y y): eachFile(FileLister); } If it is illegal describe how you would change the class dictionary. Only give the modified and new classes. Put your result into UNKNOWN1.