CSE401 Midterm, Fall 1997 (Henry)

This is the midterm exam that Robert Henry gave in CSE401 in Autumn 1997. The original electronic version, and all of my paper copies, was lost. One of students who took the class then graciously retyped the exam for me in the Autumn of 2001

ESSAY

What are the advantages to using nondeterminism when writing compilers? The disadvantages?

What are the advantages of using a table driven algorithm for some task in a compiler, over writing code that does the task directly? Disadvantages?

Suppose language L8 has 8 levels of operator precedene, and variant language L4 has 4 levels. L8 and L4 are otherwise identical, and have the same set of operators. What are the implications of this distinction for the programmer using L8 and L4 and compilers for these languages?

Show that the following grammar is LL(1)

  s => AaAb|BbBa
  A => epsilon
  B => epsilon

What actions does an LR shift reduce parser take when it makes a reduction?

Both LL(k) and LR(k) grammars see only k symbols of input as lookahead. However, LR parsers are more powerful than LL parsers. Briefly explain why this is so.

Your friend in the next office wrote the C++ compiler you use for extended PL/0 compiler development. He comes to you and says he has just found a bug in his compiler, and that under some circumstances division of two integers will produce a slightly wrong result. What impact does this have on your extended PL/0 compiler? On your users?

What is regression testing, and how is it used for writing compilers?

Why should the compiler writer not attempt to convert floating point literals to the computer's internal representation?

MACHINES

Show the reduced deterministic finite state machine that recognizes this regular expression. Think before you dive in.

(AB((AB)*|epsilon)(C|epsilon)|epsilon)

Suppose we further extend PL/0's if/then/else/end statement, so that the then and else clauses can appear in any order. A particular kind of clause can appear only 1 or fewer times.

COMPILER CONSTRUCTION

Suppose we wanted to modify part or all of the PL/0 compilation system to support some new requirements. For each of the requirements listed below briefly describe what part of the compilation system would have to be modified to support that change, and what those changes would entail. (Consider each question independently.)

COMPILER BUILDING

I'm a hot shot compiler writer with these problems and resources:

How do I go about building my customer her FOO compiler? On the back of the previous page draw the data flow "T" diagrams for the whole compiler system, carefully labelling boxes and arcs, showing which boxes that I must build from scratch.