Week 7

Exercises on type checking

  1. Give the type rules for:
    • for statements; and
    • array expressions.

    Motivation: this questions tests that you are able to formalize type rules. This will allow you to write type checker implementations in a more straightforward fashion.

  2. Construct the type proof for the following statement sequence:
    Cons x,y; int z; x = new Cons(z+1,y);
    

    Motivation: this question tests that you can read existing type rules and apply them.

  3. Consider a scenario, where we extend JOOS with a type float that also has a + operator. Furthermore, we want int values to be implicitly coerced into float values as needed. Explain the implications for the type checker.

    Motivation: it is useful to be able to extend grammars with new types.

  4. (Optional.) A radical extension of the JOOS type system allows a variable to be typed as:

    A,B,C x;
    

    which means that x may contain objects of either of the classes A, B, or C. Types are thus finite sets of classes, rather than just single classes. With the appropriate type rules, this will allow more programs to be accepted as statically type correct. Show examples of such type rules for the JOOS syntax. Show that these new rules make the type system strictly more powerful than the standard type system. Do you like this new language? Why or why not?

    Motivation: this question should help you to think about some of the advantages and disadvantages of introducing extra complexity into a language via the type system.

  5. (Optional.) Study the code for type checking JOOS programs. Report on anything that is unclear.

    Motivation: as before, the JOOS compilers are an excellent reference for your own WIG compiler.

Maintained by Christopher J. F. Pickett. [HOME]