CSCE 425/825 - Compiler Construction

CSCE 425/825
Course Home Page
Course Description
Calendar
Project Upload
Resources
Project
Java
ANTLR
JVM and ASM
Eclipse and Plugins

Type Checking

Exercises

  1. Give the type rules for:
    • for-statements;
    • new-expressions; and
    • array expressions.
  2. Assume you have a method int m(int,int) and construct the type proof for the program fragment:
             int x,y; 
             y = 2; 
             x = m(3,y)+1;
          
  3. Consider a scenario, where we extend SJ with a type real that also has a + operator.
    Furthermore, we want int values to be implicitly coerced into real values as needed.
    Explain the implications for the type checker.
  4. A radical extension of the ESJ type system would allow 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 ESJ syntax. Show that they a strictly more powerful than the standard type system.
    Do you like this new language?
  5. Study the code for type checking SJ programs.

Reading

  • Dragon, Chapter 6.1-6.5

Materials

Type Checking