Midterm Exam COM 3360 November 8, 2001 Prof. Karl Lieberherr ======================================== Open books and open notes Question 1: =========== Consider the following class dictionary, behavior file, and output. Find the UNKNOWNS. unknowns 1 - 8: 5 points each : 40 points other unknowns: 2 point each : 64 points ////////////////// class dictionary import edu.neu.ccs.demeter.dj.*; import java.util.*; import java.io.*; public UNKNOWN1 = List(Collaboration) *EOF*. public Collaboration = "collaboration" CollabName [IsACollab] ";" Structure AdapterDef. public IsACollab = "extends" CollabName. public Structure = Imports List(ParticipantDef) *l . public IsA = "extends" ParticipantName. public Impls = "implements" CommaList(ParticipantName). public HasA = JavaType VarName ";". public Imports = List(Import). public Import = "import" LongImportName ";" *l. public LongImportName = LongName. public ParticipantDef = ParticipantOrInterface ParticipantName [IsA] [Impls] *l. public ParticipantOrInterface : IsParticipant | IsInterface. public IsParticipant = "participant". public IsInterface = "interface". public AdapterDef = List(AdapterItem). public AdapterItem = "attach" [ CommaList(CollabRef)] AttachmentSpecList. public CollabRef : ResharedCollab | SharedCollab | NormalCollab common CollabName. public ResharedCollab = "reshared" . public SharedCollab = "shared" . public NormalCollab = "normal". public AttachmentSpecList = "{" List(Attachment) "}". public Attachment = "{" ShortName ":" + *l List(CompositeParticipantDef) - *l "}". public CompositeParticipantDef = PartSpec "+=" [ CommaList(PartSpec)] With *l. public With = "with" BracedList(Entry). Entry : UNKNOWN2. Around = "UNKNOWN3" ShortName ":" NameSpec "UNKNOWN4" NameSpec . public Export = "export" NameSpec ["as" NameSpec] . List(S) ~ { S}. CommaList(S) ~ S {"," *s S}. BracedList(P) ~ "{" + *l { P } - *l "}". public PartSpec = LongName. public ShortName = Ident. public LongName ~ ShortName { "." ShortName}. public VarName = ShortName. public JavaType = LongName List(ArraySpec). public ArraySpec = "[" "]". public NameSpec = ShortName. public CollabName = LongName. public ParticipantName = ShortName. Main = . ///////////////////// behavior file Main { {{ public static void main(String[] args) throws Exception { AC ac = AC.parse(System.in); ac.print(); System.out.println(); System.out.println("done 1"); ac.display(); System.out.println(); System.out.println("done 2"); ac.display_all(); System.out.println(); System.out.println("done 3"); // DJ ClassGraph cg = new ClassGraph(true, false); ClassGraph cgCommandsWithoutTail = new ClassGraph(cg, "from AC bypassing -> *,tail,* to *"); ac.process(new TraversalGraph("from AC to UNKNOWN5", cg)); System.out.println("done"); } }} } ParticipantName { UNKNOWN6 } AC { void display_all() bypassing -> *,tail,* to * (DisplayVisitor); } AC { void display() bypassing -> *,tail,* to UNKNOWN7 (DisplayVisitor); } AC { void print() to * (PrintVisitor); } AC { {{ void process(TraversalGraph where) { Visitor cV = new Visitor() { void before(ParticipantDef host){ System.out.println("participant name "); host.get_name().print(); System.out.println(); }; public void start() {System.out.println("UNKNOWN8");} }; where.traverse(this, cV); } }} } ///////////// output (I removed the indentation from the ///////////// DisplayVisitor output collaboration counts;participant Counted extends X collaboration gettersNsetters;participant Foo implements Y collaboration result;participant Food attach normal gettersNsetters{{gns: Food+=Foo, X, edu.neu.ccs.demeter.S with{ around gns:get_str do counted export main as y } }}attach shared counts{{q: Food+=Counted, R, S.T with{ export gns as counted export gnsset_i as reset } }} done 1 : AC ( : Collaboration_List { : Nonempty_Collaboration_List ( : Collaboration ( : AdapterDef ( : AdapterItem_List { } ) ) : Nonempty_Collaboration_List ( : Collaboration ( : AdapterDef ( : AdapterItem_List { } ) ) : Nonempty_Collaboration_List ( : Collaboration ( : AdapterDef ( : AdapterItem_List { : Nonempty_AdapterItem_List ( : AdapterItem ( : AttachmentSpecList ( : Attachment_List { : Nonempty_Attachment_List ( : Attachment ( ) ) } ) ) : Nonempty_AdapterItem_List ( : AdapterItem ( : AttachmentSpecList ( : Attachment_List { : Nonempty_Attachment_List ( : Attachment ( ) ) } ) ) ) ) } ) ) ) ) ) } ) done 2 : AC ( : Collaboration_List { : Nonempty_Collaboration_List ( : UNKNOWN9 ( : UNKNOWN10 ( : UNKNOWN11 { : Nonempty_LongName ( : UNKNOWN12 ( : Ident "UNKNOWN13" ) ) } ) : Structure ( : UNKNOWN14 ( : UNKNOWN15 { } ) : UNKNOWN16 { : Nonempty_ParticipantDef_List ( : UNKNOWN17 ( : UNKNOWN18 ( ) : UNKNOWN19 ( : UNKNOWN20 ( : Ident "Counted" ) ) : IsA ( : ParticipantName ( : ShortName ( : Ident "X" ) ) ) ) ) } ) : AdapterDef ( : AdapterItem_List { } ) ) : Nonempty_Collaboration_List ( : Collaboration ( : CollabName ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "gettersNsetters" ) ) } ) : Structure ( : Imports ( : Import_List { } ) : ParticipantDef_List { : Nonempty_ParticipantDef_List ( : ParticipantDef ( : IsParticipant ( ) : ParticipantName ( : ShortName ( : Ident "Foo" ) ) : Impls ( : ParticipantName_CommaList { : Nonempty_ParticipantName_CommaList ( : ParticipantName ( : ShortName ( : Ident "Y" ) ) ) } ) ) ) } ) : UNKNOWN22 ( : AdapterItem_List { } ) ) : Nonempty_Collaboration_List ( : UNKNOWN23 ( : UNKNOWN25 ( : UNKNOWN27 { : Nonempty_LongName ( : UNKNOWN28 ( : Ident "UNKNOWN29" ) ) } ) : Structure ( : Imports ( : Import_List { } ) : ParticipantDef_List { : Nonempty_ParticipantDef_List ( : ParticipantDef ( : IsParticipant ( ) : ParticipantName ( : ShortName ( : Ident "Food" ) ) ) ) } ) : AdapterDef ( : AdapterItem_List { : Nonempty_AdapterItem_List ( : AdapterItem ( : CollabRef_CommaList { : Nonempty_CollabRef_CommaList ( : NormalCollab ( : CollabName ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "gettersNsetters" ) ) } ) ) ) } : AttachmentSpecList ( : Attachment_List { : Nonempty_Attachment_List ( : Attachment ( : ShortName ( : Ident "gns" ) : CompositeParticipantDef_List { : Nonempty_CompositeParticipantDef_List ( : CompositeParticipantDef ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "Food" ) ) } ) : PartSpec_CommaList { : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "Foo" ) ) } ) : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "X" ) ) } ) : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "edu" ) : Nonempty_LongName ( : ShortName ( : Ident "neu" ) : Nonempty_LongName ( : ShortName ( : Ident "ccs" ) : Nonempty_LongName ( : ShortName ( : Ident "demeter" ) : Nonempty_LongName ( : ShortName ( : Ident "S" ) ) ) ) ) ) } ) ) ) ) } : With ( : Entry_BracedList { : Nonempty_Entry_BracedList ( : Around ( : ShortName ( : Ident "gns" ) : NameSpec ( : ShortName ( : Ident "get_str" ) ) : NameSpec ( : ShortName ( : Ident "counted" ) ) ) : Nonempty_Entry_BracedList ( : Export ( : NameSpec ( : ShortName ( : Ident "UNKNOWN30" ) ) : NameSpec ( : ShortName ( : Ident "UNKNOWN31" ) ) ) ) ) } ) ) ) } ) ) } ) ) : Nonempty_AdapterItem_List ( : AdapterItem ( : CollabRef_CommaList { : Nonempty_CollabRef_CommaList ( : SharedCollab ( : CollabName ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN32" ) ) } ) ) ) } : AttachmentSpecList ( : Attachment_List { : Nonempty_Attachment_List ( : Attachment ( : ShortName ( : Ident "UNKNOWN33" ) : CompositeParticipantDef_List { : Nonempty_CompositeParticipantDef_List ( : CompositeParticipantDef ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN34" ) ) } ) : PartSpec_CommaList { : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN35" ) ) } ) : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN36" ) ) } ) : Nonempty_PartSpec_CommaList ( : PartSpec ( : LongName { : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN37" ) : Nonempty_LongName ( : ShortName ( : Ident "UNKNOWN38" ) ) ) } ) ) ) ) } : With ( : Entry_BracedList { : Nonempty_Entry_BracedList ( : Export ( : NameSpec ( : ShortName ( : Ident "UNKNOWN39" ) ) : NameSpec ( : ShortName ( : Ident "UNKNOWN40" ) ) ) : Nonempty_Entry_BracedList ( : Export ( : NameSpec ( : ShortName ( : Ident "UNKNOWN41" ) ) : NameSpec ( : ShortName ( : Ident "reset" ) ) ) ) ) } ) ) ) } ) ) } ) ) ) ) } ) ) ) ) ) } ) done 3 start the traversal participant name Counted participant name Foo participant name Food done Question 2: =========== 100 points. Design a program that solves the following problem: Given a class dictionary, find out whether it is connected in the sense that from the first class all other classes are reachable. Example: A = B. B = C D. C : X | Y. D = . X = . Y = Q. Z : Q common B. is connected. A = B. C = D. is not connected because there is no connection from B to C. By program design I mean: 1. Sketch a class dictionary. 2. What kind of growth plan would you use? 3. What kind of traversals would you use? 4. What kind of visitors? 5. What kind of connection definition do you use?