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
AssignLangParser.java in the
assignment below. In essence, a program looks something like
var id1,id2,id3: type; id4,id5: type; begin id := exp; id := exp; end
a. Make sure that
is in your classpath. The easiest way to do so is
b. Make a copy of the directory
In that directory you will find some Java programs and some al programs.
AssignLangParser.java 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
AssignLangChecker.java to see what kinds of
errors the checker is intended to catch.
AssignLangChecker.java 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.
AssignLangChecker.java permit the assignment of
reals to integers.
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