FINAL COM 1205 Winter 2002 Karl Lieberherr ======================================================================== Overview: 1: 20 points: class dictionary design and programming 2: 18 points: class dictionary, input and strategy 3: 50 points: parsing and program understanding 4: 36 points: class dictionary design 5: 40 points: program design and programming == 164 points Question 1: ======================================================= 10 points per UNKNOWN: 20 points CDefs = CDef ["." CDefs]. CDef = CN Ps. Ps = P ["," Ps]. P = CN. CN = Ident. Main = String. Consider the above class dictionary A. Rewrite the class dictionary A without using optional parts and call the new class dictionary B. No optional parts, syntactically introduced with [ ], are allowed in B. Class dictionary B must define the same language as class dictionary A. Put class dictionary B into UNKNOWN1. Write a method that counts and prints for a given CDefs-object the total number of CN-objects the CDefs-object contains. Your program must work without change for both class dictionaries A and B. Fill in the UNKNOWN2 below: void countCN(ClassGraph cg) { UNKNOWN2 } Question 2: ========================================================== 6 points per UNKNOWN: 18 points Write a small class dictionary and an input sentence legal for the class dictionary and a strategy strat so that the method traversalKnowledge when called with ClassGraph cg = ...; X x = X.parse(...); x.traversalKnowledge(cg, strat); will call each visitor method at least once. X{ {{ void traversalKnowledge(ClassGraph cg, String strategy) { cg.traverse(this, strategy, new Visitor(){ public void start() { System.out.println(" ---------- New Traversal ---------------"); } void before(Y host) { System.out.println("NEW PointCut starts ======== "); } void before(Z host) { System.out.println("currently at object " + host); } }); } }} } Your class dictionary: UNKNOWN1 Your sentence: UNKNOWN2 Your strategy: UNKNOWN3 Question 3: ======================================================== 2 points per UNKNOWN: 50 points Consider the following class dictionary AspectJFragment in file program.cd, behavior file, input and output: Find the UNKNOWNs in the output. program.cd ============================================= import edu.neu.ccs.demeter.dj.*; import java.util.*; AspectJFragment = List(PointCut) EOF. PointCut = "pointcut" PCName PCList(ArgDecl) ":" PCExp ";". PCExp : Simple | Compound. Simple : This | Target | Call | Args | PCRef. Compound : AndOrExp | NotExp | CFlow. CFlow = "cflow" "(" PCExp ")". NotExp = "!" PCExp. Op : AndOp | OrOp. OpPCExp = Op PCExp. AndOrExp = "(" PCExp List(OpPCExp) ")". AndOp = "&&". OrOp = "||". PCRef = "*" PCName PCList(Variable). This = "this" PVariable. Target = "target" PVariable. PVariable = "(" Variable ")". Call = "call" "(" Type FName "(..)" ")". Args = "args" PCList(Variable). ArgDecl = Type Variable. Variable = Ident. PCName = Ident. FName = Ident. Type = Ident. PCList(S) ~ "(" S { "," S } ")". List(S) ~ {S}. Main = String. CommandVisitor = extends Visitor. program.beh ============================================= Main { {{ static ClassGraph cg; static String FIdent = " edu.neu.ccs.demeter.Ident "; public static void main(String args[]) throws Exception { AspectJFragment fr = AspectJFragment.parse(System.in); ClassGraph cgTemp = new ClassGraph(true, false); cg = new ClassGraph(cgTemp, "from AspectJFragment bypassing -> *,tail,* to *"); System.out.println(); fr.traversalKnowledge(cg,"from AspectJFragment " + "through NotExp to This"); fr.traversalKnowledge(cg,"from AspectJFragment " + "bypassing CFlow to This"); } }} } AspectJFragment{ {{ void traversalKnowledge(ClassGraph cg, String strategy) { cg.traverse(this, strategy, new Visitor(){ public void start() { System.out.println(" ---------- New Traversal ---------------"); } void before(PointCut host) { System.out.println("NEW PointCut starts ======== "); } void before(Object host) { // this method will be executed before every object that is reached // during the traversal System.out.println("currently at object " + host); } }); } }} } program.input ===================================== pointcut X1(S s1) : this(s1); pointcut X2(S s2, T t2) : (call(void crossing_x(..)) && this(s2) && target(t2) ); pointcut X3(A a1, B b2, C c3) : cflow( * visiting_A1(a1)); pointcut Y4(Source s): ! cflow(this(s)); output: ===================================== DemeterJ version 0.8.4 Copyright (c) 2002 Northeastern University Reading project file program.prj... Running the test... ---------- New Traversal --------------- currently at object AspectJFragment@110040 currently at object UNKNOWN1@88c0 currently at object Nonempty_PointCut_List@122221 currently at object UNKNOWN2@7ec107 NEW PointCut starts ======== currently at object Nonempty_PointCut_List@32e13d currently at object UNKNOWN3@617189 NEW PointCut starts ======== currently at object UNKNOWN4@64f6cd currently at object OpPCExp_List@72380 currently at object Nonempty_OpPCExp_List@2bb514 currently at object UNKNOWN5@7d5d2a currently at object Nonempty_OpPCExp_List@6fa474 currently at object UNKNOWN6@15c083 currently at object UNKNOWN7@11d8c1 currently at object UNKNOWN8@2d9c06 NEW PointCut starts ======== currently at object UNKNOWN9@5e5a50 currently at object Nonempty_PointCut_List@7b6889 currently at object UNKNOWN10@c2ff5 NEW PointCut starts ======== currently at object UNKNOWN11@20be79 currently at object UNKNOWN12@39240e currently at object UNKNOWN13@6e4648 ---------- New Traversal --------------- currently at object UNKNOWN14@110040 currently at object UNKNOWN15@88c0 currently at object Nonempty_PointCut_List@122221 currently at object UNKNOWN16@7ec107 NEW PointCut starts ======== currently at object UNKNOWN17@482923 currently at object Nonempty_PointCut_List@32e13d currently at object UNKNOWN18@617189 NEW PointCut starts ======== currently at object UNKNOWN19@64f6cd currently at object OpPCExp_List@72380 currently at object Nonempty_OpPCExp_List@2bb514 currently at object UNKNOWN20@7d5d2a currently at object UNKNOWN21@4ec44 currently at object Nonempty_OpPCExp_List@6fa474 currently at object UNKNOWN22@15c083 currently at object Nonempty_PointCut_List@11d8c1 currently at object UNKNOWN23@2d9c06 NEW PointCut starts ======== currently at object Nonempty_PointCut_List@7b6889 currently at object UNKNOWN24@c2ff5 NEW PointCut starts ======== currently at object UNKNOWN25@20be79 Question 4: ======================================================== 6 points per UNKNOWN: 36 points Consider the class dictionary AspectJFragment from a previous question and extend it so that it also accepts the input given below. Call the extended class dictionary: AspectJFragment-ext. Find the UNKNOWNs. import edu.neu.ccs.demeter.dj.*; import java.util.*; AspectJFragment = List(PointCut) UNKNOWN1(Advice) EOF. Advice = UNKNOWN2. UNKNOWN3 : UNKNOWN4. Before = UNKNOWN5. After = UNKNOWN6. PointCut = "pointcut" PCName PCList(ArgDecl) ":" PCExp ";". PCExp : Simple | Compound. Simple : This | Target | Call | Args | PCRef. Compound : AndOrExp | NotExp | CFlow. CFlow = "cflow" "(" PCExp ")". NotExp = "!" PCExp. Op : AndOp | OrOp. OpPCExp = Op PCExp. AndOrExp = "(" PCExp List(OpPCExp) ")". AndOp = "&&". OrOp = "||". PCRef = "*" PCName PCList(Variable). This = "this" PVariable. Target = "target" PVariable. PVariable = "(" Variable ")". Call = "call" "(" Type FName "(..)" ")". Args = "args" PCList(Variable). ArgDecl = Type Variable. Variable = Ident. PCName = Ident. FName = Ident. Type = Ident. PCList(S) ~ "(" S { "," S } ")". List(S) ~ {S}. Main = String. CommandVisitor = extends Visitor. program.input: what the extended class dictionary needs to accept ================================== pointcut X1(S s1) : this(s1); pointcut X2(S s2, T t2) : (call(void crossing_x(..)) && this(s2) && target(t2) ); pointcut X3(A a1, B b2, C c3) : cflow( * visiting_A1(a1)); pointcut Y4(Source s): ! cflow(this(s)); before(S s1) : this(s1) { }; after(S s2, T t2) : (call(void crossing_x(..)) && this(s2) && target(t2) ) { } ; Question 5: =============================================================== 40 points Write a method that works with the class dictionary AspectJFragment-ext you developed in an earlier question. The method needs to analyze an Advice-object and print out all Variable-objects on the left-hand-side (before the colon) followed by all Variable-objects on the right-hand-side (after the colon). Example: For the input: after(S s2, T t2, R r2) : (call(void crossing_x(..)) && this(s2) && target(t2) && ! cflow(this(s)) ) { } ; the method needs to produce the output: left-hand-side: s2 t2 r2 right-hand-side: s2 t2 s Fill in the UNKNOWN1 below: void analyzeAdvice(ClassGraph cg) { UNKNOWN1 }