module 1.. Explain the structure of an object module which an…
Question Answered step-by-step module 1.. Explain the structure of an object module which an… module 1..Explain the structure of an object module which an assembler or compiler might produce to be processed by a linker. Your answer should include discussion of the various object module features needed to represent the compiled form of the C program: int a[10] = { 2,3,5,7,11,13,17,19,23,29 }; extern int b[10]; extern int g(int); int f(int y) { return g(y) + b[5] + a[6]; } [10 marks] 4 CST.98.6.5 6 Comparative Programming Languages Many languages either forbid explicit pointer arithmetic or restrict its use. What kinds of problem are they seeking to avoid? Why is it allowed (with some restrictions) in C and C++, and commonly used by programmers? [8 marks] What are the dangers inherent in allowing memory deallocation to be under the direct control of the programmer? Given these dangers, why has memory deallocation not been automated in standardised C or C++? [12 marks] 7 Prolog for Artificial Intelligence According to the rules of the Billy Badger Fan Club, an applicant is acceptable for membership provided that: The applicant must have two proposers who are members of the club. (a) Give two reasons why a compiler is typically broken down into passes (orphases) and indicate a typical set of passes and the data structures passedbetween them. [4 marks](b) nd run within many browsers, might differ from that ofcompiling an application and running it multiple times on a single machine.sign a protocol (including message formats) for distributing this information across the network. [10 marks] (c) Give a bound on the total amount of information which is transmitted to ensure that every node acquires complete topology information. [5 marks] 2 CST.98.6.3 4 Computer Graphics and Image a rectangular array of square pixels. The panel is tinted with a special ink which allows each pixel to range from totally transparent to transmitting only the colour of the ink. Each pixel has an 8-bit value. For example, if the ink is blue then a pixel value of 0 would be totally transparent, 255 totally blue (only blue light transmitted) and 100 a light blue. light light diffuser panel viewer The inventor has recently found that he can make the special ink in any colour he likes, but that each panel can be tinted with only one of these colours. He proposes to use three inks in three panels to make a 24-bit colour display: a red-tinted panel, a green-tinted panel and a blue-tinted panel will be stacked up to make a full-colour display (see picture). A value of (0, 0, 0) will thus be white (transparent), (255, 0, 0) red and (255, 255, 255) black. light light diffuser viewer red panel green panel blue panel Explain why this will not work. [4 marks] Modify the three-panel design so that it will work. [3 marks] In common with other 24-bit “full-colour”. Text-based play: The main() method of GameEngine class should support a text-based game play in the console.Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well1 Compiler Construction2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features.Question 3: Game GUI: The goal of this stage is to use JavaFX to add an elegant and fully functional GUI to the game so that it can more easily be played on desktop computers. GUI should have the following features: event-handling of mouse events, including buttons for starting game and moving up/down/left/right; display of bitmap images (recommend use some large images for the background whole game, and use some small images for different items/cells in the map, so that the game looks professional and entertaining); multiple panels, with a main gaming panel to display the game, plus one or more panels around the edges to display game options, score information, and control and help buttons etc.; a clean separation between the back-end (game engine) and front-end (GUI) classes using different Java package names, as described above;Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well displays (for example CRT, LCD), your display cannot display every colour which a human can perceive. Why not? [3 marks] In image compression we utilise three different mechanisms to compress pixel data: (a) mapping the pixel values to some other set of values (b) quantising those values (c) symbol encoding the resulting values Explain each mechanism, why it helps us to comprogramming language with a C-like syntax, with integer variables and functions and with static binding of free variables. Your manager can parameterise certain aspects of the language, including the following three options: For “int x = e;” whether the variable x has the same l-value of e or whether a new l-value is created and initialised to the r-value of e. If e is only an r-value then a new l-value is created in both circumstances. For “int f(int x) { … }” whether the variable x is passed by l-value (“by reference”) or by r-value (“by value”). If the switch is set to “l-value” and the value passed is only an r-value then a new l-value is created, initialised and passed. For “int f(int x) { … y … }” (where the variable y is free to f) whether the value of y is calculated at the times of its uses (association by l-value) or at the time of the definition of f (association by r-value). As a test of your programming skills your manager asks you to program which tells how the language has been parameterised. Do so by printing a 3-digit decimal number where the “hundreds” digit is one or two according to whether the first option is by l-value or r-value respectively, similarly with the “tens” digit for the second and with the “units” digit for the third option. [10 marks] Explain the structure of an object module which an assembler or compiler might produce to be processed by a linker. Your answer should include discussion of the various object module features needed to represent the compiled form of the C program: int a[10] = { 2,3,5,7,11,13,17,19,23,29 }; extern int b[10]; extern int g(int); int f(int y) { return g(y) + b[5] + a[6]; } [10 marks] 4 CST.98.6.5 6 Comparative Programming Languages Many languages either forbid explicit pointer arithmetic or restrict its use. What kinds of problem are they seeking to avoid? Why is it allowed (with some restrictions) in C and C++, and commonly used by programmers? [8 marks] What are the dangers inherent in allowing memory deallocation to be under the direct control of the programmer? Given these dangers, why has memory deallocation not been automated in standardised C or C++? [12 marks] 7 Prolog for Artificial Intelligence According to the rules of the Billy Badger Fan Club, an applicant is acceptable for membership provided that: The applicant must have two proposers who are members of the club. The applicant must be aged between 18 and 30 years of age (inclusive). Each proposer must have been a member for at least two years. Each proposer must not be a parent of the applicant. Prolog program that includes a rule for deciding whether an applicant is acceptable for membership, illustrating with a sample database. [20 marks] 5 [TURN OVER CST.98.6.6 8 Databases Explain what is meant by a referential integrity constraint in a relational data model. [4 marks] The University of Cambridge is determined to maintain its standards under increasing financial pressure. The government maintains league tables of various kinds: teaching quality, research rating, unit cost of each student place. The university still enjoys a high reputation worldwide, but it is in competition with institutions such as MIT and Stanford whose unit costs are much greater. The only way to provide facilities such as new research laboratories, graduate accommodation, a much-needed swimming pool, is by public appeal. It is vital that there is close liaison between the university development offices and colleges so that prospective donors do not become alienated by simultaneous demands. You have been invited by the university to assist in recording details of its fund-raising. The main purpose is to coordinate the activities of agencies such as the university and college development offices in their dealings with prospects. The latter may be alumni of some college, charitable foundations or major companies with an educational commitment; it is important to record their interests (bioscience, student welfare, sport) so that they can be approached in a favourable context; also their potential resources, in order to maximise the possible benefit to the university. At any time a number of projects need funding: each will be developed by a single agency, requiring that a target sum be raised by a given date; projects will have one or more purposes which may be linked with the interests of prospects. The other main use of the database is to keep a diary of interaction with prospects; in order to retain their goodwill it is essential to know who has been invited where and when, and in what context. Design the schema for a relational database that will record this information. State clearly any assumptions that you need to make in order to complete the design, and indicate any difficulties that you foresee in maintaining the database. [16 marks] 6 CST.98.6.7 SECTION C 9 Foundations of Functional Programming The binary trees, denoted by B, whose branch nodes contain natural numbers, are generated by the gramma1. Text-based play: The main() method of GameEngine class should support a text-based game play in the console.2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features. Question 3: Game GUI: The goal of this stage is to use JavaFX to add an elegant and fully functional GUI to the game so that it can more easily be played on desktop computers. GUI should have the following features: event-handling of mouse events, including buttons for starting game and moving up/down/left/right; display of bitmap images (recommend use some large images for the background whole game, and use some small images for different items/cells in the map, so that the game looks professional and entertaining); multiple panels, with a main gaming panel to display the game, plus one or more panels around the edges to display game options, score information, and control and help buttons etc.; a clean separation between the back-end (game engine) and front-end (GUI) classes using different Java package names, as described above;Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well1 Compiler Construction(a) Give two reasons why a compiler is typically broken down into passes (orphases) and indicate a typical set of passes and the data structures passedbetween them. [4 marks](b) nd run within many browsers, might differ from that ofcompiling an application and running it multiple times on a single machine. B ::= Leaf | Br (n, B, B) where n ranges over natural numbers. Although this question concerns the encoding of binary trees as ?-terms, you may use the encodings of other well-known data structures, such as booleans and pairs, provided you state the properties assumed. Give an encoding of binary trees as ?-terms by defining as ?-terms (a) Leaf and Br, used to construct the ?-terms corresponding to binary trees; (b) isLeaf, which tests whether a ?-term corresponds to a leaf or a branch node; (c) value, fstsubtree and sndsubtree, used to identify respectively the natural number and the two subtrees at a branch node. Justify your answer by describing the behaviour of isLeaf, value, fstsubtree and sndsubtree: for example, the reduction isLeaf(Leaf) true describes part of the behaviour of isLeaf. [8 marks] Consider the function treeadd defined inductively on the structure of binary trees by treeadd (m, Leaf) = Leaf treeadd (m, Br (n, B1, B2)) = Br (m + n,treeadd (m, B1),treeadd (m, B2)) Give and justify a ?-term which encodes treeadd, using the ?-term Y ? ?f.(?x.f(xx))(?x.f(xx)). [6 marks] Give the ?-term for the infinite binary tree whose branch nodes consist of zeros at even depths and ones at odd depths, as pictured below: 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 . . . [6 marks] 7 [TURN OVER CST.98.6.8 10 Logic and Proof Outline the concepts behind modal logic. Illustrate your answer by explaining the meaning of the axiom A ? tu A. [6 marks] Attempt to prove, using rules for S4, the following sequents: tu(A ? B) ? (tuA) ? (tuB) (tuA) ? (tuB) ? tu(A ? B) For each sequent, briefly explain why it is valid (or is not, as the case may be). [4 + 4 marks] Use resolution to derive a contradiction from this set of clauses: {¬P(x, x), P(x, a)} {P(x, x), P(x, f(a))} {¬P(y, f(x)), ¬P(y, x)} [6 marks] 8 CST.98.6.9 11 Complexity Theory Here are some informally expressed opinions about computational complexity. They may be correct, incorrect, misleading or meaningless. In some cases the truth or otherwise of the statement might not be known, either in the sense of it not having been covered in the course or by the answer not being known by anybody anywhere. For each statement comment on its validity and in cases where that is both necessary and straightforward produce an adjusted version of the observation that is properly valid. You are not expected to include proofs to support your claims. (a) Problems that are not NP-re easy to solve. [3 marks] (b) Problems that are NP-complete will never be solved in reasonable amounts of time even though computers continue to get faster and faster. [3 marks] (c) To test a number N to see whether it is prime you just have to do testdivision by each of the numbers from 2 to N ? 1, and since there are only N ?2 of these and division can be done in time O(n 2 ) this is polynomial time. Thus primality testing is in the class P. [4 marks] (d) There is a polynomial-time reduction from the k-clique problem to 3-SAT. [3 marks] (e) There is a polynomial-time reduction from 3-SAT to the k-clique problem. [3 marks] (f ) There have been proposals that biological computers based on DNA might use the massive parallelism of their biochemical activity to solve NP problems rapidly. If such systems could be made to work reliably this would solve the theoretical challenge posed by the concept of NP-completeness. [4 marks] 9 [TURN OVER CST.98.6.10 12 Semantics of Programming Languages What is meant by a labelled transition system? [2 marks] A language of commands, C, for interactive input/output is given by C ::= skip | ` := ` | getc(`) | putc(`) | C ; C | if ` = ` then C else C | while ` = ` do C where ` ranges over some fixed set of locations for storing characters. The command `1 := `2 copies the contents of `2 to `1. The command getc(`) reads the next character from the standard input stream into `. The command putc(`) writes the contents of ` to the standard output stream. The conditional and while-loop commands involve testing whether or not the contents of two locations are equal. The commands skip and C1 ; C2 have their usual meanings. Define an operational semantics for this language as a labelled transition system whose configurations are (command, state)-pairs, hC, si, and whose actions are of the form get(c) (for reading a character c), put(c) (for writing a character c), and ? (for transitions not involving input/output). [9 marks] Explain, without proof, in what sense this labelled transition system is deterministic. [2 marks] A finite list t of non-? actions is a trace of hC, si if there is a sequence of labelled transitions starting from hC, si whose corresponding list of actions is equal to t once any ? -actions have been erased from it. Write C ?tr C 0 to mean that for any state s, the configurations hC, si and hC 0 , si have the same traces. Show that C1 ?tr C2, where C1 def = getc(`1) ; putc(`1) and C2 def = getc(`1) ; `2 := `1 ; putc(`2). [3 marks] By considering C1 ; C and C2 ; C for a suitable C, or otherwise, show that ?tr does not have the congruence property for this language. This question covers a wide variety of topics in the interdisciplinary subject of Compiler Construction. (a) What is the difference between lexical analysis and parsing? [2 marks] (b) Give an example of an ambiguous context-free grammar together with a demonstration that it is indeed ambiguous. [3 marks] (c) In the context of functional programming, describe the concept of a closure and how it is used. [3 marks] (d) Can any recursive function be transformed into a tail-recursive function? Briefly explain you answer. [3 marks] (e) Describe one advantage and one disadvantage for using reference counting as a technique for memory management. [2 marks] (f ) For what kinds of programming languages might you employ static links on the stack? Explain your answer. [3 marks] (g) Consider an optimisation that replaces any expression of the form 0 × e with 0, where e is an arbitrary expression. Why might this rule be useful in a compiler’s optimisation phase? Is it always correct? [4 marks] 4 CST1.2018.4.5 4 Compiler Construction Suppose that we are to implement a compiler for the following simple, strongly-typed language with types t, expressions e, and programs p. t ::= int | t ? t (product type) e ::= n (integer) | ? (read integer input by user) | e + e (addition) | e ? e (subtraction) | (e, e) (pair) | fst e (first projection) | snd e (second projection) | f(e) function application | let x : t = e in e end (let binding) p ::= e | fun f(x : t) : t = e ; p (function definition, recursion allowed) In the above x and f range over identifiers. For example, here is a simple program: fun swap (p : int * int) : int * int = (snd p, fst p) ; fun swizzle (p : int * (int * int)) : (int * int) * int = (swap (snd p), fst p) ; swizzle (?, (?, ?)) You are asked to implement this language on a stack machine that has no heap. All stack entries are simple words (integers or pointers). Hint: consider using type information. (a) Describe how your compiler will use the stack to implement function calls and returns. Describe any auxiliary pointers that you might need. Is there anything about the language above that makes this especially easy? [5 marks] (b) Describe how you allocate space on the stack for a value of type t. [5 marks] (c) Describe how your compiler will implement expressions of the form (e1, e2). Explain how the order of evaluation (left-to-right, or right-to-left) impacts your choices. [5 marks] (d) Describe how your compiler will implement expressions of the form fst e and snd e. [5 marks] 5 (TURN OVER) CST1.2018.4.6 5 Further Java A social network can be represented as an undirected graph where vertexes represent people and edges represent bidirectional friendship relationships between two people. A developer constructs a simple representation of a social network using instances of the following Java class: public class Person implements Serializable { private final long accountId; private String fullname; private Set friends; public Person(String fullname) { … } public void addFriends(Set friends) { … } } (a) The developer wishes to ensure that all public methods for Person are thread-safe. Describe what thread-safety means in this context. [1 mark] (b) thread-safe implementation of the constructor for Person. You must ensure no two instances of Person share the same accountId. You mayditional private fields, methods or inner classes in Person. [4 marks] (c) thread-safe implementation of addFriends which uses fine-grained locking to atomically establish new bidirectional friendship links between people in the social network. [5 marks] (d) The developer wishes to serialize a copy of the graph of Person objects to disk. Without modifying the definition of Person, write n implementation of a non-thread-safe static method void SocialNet.save(Set everyone, ObjectOutputStream oos) which will writ a single copy of all people in everyone to oos. Hint: oos.writeObject(obj) saves a copy of all objects reachable via references from obj and safely handles any cycles of references. [6 marks] (e) Give two reasons why it is useful to store a single copy of each Person object in Part (d). [2 marks] (f ) Describe in words the modifications you would need to make if there are multiple threads attempting to add friendship links to the social network concurrently with the execution of SocialNet.save. [2 marks] 6 CST1.2018.4.7 6 Security (a) A Linux cloud server used by your team has the following discretionary access-control setup: $ getent group admin users admin:*:9001:alice users:*:9002:alice,bobby,carla $ ls -ld . * */* drwxr-xr-x 3 carla users 4096 Apr 2 2017 . -rwsr–r-x 1 bobby admin 241859 Jan 1 2013 proedit -r–rw–w- 1 bobby admin 6355 Jul 24 2016 readme.txt -rw—-r– 1 carla admin 1459 Jun 12 2016 runtime.cfg dr–r-xr-x 2 bobby users 4096 Jul 23 2016 src -rw-r–r– 1 bobby users 26339 Apr 28 2018 src/code.c -r–rw—- 1 alice admin 6701 Jan 23 2017 src/code.h The file proedit is a normal text editor, which allows its users to open, edit, save and execute files. Copy and complete the access-control matrix illustrated below, such that it shows for each of the above five files, whether alice, bobby, or carla are able to obtain, directly or indirectly, read (R) or replace (W) access to its contents. Underline any access that can only be obtained through elevated rights. proedit readme.txt runtime.cfg src/code.c src/code.h alice bobby carla [12 marks] (b) Several Linux file systems extend the POSIX file permission bits with an access-control list mechanism defined in POSIX.1e Draft 17. Explain four significant differences between these Linux ACLs and those of Windows NTFS. [8 marks] 7 (TURN OVER) CST1.2018.4.8 7 Security (a) An application process receives information via a UDP packet over a wired Ethernet LAN connection. If the packet carries a source port number below 1024, under which conditions can the information be trusted? [6 marks] (b) What is a UDP-based amplification attack and why are similar attacks far less practical via TCP? [6 marks] (c) Name and briefly explain four techniques that the designers of C compilers and operating system kernels can implement to reduce the risk of stack-based buffer-overflow attacks. [4 marks] (d) How can an implementation of the C function strcmp() cause a vulnerability to a side-channel attack, and how can this be mitigated? [4 marks] 8 CST1.2018.4.9 SECTION B 8 Semantics of Programming Languages Consider the following syntax up to alpha equivalence, where n ranges over natural numbers, x over a set of variables, and (as usual) x is binding in e in fn x ? e. expressions, e ::= n | x | fn x ? e | e e0 values, v ::= n | x | fn x ? e (a) Define free variables fv(e) and capture-avoiding substitution {e/z}e 0 . [3 marks] (b) Define a left-to-right call-by-value reduction relation e ?? e 0 . [3 marks] Implementing a language using substitution is inefficient, as each substitution has to traverse a potentially large subterm. Consider the following proposal for an abstract machine for this language using environments E, lists of variable/value pairs. hE, ei ?? hE 0 , e 0 i (x , v) ? E hE, x i ?? hE, vi lookup x 6? dom(E) ? fv(range(E)) ? fv(v) hE,(fn x ? e) vi ?? h(x , v) :: E, ei fn hE, e1i ?? hE 0 , e 0 1 i hE, e1 e2i ?? hE0 , e 0 1 e2i app left hE, e2i ?? hE 0 , e 0 2 i hE, v1 e2i ?? hE0 , v1 e 0 2 i app right (c) Give the sequence of abstract-machine reduction steps, including the configurations and the names of the rules used, for the initial configuration below. You need not give full derivation trees. h[],((fn x ? (fn y ? x y)) (fn z ? z)) 3i [5 marks] (d) Explain, with a concrete example and its reduction sequence, what could go wrong if the premise of fn had been omitted.1. Text-based play: The main() method of GameEngine class should support a text-based game play in the console.2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features. Question 3: Game GUI: The goal of this stage is to use JavaFX to add an elegant and fully functional GUI to the game so that it can more easily be played on desktop computers. GUI should have the following features: event-handling of mouse events, including buttons for starting game and moving up/down/left/right; display of bitmap images (recommend use some large images for the background whole game, and use some small images for different items/cells in the map, so that the game looks professional and entertaining); multiple panels, with a main gaming panel to display the game, plus one or more panels around the edges to display game options, score information, and control and help buttons etc.; a clean separation between the back-end (game engine) and front-end (GUI) classes using different Java package names, as described above;Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well1 Compiler Construction(a) Give two reasons why a compiler is typically broken down into passes (orphases) and indicate a typical set of passes and the data structures passedbetween them. [4 marks](b) nd run within many browsers, might differ from that ofcompiling an application and running it multiple times on a single machine. information be trusted? [6 marks] (b) What is a UDP-based amplification attack and why are similar attacks far less practical via TCP? [6 marks] (c) Name and briefly explain four techniques that the designers of C compilers and operating system kernels can implement to reduce the risk of stack-based buffer-overflow attacks. [4 marks] (d) How can an implementation of the C function strcmp() cause a vulnerability to a side-channel attack, and how can this be mitigated? [4 marks] 8 CST1.2018.4.9 SECTION B 8 Semantics of Programming Languages Consider the following syntax up to alpha equivalence, where n ranges over natural numbers, x over a set of variables, and (as usual) x is binding in e in fn x ? e. expressions, e ::= n | x | fn x ? e | e e0 values, v ::= n | x | fn x ? e (a) Define free variables fv(e) and capture-avoiding substitution {e/z}e 0 . [3 marks] (b) Define a left-to-right call-by-value reduction relation e ?? e 0 . [3 marks] Implementing a language using substitution is inefficient, as each substitution has to traverse a potentially large subterm. Consider the following proposal for an abstract machine for this language using environments E, lists of variable/value pairs. hE, ei ?? hE 0 , e 0 i (x , v) ? E hE, x i ?? hE, vi lookup x 6? dom(E) ? fv(range(E)) ? fv(v) hE,(fn x ? e) vi ?? h(x , v) :: E, ei fn hE, e1i ?? hE 0 , e 0 1 i hE, e1 e2i ?? hE0 , e 0 1 e2i app left hE, e2i ?? hE 0 , e 0 2 i hE, v1 e2i ?? hE0 , v1 e 0 2 i app right (c) Give the sequence of abstract-machine reduction steps, including the configurations and the names of the rules used, for the initial configuration below. You need not give full derivation trees. h[],((fn x ? (fn y ? x y)) (fn z ? z)) 3i [5 marks] (d) Explain, with a concrete example and its reduction sequence, what could go wrong if the premise of fn had been omitted.1. Text-based play: The main() method of GameEngine class should support a text-based game play in the console.2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features. Computer Science Engineering & Technology Python Programming Share QuestionEmailCopy link Comments (0)


