1. Give an example of a situation where context-sensitive analysis is necessary and explain why a context-free grammar is inadequate. [4] 2. What is the difference between dynamic scope and static scope? Why do modern languages tend towards static scope? [4] 3. Discuss, in terms of its abstract interface, how a symbol table is used to used to support scope resolution during semantic analysis. [5] 4. Explain how entries in a recently closed scope (assuming static scope) can be removed from an imperatively designed symbol table, implemented as a hash table. [5] 5. Discuss the efficiency constraints that are applicable to using hash tables vs. binary search trees for an imperative implementation of a symbol table. [5] 6. What is the difference between name and structural type checking? [2] 7. With non-reentrant subprograms, why is a stack not necessary for activation records? [2] 8. Explain one possible advantage of a callee-save approach to register handling. [2] 9. Assume the following algorithm calculates the addresses of elements in a multi-dimensional array. Use it to derive simple formulae for the 2-d array X[d1S..d1E][d2S..d2E] and 4-d array X[d1S..d1E][d2S..d2E][d3S..d3E][d4S..d4E]. Show how the formulae can be rewritten for optimal runtime execution. [6] Addr = 0 For each dimension d Addr *= (end index of d – start index of d + 1) Addr += (given index in position d – start index of d) Addr = Addr * n + address of first element 10. Draw the stack of activation records corresponding to the following program when it is executing the “print” statement. [10] (Assume static chains). program main () void funca ( int x ) { if (x>0) funcb (x-1) } void funcb ( int x ) { if (x>0) funca (x/2); else print (‘done.’); } funcb (6); } 11. Draw the display corresponding to the above stack if static chains are not used for non-local reference resolution. [5] 12. Discuss two reasons why stack-based variables are needed in activation records, over and above the use of registers. Then discuss two reasons why registers can be used efficiently for parameter passing instead of (or in addition to) the stack. [8] 13. What is a view shift and how is it implemented? (Provide a sequence of abstract instructions and discuss) [6] 14. Answer questions 7.1 and 7.2 of Appel.