Midterm COM 1205 Fall 2002 ========================================================== Open book and open notes, one hour exam Question 1: 10 points Question 2: 20 points Question 3: 30 points Question 4: 24 points Question 5: 20 points Question 6: 20 points Total: 124 points All questions (except 6) refer to the following class dictionary and program: import edu.neu.ccs.demeter.dj.*; Input = Component Attachment. Component = "component" ComponentName "class" "graph" MyClassGraph "provides" Provided "expects" PList(Normal) ["constraints" PList(Constraint)] "classes" PList(ClassName). Attachment = "attachment" CList(ComponentName) "on" ComponentName. ComponentName = Ident. ClassGraphName = Ident. ClassName = Ident. Provided = PList(FunctionMember). MyClassGraph = ClassGraphName. FunctionMember : Normal | Aspectual. Normal = "normal". Aspectual = "aspectual". Member = "member". Constraint = . PList(S) ~ "{" S {";" S} "}". CList(S) ~ "(" S {"," S} ")". Main = . program: ---------------------------------------------------------------------- Main { {{ static ClassGraph cg; public static void main(String args[]) throws Exception { cg = new ClassGraph(true, false); ClassGraph cgWT = new ClassGraph(Main.cg, "from Input bypassing -> *,tail,* to *"); cg = cgWT; Input c = Input.parse(System.in); c.display(); System.out.println(); System.out.println("original Input-object"); c.print(); System.out.println(); c.normals(); c.updateInput(); c.print(); System.out.println(); c.normals(); System.out.println(); TraversalGraph tg = new TraversalGraph( "from Input via Provided to Normal", cg); System.out.println(tg); System.out.println(" done "); } }} } Input { void display() to * (DisplayVisitor); void print() to * (PrintVisitor); } Normal { void print() to * (PrintVisitor); } Input { {{ void normals(){ UNKNOWN2 } void updateInput(){ UNKNOWN3 } }} } Question 1: =========== 10 points Consider the following input in program.input: "It works!" What output will the parser produce for this input? Put your answer into UNKNOWN1 Question 2: =========== 20 points Write a method called normals() which prints for a given Input-object o all Normal-objects that o contains. For example, for the Input-object: component T class graph G provides {aspectual;normal} expects {normal} classes {T1} attachment (Y) on B the output should be: normal normal (because there are two normal objects in the input) Put your answer in UNKNOWN2 Question 3: =========== 30 points Write a method called updateInput() which updates a given Input-object o by adding one Normal-object at the end of the list fms contained in every Provided-object of o. For example, if the Input-object is: component T class graph G provides {aspectual} expects {normal} classes {T1} attachment (Y) on B the modified Input-object should be: component T class graph G provides {aspectual;normal} expects {normal} classes {T1} attachment (Y) on B Put your answer in: UNKNOWN3 Question 4: =========== 24 points: 3 per UNKNOWN When we call the print() method on the following Input-object, what gets printed? : Input ( : Component ( : ComponentName ( : Ident "A" ) : MyClassGraph ( : ClassGraphName ( : Ident "G" ) ) : Provided ( : FunctionMember_PList { : Nonempty_FunctionMember_PList ( : Normal ( ) : Nonempty_FunctionMember_PList ( : Aspectual ( ) : Nonempty_FunctionMember_PList ( : Normal ( ) : Nonempty_FunctionMember_PList ( : Aspectual ( ) ) ) ) ) } ) : Normal_PList { : Nonempty_Normal_PList ( : Normal ( ) : Nonempty_Normal_PList ( : Normal ( ) ) ) } : Constraint_PList { : Nonempty_Constraint_PList ( : Constraint ( ) ) } : ClassName_PList { : Nonempty_ClassName_PList ( : ClassName ( : Ident "R" ) : Nonempty_ClassName_PList ( : ClassName ( : Ident "S" ) : Nonempty_ClassName_PList ( : ClassName ( : Ident "T" ) ) ) ) } ) : Attachment ( : ComponentName_CList { : Nonempty_ComponentName_CList ( : ComponentName ( : Ident "X" ) : Nonempty_ComponentName_CList ( : ComponentName ( : Ident "Y" ) : Nonempty_ComponentName_CList ( : ComponentName ( : Ident "Z" ) ) ) ) } : ComponentName ( : Ident "A" ) ) ) original Input-object component UNKNOWN4 class graph UNKNOWN5 provides UNKNOWN6 expects UNKNOWN7 constraints UNKNOWN8 classes UNKNOWN9 attachment UNKNOWN10 on UNKNOWN11 Question 5: =========== 20 points Consider the traversal specification: from Input through Provided to Normal For which classes would you have to write code if you would have to implement this traversal manually following the Law of Demeter? Give the list of classes: UNKNOWN12 Question 6: ======================= 20 points Consider the object tree a_in representing an object of class A in the Java program below. We want to traverse this object in depth-first order as shown in the implementation below. Consider the method t. It's code is spread across several classes. The program: class A { B b; C c; A(B b, C c){ this.b = b; this.c = c;} void t() { b.t(); c.t(); } } class B { D d; E e; B(D d, E e) {this.d = d; this.e = e;} void t() { d.t(); e.t(); } } class C { void t() {} } class D extends C { void t() { System.out.println(" in D-object "); } } class E extends C { void t() { System.out.println(" in E-object "); } } class Main { static public void main(String args[]) { A a_in = new A(new B(new D(), new E()), new D()); a_in.t(); } } Question: if you would implement the same traversal in DJ, which traversal specification would you use? UNKNOWN13