Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Tuesday 19 May 2020, 14:15 BST

Programming Languages H

COMPSCI 4016

1.      This question concerns ambiguity in programming languages.

a.   Comment on ambiguity in programming languages and its effects.

b.   Write down a simple ambiguous grammar.

c.   Illustrate the ambiguity of the grammar on a term of the language.

d.   Fix the grammar so it is not ambiguous.

e.   Illustrate the new grammar, using the same term as in part (b).

Note: obviously, go beyond Calc and Fun grammars.

If you are typing your answers, then

    use colon “:” and equal “=” for grammar production, i.e., ::=  and use pipe

“|” to separate the productions.

    Use hyphens “–“ and pipes “|” in sequence to simulate lines and thus draw

trees, for example, the syntax tree of the put command in Calc would look like the following:

|-------- com --------|

|              |               |

|           expr            |

|              |               |

|           prim          |

|              |               |

|             id              |

|              |               |

put          n             \n              [10 marks]

2.      Discuss the different categories of types you studied in the course, by defining and comparing them with each other.

Write two correct (and different) programs, one in Java and one in another statically-typed high-level programming language of your choice, where:

i.      You use all the categories of types.

ii.      Comment on each category.

iii.      Compare the two programs with respect to the types, by drawing on analogies and differences.

Note: each program, together with the explanations above (i.—iii.) should be no    more than 700 words. Definitions and discussions on types should be no more than 100 words. [20 marks]

3.      Write a brief technical report explaining run-time organisation for programming    languages covering topics including data representation and memory management. Compare and discuss possible technical approaches providing examples in various programming languages, e.g. C, Java, etc. You can assume

i.      The programming language is statically typed.

ii.      The compiler decides the size and layout of each type.

iii.     All variables of the same type have the same size.   [30 marks]