Question: Comp.5310: Final Assignment Fall 2023 == 1 (Parameter Passing) == Consider the following pseudocode: int a := 3 ; int b := 2 ; int
Comp.5310: Final Assignment Fall 2023 == 1 (Parameter Passing) == Consider the following pseudocode: int a := 3 ; int b := 2 ; int c := 1 ; int d := 7 ; int z; // global variable procedure f(int x) { if a > b and c > d then z := a - d; elseif a > b and c d then x := d - c; elseif a b and c > d then x := c - a; else z := d - a; endif; ... insert code ... } // The main execution starts here. z := a; f(z); print(z); Insert your own code where indicated above. Your code cannot modify the values of a, b, c, and d. Your code must simultaneously make the execution of the program: (a) print a number that is greater or equal than (a + 5) 4, if executed using call by reference. (b) print a number that is smaller or equal than b, if executed using call by value-result. Remember: Do not provide two code solutions (one for (a) and one for (b)). You will have to provide the same code that simultaneously satisfies (a) and (b). == 2 (Type Soundness) == Consider the theorem called type preservation that is covered in the lecture recordings on Blackboard for the 7th December. Consider a language with integers and booleans pairs (e1, e2), which works as we have seen for OCaml (but we use notation T1 T2 for the pair type.). As in that recordings, the type system is such that: if e1 is of type T1 and e2 is of type T2 then the pair (e1, e2) is of type T1 T2. lists [e1, e2, e3, . . . , en]. As in that recordings, the type system is such that: e1, e2, e3, . . . , en are all required to be of the same type T and, if so, the list [e1, e2, e3, . . . , en] is of type List T. a new operator called (pairToList e) that takes a pair and returns a list: The type system requires e to be of type T1 T2, for some types T1 and T2 and, if so, establishes that (pairToList e) is of type List T1. Explain why the following operational semantics reduction rule is not type preserving. (pairToList (e1, e2)) [e1, e2] How would you modify this rule to make it type preserving?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
