Compilers (CS362 2002F)

Type Checking a Simple Language

Warning! This lab is less polished than most!


Summary: In today's lab, you will experiment with a simple type checker that I've written for your edification. I hope that this lab and the related code will help you think about the design of your parser, your parse trees, your type checker, and other tree walker.

Collaboration: Feel free to work on this lab in pairs or trios.

Turning It In: You don't need to bother turning in this lab.

Grading: Since you're not turning in the lab, I won't grade it.


Since Pascal is a fairly big language, at times in the construction of a compiler or the consideration of pieces, it's worthwhile working with smaller pieces of the language. For the problem of type checking, two key program parts are the declarations and assignment statements.

I've designed a simple language that consists only of declarations and assignment statements. You can find the formal definition of the syntax of the language in the file in the assignment below. In essence, a program looks something like

  id1,id2,id3: type;
  id4,id5: type;
  id := exp;
  id := exp;


a. Make sure that /home/rebelsky/Web/Courses/CS362/2002F/Examples is in your classpath. The easiest way to do so is

export CLASSPATH=".:/home/rebelsky/Web/Courses/CS362/2002F/Examples:


export CLASSPATH="/home/rebelsky/Web/Courses/CS362/2002F/Examples:$CLASSPATH"

b. Make a copy of the directory /home/rebelsky/Web/Courses/CS362/2002F/Examples/TypeCheck. In that directory you will find some Java programs and some al programs.

c. Read to ensure that you understand the syntax of the language.

d. Run TestAL on the sample programs (and a few of your own) to ensure that you understand what the parse trees I build look like.


1. Given your understanding of the Assignment Language, make a list of the kinds of type errors that might occur in programs.

2. Uncomment the instructions to type check in TestAL and recompile. See what kinds of errors the type checker currently catches.

3. Look at to see what kinds of errors the checker is intended to catch.

4. Make catch more errors (you can choose which other ones to catch). For example, you might check whether a variable is defined before being used or you might handle expressions that involve operations.

5. Make permit the assignment of reals to integers.



Tuesday, 29 October 2002 [Samuel A. Rebelsky]

  • Created.


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 10 08:53:32 2002.
The source to the document was last modified on Tue Oct 29 14:04:23 2002.
This document may be found at

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Glimmer Labs: The Grinnell Laboratory for Interactive Multimedia Experimentation & Research