CS 153: Concepts of Compiler Design
Fall Semester 2009
Department of
Instructor: Ron Mak
Assignment #1
|
Assigned: |
Tuesday, August 25 |
|
Due: |
Tuesday, September 1
at 11:59 pm |
|
|
Individual
assignment, 100 points max |
Write a Pascal program
The purpose of this
assignment is to give you a crash course in Pascal programming. It is important
for you to be familiar with Pascal because the source programs for our
interpreter and compiler will be written in that language. (For your team
compiler project, you can choose a different source language.)
Pascal has a
relatively simple syntax, but it is a powerful procedure-oriented language. It
was popular during the mid-1970s through the 1980s as a teaching language. If
you had taken Introduction to Programming during that period, the language you
learned would most likely have been Pascal. The original version of Pascal,
which the booklets Essentials of Pascal I
and II describe, was not object-oriented, unlike later versions of the
language and its descendants.
For this assignment,
write a Pascal program named EmployeeListing that prints a sorted employee listing from data read in
from a text file. Here’s an input file that your program must process:
1234:P:Jones:Mary
3052:X:Smith:Tom
5886:Y:Lowe:Marie-Antoinette
2912:B:
4040:H:Schlesinger:Frank
7023:E:von Braun:William
6273:C:Thomas:Leslie
Each line of input
contains four fields separated by a : character:
Note that the first
name is not followed by a : character.
From this input file,
your program should produce an output listing similar to:
Id: 1234
Job code: P
Last name: Jones
First name: Mary
Profession: scientist
Id: 2912
Job code: B
Last name:
First name: Wendy
Profession: scientist
Id: 3052
Job code: X
Last name: Smith
First name: Tom
Profession: unknown
Id: 4040
Job code: H
Last name: Schlesinge
First name: Frank
Profession: teacher
Id: 5886
Job code: Y
Last name: Lowe
First name: Marie-Anto
Profession: unknown
Id: 6273
Job code: C
Last name: Thomas
First name: Leslie
Profession: scientist
Id: 7023
Job code: E
Last name: von Braun
First name: William
Profession: teacher
7 employees read.
Note that your
program must sort the employees by id for printing, and that your program must
limit each first and last name to 10 characters (although it must be able to read
longer names). The program figures out each employee’s profession based on the
job code:
|
Profession |
Job codes |
|
scientist |
B C P |
|
teacher |
E H U |
|
unknown |
any other letter |
To make sure that you
exercise some of the key features of Pascal, you must use the following:
Other than these
requirements, keep your program simple! Remember the purpose is to learn
Pascal, not to show off your data structures and algorithms skills.
Text input hints:
What to
turn in
E-mail your two files
as attachments to mak@cs.sjsu.edu
by the due date and time. Do not e-mail any executable files because some
mailers will reject the entire message. In the subject line, please include the
label ASSIGNMENT #1.
The Free
Pascal compiler
To do your
assignment, you can use the open-source Free Pascal compiler, which you
download from http://www.freepascal.org/.
Besides the compiler that generates executable code for various platforms
(Windows, Linux, Mac OS X), it comes with a clunky character-based screen
editor. If you’re more adventurous, you can try Lazarus (http://www.lazarus.freepascal.org/)
which has a friendlier GUI-based development environment, but it assumes that
you know a more advanced version of Pascal.