Question 1: =========== /proj/asl/lieber/java/java-envs/jk-smallest Consider the following behavior file program.beh. Find the SMALLEST (in terms of number of characters) class dictionary program.cd so that program.beh and program.cd result in an executable Java program. program.beh ============================ A{ traversal t(V v) { to D;} } ClassGraph { traversal f() { to *;} } V { before B (@ set_i(new Integer(5)); @) before C (@ System.out.println(get_i()); @) before D (@ Q q = new R(); @) } Main { (@ static public void main(String args[]) throws Exception { ClassGraph a = ClassGraph.parse(System.in); a.f(); A a1 = A.parse(System.in); V v = new V(); a1.t(v); System.out.println("done "); } @) } Fill in the UNKNOWNS below: A = UNKNOWN. B = UNKNOWN. C = UNKNOWN. D = . V = UNKNOWN . UNKNOWN = . Main = . UNKNOWN : UNKNOWN. R = . sol: A = B. B = C. C = D. D = . V = Integer . ClassGraph = . Main = . Q : R. R = . Question 2: /proj/asl/lieber/java/java-envs/jk-sys-simpler Consider files program.beh, program.cd and program.input below. Find the unknowns in the output shown after program.input. program.beh ------------------------------------------ EquationSystem{ (@ void f() { V1 v1 = new V1(); t1(v1); } @) (@ void g(Variable w) { // creates a new visitor object for each call V2 v2 = new V2(new Equation(), w); t2(v2); } @) traversal t1(V1 v1) { bypassing Exp to Variable;} traversal t2(V2 v2) { bypassing {-> Equation,var,Variable} to Variable;} } V1{ before EquationSystem (@ e = host; @) before Variable (@ // find out where used System.out.println(" V1 " + host.get_variableName().toString()); e.g(host); @) } V2{ before * (@ System.out.println("V2 is in " +host.getClass().toString()); @) before Equation (@ equation = host; @) before Variable (@ System.out.println(" V2 variable " + host.get_variableName().toString()); if (host.get_variableName().equals(variable.get_variableName())) { System.out.println(" V2 " + host.get_variableName().toString() + " is used in an equation"); } @) } Main { (@ static public void main(String args[]) throws Exception { EquationSystem e = EquationSystem.parse(System.in); e.f(); System.out.println("done: "); } @) } program.cd -------------------------------------------------- EquationSystem = List(Equation). Equation = Variable "=" Exp "." . Exp : FunctionCall | Variable | Numbe. FunctionCall = "call" Function CommaList(Variable) . Variable = Ident. Function = Ident. Numbe = Integer. List(S) ~ {S}. CommaList(S) ~ "(" S {"," S} ")". Main = . // visitors V1 = EquationSystem. V2 = Equation Variable. program.input -------------------------------------------- A = B. B = 2. C = 3. Z = call f(A, B, C). The output is below java Main < program.input V1 A V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List V2 variable B V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList V2 variable A V2 A is used in an equation V2 is in class Nonempty_Variable_CommaList V2 variable B V2 is in class Nonempty_Variable_CommaList V2 variable C V1 B V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List V2 variable B V2 B is used in an equation V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList V2 variable A V2 is in class Nonempty_Variable_CommaList V2 variable B V2 B is used in an equation V2 is in class Nonempty_Variable_CommaList V2 variable C V1 C V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List V2 variable B V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList V2 variable A V2 is in class Nonempty_Variable_CommaList V2 variable B V2 is in class Nonempty_Variable_CommaList V2 variable C V2 C is used in an equation V1 Z V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List V2 variable B V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList V2 variable A V2 is in class Nonempty_Variable_CommaList V2 variable B V2 is in class Nonempty_Variable_CommaList V2 variable C done: Question: Write a class dictionary for your favorite video store. You will use the class dictionary to keep track of rentals and returns and of fines. Question 4: =========== Consider the following sentence describing an object (program.input): A = call f1(A,B). B = call f2(C,A). C = 3. D = call f(A, B, C). The class dictionary is (program.cd, same as in question 3): EquationSystem = List(Equation). Equation = Variable "=" Exp "." . Exp : FunctionCall | Variable | Numbe. FunctionCall = "call" Function CommaList(Variable) . Variable = Ident. Function = Ident. Numbe = Integer. List(S) ~ {S}. CommaList(S) ~ "(" S {"," S} ")". Main = . // visitors V1 = EquationSystem. V2 = Equation Variable. Find the unknowns in the following object: : EquationSystem ( < eqs > : Equation_List { : Equation ( < var > : Variable ( < variableName > : Ident "A" ) < exp > : FunctionCall ( < fn > : Function ( < functionName > : Ident "f1" ) < args > : Variable_CommaList { : Variable ( < variableName > : Ident "A" ) , : Variable ( < variableName > : Ident "B" ) } ) ) , : Equation ( < var > : Variable ( < variableName > : Ident "B" ) < exp > : FunctionCall ( < fn > : Function ( < functionName > : Ident "f2" ) < args > : Variable_CommaList { : Variable ( < variableName > : Ident "C" ) , : Variable ( < variableName > : Ident "A" ) } ) ) , : Equation ( < var > : Variable ( < variableName > : Ident "C" ) < exp > : Numbe ( < n > : Integer "3" ) ) , : Equation ( < var > : Variable ( < variableName > : Ident "D" ) < exp > : FunctionCall ( < fn > : Function ( < functionName > : Ident "f" ) < args > : Variable_CommaList { : Variable ( < variableName > : Ident "A" ) , : Variable ( < variableName > : Ident "B" ) , : Variable ( < variableName > : Ident "C" ) } ) ) } )