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.
- Do the following for PhP, SML, C and Java: (You may replace the
languages with other languages you are familiar with)
- Describe the set of values that data objects of type Integer (int)
may contain
- Determine the storage representation for values of Integer type
- Determine the syntactic representation used for constants of that
type
- Determine the set of operations defined for Integers and give the
signature for these operations and syntactic representation
- Determine if any of the operation symbols defined for integers may
be overloaded
- Determine whether static or dynamic type checking is used to
determine the validity of each operation.
- Do exercise 1 for floating point data type
- Do exercise 1 and 2 for your own language
- 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.
- Does the language provide dynamic checking or leave it unchecked
at runtime?
- Are there other constructs you can think of?
- What about the language you are designing?
- Do Sebesta exercise 13 on page 288 (rather than write, discuss with
your group)
- Do Sebesta exercise 14 on page 288.
- Do Sebesta exercise 15 on page 288.
- 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?
- Do Sebesta exercise 9 on page 288.