Programming Languages and Translators
Homework Assignment #4
Submit solutions electronically on
by 2:40pm, April 24, 2013
- Problems 1-4 are each worth 25 points.
- You may discuss the questions with the TAs and others in the class but your answers
must be in your own words. You must not copy someone
If you consult others or use external sources, please cite the
people or sources used in your answers.
- Solutions to these problems will be posted
on Courseworks on May 1, 2013.
- This assignment may submitted electronically on Courseworks by 2:40pm,
May 1, 2013 for 50% credit.
- Pdf files are preferred.
- Consider the arithmetic expression
u * (v - w) + x / y
and a register machine with instructions of the form
LD reg, src
ST dst, reg
OP reg1, reg2, reg3 // the registers need not be distinct
- Draw an abstract syntax tree for the expression and label the nodes with Ershov numbers.
- Generate machine code for the expression on a two-register machine
minimizing the number of spills.
- Consider the following sequence of three-address code:
x = 0
i = 0
L: t1 = i * 4
t2 = a[t1]
t3 = i * 4
t4 = b[t3]
t5 = t2 * t4
x = x + t5
i = i + 1
if i < n goto L
- Draw a flow graph for this three-address code.
- Optimize this code by eliminating common subexpressions,
performing reduction in strength on induction variables,
and eliminating all the induction variables that you can.
State what transformations you are using at each optimization step.
- Consider the lambda-calculus expression
(λu. (λx. u) u) ((λy. y) (λw. (λv.v) w) ).
- Draw a parse tree for this expression.
- Identify all redexes in this expression.
- Evaluate this expression using normal order evaluation.
- Evaluate this expression using applicative order evaluation.
- Evaluate the lambda-calculus expression
(λx.(λy.(x(λx.xy))))y. What order of
evaluation did you use? Explain all the steps you used in the evaluation.