Programming Languages and Compilers

 

Lecture 7

 

In this lecture we will look a bit more at types and type systems.

 

The slides for this lecture can be found here.

 

Literature

 

Sebesta, chapter 6.

 

As background information I can recommend taking a look at the web page Type theory - Wikipedia and the introduction to Luca Cardelli’s note on type systems http://research.microsoft.com/Users/luca/Papers/TypeSystems.pdf

The other sections in this note should be easier to read after you have completed the SS course.

Exercises

 

Exercises for lecture 7 will be done from 12.30 till 14.15 before Lecture 8 on Thursday the 11th of March.

 

  1. Do the following for PhP, SML, C and Java: (You may replace the languages with other languages you are familiar with)
    1. Describe the set of values that data objects of type Integer (int) may contain
    2. Determine the storage representation for values of Integer type
    3. Determine the syntactic representation used for constants of that type
    4. Determine the set of operations defined for Integers and give the signature for these operations and syntactic representation
    5. Determine if any of the operation symbols defined for integers may be overloaded
    6. Determine whether static or dynamic type checking is used to determine the validity of each operation.
  2. Do exercise 1 for floating point data type
  3. Do exercise 1 and 2 for your own language
  4. Consider the languages SML, C, Java and Perl or JavaScript. For each language determine what the language implementation does with respect to constructs that cannot be checked statically, e.g. arrays bounds check, access to pointers/references and division by 0.
    1. Does the language provide dynamic checking or leave it unchecked at runtime?
    2. Are there other constructs you can think of?
    3. What about the language you are designing?
  5. Do Sebesta exercise 13 on page 288 (rather than write, discuss with your group)
  6. Do Sebesta exercise 14 on page 288.
  7. Do Sebesta exercise 15 on page 288.
  8. The language SIMSCRIPT allows data elements of different types to be stored as elements of an array. One reason for this is that arrays in SMSCRIPT are implements as vectors of pointers to the data elements thus each element in an array has a uniform representation. Both Java and SML use the same implementation technique, but do not allow data elements of mixed types in arrays. Can you explain why? Can you give a work-around in Java which doesn’t work in SML that enables you to store mixed elements in an array? Can you explain why this works in Java? What about your own language – will it allow mixed types in arrays/compound data types – why/why not?
  9. Do Sebesta exercise 9 on page 288.