-------------------------------------------------------------------------- Adaptive Object-Oriented Software Development Fall 2000 COM 3360 NTU SE-737 --------------------------------------------------------------------------- Final Your name --------------------------------------------------------------------------- If a question is not clear, make a reasonable assumption, write down your assumption and answer the question with the assumption. Question 1: ============================================== Predicting the behavior of an adaptive program. 20 points Consider the following class dictionary, behavior file, input and output: import edu.neu.ccs.demeter.dj.*; Main = . Cd_graph = GlobalImports < adjacencies > Nlist(Adjacency) EOF. GlobalImports = [ SList(Import) *l ] . Import = "import" PackageName [ ImportAllClasses ] ";". ImportAllClasses = ".*". PackageName ~ Ident {"." Ident}. Adjacency = < source > Vertex ["(" < parameters> Comma_list(Vertex) ")"] < ns > Neighbors "." . Neighbors : Neighbors_wc | Repetit_n *common*. Neighbors_wc : Construct_ns | Alternat_ns *common* < construct_ns > List(Any_vertex). Construct_ns = "=". Alternat_ns = ":" < alternat_ns > Bar_list(Term) [ Common]. Common = "*common*". Repetit_n = "~" Sandwich(Kernel). Kernel = [ Term ] "{" Sandwich(Term) "}". Any_vertex : Opt_labeled_term | Syntax_vertex . Vertex = < vertex_name > Ident. Syntax_vertex : Regular_syntax | Print_command *common*. Print_command : Print_indent | Print_unindent | Print_skip | Print_space *common*. Print_indent = "+" . Print_unindent = "-" . Print_skip = "*l" . Print_space = "*s" . Regular_syntax = < string > String . Opt_labeled_term : Labeled | Regular *common* Term. Regular = . Labeled = "<" < label_name > Ident ">" . Term : Normal *common* Vertex ["@" Module_name] ["(" Comma_list(Term) ")" ] . Module_name = Ident. Normal = . // parameterized classes List(S) ~ {S}. SList(S) ~ S { *l S } . Nlist(S) ~ S {*l S}. Bar_list(S) ~ S {"|" S}. Comma_list(S) ~ S {"," S}. Sandwich(S) = List(Syntax_vertex) S List(Syntax_vertex) . ListEditingVisitor = extends Visitor. ListEmptyingVisitor = extends Visitor. //------------------BEH FILE------------- Main { {{ static ClassGraph cg; static public void main(String args[]) throws Exception { Cd_graph cd = Cd_graph.parse(System.in); ClassGraph cg = new ClassGraph(true, false); cd.removeSyntax(cg); cd.print(); } }} } Cd_graph { void print() to * (PrintVisitor); } Any_vertex { void print() to * (PrintVisitor); } // The program eliminates all Syntax_vertex-objects from // a class dictionary Cd_graph{ {{ void removeSyntax(ClassGraph cg){ String beforeListsToBeEmptied = "from Cd_graph to {Kernel_Sandwich, Term_Sandwich}"; cg.traverse(this, beforeListsToBeEmptied, new ListEmptyingVisitor()); String whatToKeepInList = "from Cd_graph bypassing Syntax_vertex to Any_vertex"; cg.traverse(this, whatToKeepInList, new ListEditingVisitor()); } }} } ListEmptyingVisitor{ {{ public void before(Kernel_Sandwich target) { target.set_first(new Syntax_vertex_List()); //set both lists empty target.set_second(new Syntax_vertex_List()); } public void before(Term_Sandwich target) { target.set_first(new Syntax_vertex_List()); //set both lists empty target.set_second(new Syntax_vertex_List()); } }} } ListEditingVisitor { {{ private Any_vertex_List list; public void before(Neighbors_wc a) { list=new Any_vertex_List(); } public void before(Any_vertex a) { list.addElement(a); System.out.println("non syntax element added"); a.print(); System.out.println(); } public void after(Neighbors_wc a) { a.set_construct_ns(list); } }} } input ------------------------- R ~ "l" + S { + "l" S + "l" + } "p". A = "{" "'" "g" + S "{" "P" +. S = A + "b" + B "c" + C. B = . C = "&" ":" A + "]" . X = Y. U : U1 | U2 *common* "g" H "j" + J +. output -------------------------- non syntax element added S non syntax element added A non syntax element added B non syntax element added C non syntax element added A non syntax element added Y non syntax element added H non syntax element added J R~S{S}. A=S. S=A B C. B=. C=A. X=Y. U:U1|U2*common*H J. Now we change the input to: (notice that the only change is that *common* was changed to common) R ~ "l" + S { + "l" S + "l" + } "p". A = "{" "'" "g" + S "{" "P" +. S = A + "b" + B "c" + C. B = . C = "&" ":" A + "]" . X = Y. U : U1 | U2 common "g" H "j" + J +. Describe how the output will change. Question 2: ============================================== Program modification after class dictionary change 60 points We reuse the program from question 1 and we evolve it (going to the next growth phase). We add Optional_term = "[" Sandwich(Opt_labeled_term) "]". and we add Optional_term as an alternative to Any_vertex: Any_vertex : Opt_labeled_term | Optional_term | Syntax_vertex . For the following input: R ~ "l" { "l" S "l" } "p". A = "{" [ "'" "g" S "{" ] "P". S = A "b" B "c" C. B = . C = "&" [":" A "]" ]. X = [Y]. U : U1 | U2 common "g" H "j" J. we get the following output: non syntax element added ["'" "g" S "{"] non syntax element added S non syntax element added A non syntax element added B non syntax element added C non syntax element added [":" A "]"] non syntax element added A non syntax element added [Y] non syntax element added Y non syntax element added H non syntax element added J R~{S}. A=["'" "g" S "{"]S. S=A B C. B=. C=[":" A "]"]A. X=[Y]Y. U:U1|U2*common*H J. Modify the program so that all Syntax_vertex-objects will be eliminated. Describe where you insert or modify code. Surprisingly, the program does not behave as expected. Notice the output line (with syntax eliminated): A=["'" "g" S "{"]S. although the input was: A=["'" "g" S "{"]. The S at the end of the output is wrong. This is an example where a change to the class dictionary (we added Optional_term) makes the adaptive program behave incorrectly. Explain why we get this wrong output and correct the program so that it will behave correctly. Describe where you will modify the program. Question 3: ============================================= Class dictionary design. Find a "small" class dictionary to test an adaptive program. 80 points This is a question about class dictionary design related to question 1. Consider the class dictionary and behavior file of question 1. Design a new class dictionary that is LL(1), not left recursive and inductive that can be used to test the adaptive program in the behavior file. Try to make the class dictionary as small as possible but it is important that the adaptive program still works correctly in eliminating Syntax_vertex objects from Cd_graph objects. Design an interesting input to your class dictionary and give the output that the adaptive program will produce. Question 4: ============================================= Simplified definition of traversals. 40 points Given a class graph G, an object graph O compatible with G, and a strategy S compatible with G with source s and target t, give a definition of the object graph slice for O (a subgraph of O) defined by S and G. You may assume that the strategy is a "positive" strategy without "bypassing", i.e., it is a subgraph of the transitive closure of G. You should use the definition that is most intuitive to you. We have used several equivalent definitions in this class. Question 5: ========================================== Parsing 20 points Consider the class dictionary of question 1. Find a smallest class dictionary (count the number of characters) that is a legal input and whose corresponding object contains a Syntax_vertex_List object and a Common-object and a Print_space-object. Question 6: =========================================== Programming 40 points Consider the class dictionary of question 1. Write a Java program (you may use DJ and/or DemeterJ) that counts the number of construction edges in a given class dictionary. HAPPY HOLIDAYS