Final COM 1205 Fall 2002 ==================================================== Open book and open notes, 1.45 hour exam Question 1: Parsing and Printing 69 UNKNOWNs: 87 points Question 2: Class Dictionary Design 11 UNKNOWNs: 6 points each: 66 points Question 3: Executing a Small Program 27 UNKNOWNs: 5 points each 135 points ============== 288 points total Question 1: Parsing and Printing ======================================================== 69 UNKNOWNs: UNKNOWN 1 - 67: 1 points each UNKNOWN68: 10 points UNKNOWN69: 10 points --------------- 87 points total Consider the following class dictionary program.cd, behavior file program.beh and program.input. Find the UNKNOWNs. This is an easy question about parsing and printing. // class dictionary cd1 DAJ = List(TraversalAspect). TraversalAspect = "aspect" AspectName CurlyList(Definition). Definition = "declare" DefinitionBody ";". DefinitionBody : CG | Strategy | AdaptiveMethod. CG = "ClassGraph" ClassGraphName. Strategy = "Strategy" StrategyName "=" StrategyExpression. StrategyExpression = StrategyName. AdaptiveMethod = "Method" MethodSignature MethodBody. MethodSignature = List(MethodKeyword) JavaType MethodName "(" [ Commalist(MethodParm) ] ")" Throws. MethodKeyword : PublicMethod | ProtectedMethod | PrivateMethod | StaticMethod | FinalMethod . PublicMethod = "public". ProtectedMethod = "protected". PrivateMethod = "private". StaticMethod = "static". FinalMethod = "final". MethodParm = JavaType ParmName List(ArraySpec). Throws = [ *s "throws" Commalist(ClassName) ]. MethodBody = StrategyExpression VisitorRef. VisitorRef = "(" Commalist(ClassName) ")" . JavaType = Name List(ArraySpec). ArraySpec = "[" "]". Name ~ Ident { "." Ident }. ClassGraphName = Ident. StrategyName = Ident. MethodName = Ident. ClassName = Name. ParmName = Ident. AspectName = Name. List(S) ~ {*s S}. NList(S) ~ S {*s S}. CurlyList(S) ~ "{" S {*s S} "}". Commalist(S) ~ S {"," *s S}. Main = String. //======================================================== // program.beh Main { public static void main(String args[]) throws Exception {{ DAJ m = DAJ.parse(System.in); m.display(); System.out.println("done"); }} } DAJ { void display() bypassing -> *,parent,* to * (DisplayVisitor); } //======================================================== // program.input aspect A { declare ClassGraph cg; declare Strategy s1 = s2; declare Method public final static R f(A a) s1(V1,V2); } UNKNOWN69 //======================================================== // output : DAJ ( : TraversalAspect_List { : Nonempty_TraversalAspect_List ( : UNKNOWN1 ( : UNKNOWN3 ( : UNKNOWN5 { : Nonempty_Name ( : Ident "UNKNOWN6" ) } ) : Definition_CurlyList { : Nonempty_Definition_CurlyList ( : UNKNOWN7 ( : UNKNOWN8 ( : UNKNOWN9 ( : UNKNOWN11 "UNKNOWN12" ) ) ) : Nonempty_Definition_CurlyList ( : UNKNOWN13 ( : UNKNOWN15 ( : UNKNOWN17 ( : Ident "UNKNOWN18" ) : UNKNOWN20 ( : UNKNOWN22 ( : UNKNOWN24 "UNKNOWN25" ) ) ) ) : Nonempty_Definition_CurlyList ( : UNKNOWN26 ( : UNKNOWN27 ( : UNKNOWN28 ( : MethodKeyword_List { : Nonempty_MethodKeyword_List ( : UNKNOWN29 ( ) : Nonempty_MethodKeyword_List ( : UNKNOWN30 ( ) : Nonempty_MethodKeyword_List ( : UNKNOWN31 ( ) ) ) ) } : UNKNOWN32 ( : UNKNOWN33 { : Nonempty_Name ( : Ident "UNKNOWN34" ) } : UNKNOWN35 { } ) : UNKNOWN37 ( : UNKNOWN39 "UNKNOWN40" ) : MethodParm_Commalist { : Nonempty_MethodParm_Commalist ( : UNKNOWN41 ( : UNKNOWN43 ( : UNKNOWN44 { : Nonempty_Name ( : UNKNOWN45 "UNKNOWN46" ) } : ArraySpec_List { } ) : UNKNOWN47 ( : Ident "UNKNOWN48" ) : UNKNOWN49 { } ) ) } : UNKNOWN50 ( ) ) : UNKNOWN52 ( : UNKNOWN54 ( : UNKNOWN56 ( : Ident "UNKNOWN57" ) ) : UNKNOWN58 ( : ClassName_Commalist { : Nonempty_ClassName_Commalist ( : UNKNOWN60 ( : UNKNOWN61 { : Nonempty_Name ( : UNKNOWN62 "UNKNOWN63" ) } ) : Nonempty_ClassName_Commalist ( : UNKNOWN64 ( : UNKNOWN66 { : Nonempty_Name ( : Ident "UNKNOWN67" ) } ) ) ) } ) ) ) ) ) ) ) } ) : Nonempty_TraversalAspect_List ( : TraversalAspect ( : AspectName ( : Name { : Nonempty_Name ( : Ident "B" ) } ) : Definition_CurlyList { : Nonempty_Definition_CurlyList ( : Definition ( : CG ( : ClassGraphName ( : Ident "cg" ) ) ) ) } ) ) ) } )done // ================================================ Additonal question about this class dictionary and behavior file: What is the output for the following input in program.input: aspect B { } Explain your answer in UNKNOWN68. Question 2: Class Dictionary Design ==================================================== 11 UNKNOWNs: 6 points each: 66 points Consider the class dictionary cd1 from question 1. Extend the class dictionary so that the class dictionary accepts the following input in program.input. aspect A { declare ClassGraph cg; declare Strategy s1 = "from * bypassing -> *,tail,* to *"; declare Method public final static R f(A a) (&& s1 "from A to B") (V1,V2); declare Method public final static R f(A a) (|| (&& s1 "from A to B") "from A via X to C") (V1,V2); } aspect B { declare ClassGraph cg; declare Strategy s1 = "from * bypassing -> *,tail,* to *"; declare Strategy s2 = "from * bypassing -> *,tail,* to *"; declare Strategy s3 = ( && s1 s2); declare Strategy s4 = ( || s3 s2); declare Strategy s4 = ( ! s3 ); } Replace the following line from class dictionary 1: StrategyExpression = StrategyName. by the following lines: StrategyExpression : Simple | UNKNOWN1. UNKNOWN2 : StrategyName | UNKNOWN3. UNKNOWN4 = "UNKNOWN5" UNKNOWN6 List(UNKNOWN7) "UNKNOWN8". Op : And | Or | Not. And = "UNKNOWN9". Or = "||". UNKNOWN10 = "!". UNKNOWN11 = String. Find the UNKNOWNs. Note that for some UNKNOWNs multiple answers are correct. Question 3: Executing a Small Program ====================================================== 27 UNKNOWNs: 5 points each 135 points We reuse the class dictionary cd1 from question 1 in the program.beh file below. We enhance the class dictionary with the class definition: ArraySpecChoiceVisitor = extends Visitor. The input in program.input is: aspect A { declare ClassGraph cg; declare Strategy s1 = s2; declare Method public final static R f(A[][] a[][]) s1(V1,V2); } Find the UNKNOWNs in the output. Note that ArraySpec@551f60 is an object identifier: the identifier at the beginning gives the name of the class. //////////////////////////////////// //program.beh Main { {{ static ClassGraph cg2; public static void main(String args[]) throws Exception { DAJ m = DAJ.parse(System.in); ClassGraph cg1 = new ClassGraph(true,false); cg2 = new ClassGraph(cg1, "from * bypassing ->*,tail,* to *"); m.chooseArraySpec(); System.out.println("done"); } }} } JavaType { void print() to * (PrintVisitor); } DAJ { {{ void chooseArraySpec(){ ArraySpecChoiceVisitor v = new ArraySpecChoiceVisitor(); Main.cg2.traverse(this, "from DAJ via JavaType to ArraySpec", v); System.out.println(); System.out.println("================================"); Main.cg2.traverse(this, "from DAJ bypassing JavaType to ArraySpec", v); System.out.println("================================"); Main.cg2.traverse(this, "from DAJ to ArraySpec", v); } }} } ArraySpecChoiceVisitor { {{ public void start(){ System.out.println("Traversal Started "); } public void before(DAJ host){ System.out.println(host); } public void before(MethodParm host){ System.out.println(host); } public void before(JavaType host){ host.print(); System.out.println(); System.out.println(host); } public void before(ArraySpec host){ System.out.println(host); } }} } //////////////////////////////////// //output Reading project file program.prj... Running the test... UNKNOWN1 UNKNOWN2@763f5d UNKNOWN3 UNKNOWN4@6768e UNKNOWN5@519bc8 UNKNOWN6 UNKNOWN7@4a8cd1 UNKNOWN8@630ab9 UNKNOWN9@551f60 ================================ UNKNOWN10 UNKNOWN11@763f5d UNKNOWN12@519bc8 UNKNOWN13@7ee8b8 UNKNOWN14@60b6f5 ================================ UNKNOWN15 UNKNOWN16@763f5d UNKNOWN17 UNKNOWN18@6768e UNKNOWN19@519bc8 UNKNOWN20 UNKNOWN21@4a8cd1 UNKNOWN22@630ab9 UNKNOWN23@551f60 UNKNOWN24@7ee8b8 UNKNOWN25@60b6f5 UNKNOWN26 // end of output // additional question Is it ok to switch in class Main the two lines: cg2 = new ClassGraph(cg1, "from * bypassing ->*,tail,* to *"); m.chooseArraySpec(); ? Justify your answer with one sentence in UNKNOWN27.