Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that the following rules are proposed as possible optimizations to be implemented in your compiler. Hello, These are the guidelines that you can use

Suppose that the following rules are proposed as possible optimizations to be implemented in your compiler. Hello, These are the guidelines that you can use to answer the question, But it is not necessary Required. expression simplifies to expression (fst e, snd e) e fst (e1, e2) e1 snd (e1, e2) e2 Describe how you could implement these rules so that the simplifications are made only when the program's semantics is correctly preserved. [5 marks] 5 (TURN OVER) CST.2016.3.6 5 Concepts in Programming Languages (a) Explain what is meant by a monad in a programming language, giving the two fundamental operations of a monad along with their types. [3 marks] Describe an algorithm (other than thresholding) which will convert a greyscale image (8 bits per pixel) to a bi-level black and white image (1 bit per pixel), with the same number of pixels, while retaining as much detail as possible. [8 marks] (c) Explain what specular and diffuse reflection are in the real world. State and explain equations for calculating approximations to both in a computer. [8 marks] 6 [TURN OVER CST.2006.13.6 7 Compiler Construction (a) Explain the differences (illustrating each with a small program) between (i) static and dynamic binding (scoping); [4 marks] (ii) static and dynamic typing. [2 marks] (Use the next available subnet) Network R (LAN) requires 4 Usable host IP addresses. (Use the next available subnet) Network X (WAN) requires 2 Usable host IP addresses. (Use the next available subnet) Network Y (WAN) requires 2 Usable host IP addresses. (Use the next available subnet) Network Z (WAN) requires 2 Usable host IP addresses. (Use the next available subnet) Subnet Table: Subnet Description Network Address First Host Address Second Host Address Last Host Address Broadcast Address Subnet Mask Network P Network Network R Network X NA Network Y NA Network Z NA Part 2: Complete the Addressing Table Document the addressing scheme and complete the addressing table. a. Assign the Last host IP address from Network P subnet to G0/1 interface of Ri. b. (a) Give a suitable state vector for a simple, finite-difference, time domain simulation of the drink system. [3 marks] (b) List the initial values and any other parameters that are needed for the simulation. TLBs and caches are examples of content-addressable memories (CAMs). (a) What is the principal difference between a CAM and a RAM? [4 marks] (b) What is the difference between fully associative, set associative and direct mapped lookup? [6 marks] (c) Why are TLBs always much smaller than caches? [4 marks] (d) Which of the lookup mechanisms in part (b) is usually used for a TLB and why aren't the other mechanisms usually used? [6 marks] (b) Consider the use of a monad for input-output. For the purposes of this question, take the IO monad as including two operations readint and writeint which respectively read integers from stdin and write integers to stdout. Give the types of these operators. [2 marks] (c) Assume MLreadint and MLwriteint are primitives with side effects for inputoutput and consider the ML expression add1 of type int: let val x = MLreadint() in MLwriteint(x+1); x end (i) Give an equivalent expression which uses the IO monad instead of side-effects, and state its type. [3 marks] (ii) Give a function run2diff which can be applied to your answer to part (c)(i). When so applied it should give a value in the IO monad which corresponds to ML code that runs add1 twice and returns the difference between the values read. [4 marks] datatype 'a vtree = Lf of 'a | Br of ('a vtree) list; (i) Write function flat t that converts a given tree t of this type to a list of the labels (without eliminating duplicates). Your function should run in linear time in the size of the tree. [4 marks] (ii) Write function counts x t that counts the number of times that x occurs as a label in t, but without first converting t to a list. Well-known utility functions may be assumed to be available.

trojan caches are examples of content-addressable memories (CAMs). (a) What is the principal difference between a CAM and a RAM? [4 marks] (b) What is the difference between fully associative, set associative and direct mapped lookup? [6 marks] (c) Why are TLBs always much smaller than caches? [4 marks] 4 CST.2016.3.5 4 Compiler Construction Consider writing a compiler for a simple language of expressions given by the following grammar, e ::= n (integer) | ? (read integer input from user) | e + e (addition) | e e (subtraction) | e e (multiplication) | (e, e) (pair) | fst e (first projection) | snd e (second projection) (a) Describe the tasks that should be carried in implementing a front end for this language and any difficulties that might be encountered. [5 marks] (b) Suppose that the target virtual machine is stack-oriented and that the stack elements are integer values, and addresses can be stored as integers. Explain which other features are required in such a virtual machine. Invent a simple language of instructions for such a machine and show how it would be used to implement each of the expressions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Networking A Top-Down Approach

Authors: James F. Kurose, Keith W. Ross

5th edition

136079679, 978-0136079675

More Books

Students also viewed these Computer Network questions

Question

Estimate the moment of inertia of a bicycle wheel.

Answered: 1 week ago

Question

69. In the match problem, say that (i, j), i Answered: 1 week ago

Answered: 1 week ago