Lab for Automated Reasoning and Analysis LARA

Homework 05

To be handed on October 28th, 10AM

Problem 1

If the following programs type-check according to the rules given in the course, give the corresponding type derivation tree, otherwise give a partial tree that shows where it doesn't work (like in Solution to Exercises 05).
Please write clearly.
You may need to add some simple and obvious typing rules not given in the course. In this case give the new rules.

a)

int x;
int y;
if (1 > 42)
  {return x}
else
  {return y}
x := y;

Solution
b)

int x;
int y;
if (0 > 0) {
  if (3 > 4) {x = y;}
  else {y = x;}
}
else
  if (4 > 3) {x = x;}
  else {y = y;}
}

Solution
c)

Class C {
  int f(int x) {
    return 1+f(x);
  }
}

Solution

Problem 2

Suppose we allow nested function definitions:

varDecl ::= type ID | method

Give a new set of type rules to type-check a program with nested function definitions.

Solution

 
cc09/homework_05.txt · Last modified: 2009/10/28 21:57 by losa
 
© EPFL 2018 - Legal notice