ICS 142: Compilers and Interpreters
Summer Session II, August 6 September 12, 2001
Homework Assignments
As part of your homework assignments, you will construct an interpreter
and compiler for Simple, the
simple imperative
language example.
While the assignments are available above, we will provide some notes
and hints on the project parts here.
General Instructions
Short Version:
We need all your sources, excluding standard libraries.
We need a file called "sc" that accepts one command line
parameter, the file to be processed.
We need either a Makefile or a script "mksc"
that performs the compilation from your sources to an executable program
we can run using "sc".
We need all this printed, as well as sent to the
email address listed on the handout in the form
of a tar archive compressed with
gzip; the archive should be named
"sc-studentid.tar.gz" and create a directory
"sc-studentid" with everything
in it (studentid should be your eight digit
UCI student ID number).
Long Version:
-
Your programs have to run on the ICS department's SunOS 5
workstations.
To make your life easy, you should develop on these workstations
as well.
If you don't know how to work on a Unix system, you should
start learning about it right away; many of the following terms
refer specifically to Unix.
You can work on these machines remotely using telnet or
ssh.
-
If you can not work on these machines for some reason, your best
bet is to use Java on your personal computer.
Avoid libraries (and language extensions) not available in the
standard JDK (i.e. don't use Apple, Microsoft, or other
vendor-specific libraries or extensions in your code).
-
You may use Java, C, or C++ to implement your programming assignments,
nothing else.
The only exception is Python, and assignments using that language will
be graded by the instructor, not the assistants.
-
Your program should always be named "sc" so that we can run it
within our automated grading system.
If your program needs a special environment, please write a shell
script "sc" that performs the required setup and then runs the
"real" program.
A simple script for Java is included as part of the solutions for
assignment 1, available on the Downloads
page.
-
You have to include a Makefile (if you know how to write one) or a
script that executes the compilation steps you did to get from your
sources to your executable.
Writing such a script is easy, since you just put the same commands
you use all the time during development (e.g. javac, cc, ...) in one
file.
If you include a script and not a Makefile, call that script "mksc".
-
Your program should accept one command line parameter which is
the name of the file to be processed; the required output (described
on the particular assignment) should be made on the standard
output.
The exception is the final assignment in which
error messages go to the standard output but you create an object
file "sc.out" in the current directory.
-
Starting with assignment 2, you have to hand in a printed copy of
your source code as well. Please make sure that you include all
relevant information (name, student-id, who you collaborated with, etc.)
in the header of each source file.
-
Send the source code for your programs to the email address indicated
on the particular assignment in the form of a tar archive compressed
with gzip.
Make sure that extracting this archive creates a directory
"sc-studentid" that contains everything needed to run
your program, especially the "sc" file referred to above and
a Makefile or "mksc" file for building your program.
Of course, studentid should be your
eight-digit student id number!
Use the subject "ICS 142: Assignment x" where x
is the number of the assignment.
-
Note that we will take off points for everything
we have to do in addition to extracting, running, and comparing the
results produced by your program.
Assignment 1: A Scanner for Simple
-
Peter: The "@" sign in the example output just
indicates that the following is the position of the token. Similarly,
the brackets "<" and ">" indicate that everything between them is
the value associated with a token of that kind. This is really just
a formatting issue.
-
Peter: To find out the keywords you have to
recognize, look at the grammar. If it's in there, and if it's
in quotation marks, then it probably is a keyword (or a symbol
like ":=" for that matter). If you can't find something in the
grammar, it's not a keyword (or symbol)!
-
Peter: The position should be the position from
the beginning of the file (or string), not from the beginning of
the line. Remember that we ignore linefeeds as whitespace, just like
blanks or tabs. BTW, ignoring one TAB character just advances the
position by one!
-
Peter: Test your scanner with the example given
on the assignment. Once that works, test it with
this file which should produce
this output. Use "Save as..." to
get these files, otherwise something might get lost!
-
Peter:
For exercise 1, when I say "no abbreviations" I mean that you can
not use "|" for alternatives, "[]" for optional, etc. If you
believe the solution requires recursion, you are on the right
track.
-
Peter:
We will use the command sc our-test-file to run your
programs. If you hand in a C/C++ solution, just call your
program "sc" and you are fine. If you hand in a Java program,
just include a short script like this
with suitable modifications for your main class.
-
Peter:
If you generate tokens individually in your scanner, you don't
have to assemble them into a list in the driver program. Just
print them! Try to come close to the output used on the (updated)
homework assignment and in the test file from above. You don't
have to match it 100% though.
-
Peter:
You can download solutions for homework 1 either in
Java or in
Python. These
are provided with no guarantee for
correctness, so make sure they work before you use them!
If you find a bug, please contact the author listed in the sources. Thanks!
Assignment 2: A Parser for Simple
-
Peter:
Here are a couple of test cases for the parser. As before, please get
these with "Save as.." just to be sure you have the same files:
Program 1
Output 1
Program 2
Output 2
Program 3
Output 3
Please note that I did not prove my parser correct, so there might be
a bug in one of these...
Assignment 3: The Simple Intermediate Representation
-
Peter:
Note that you are not required to handle semantic errors "elegantly"
in any way, you can still just abort with an error message when you
find one.
-
Peter:
Here is a first bunch of test cases, mostly for the symbol table
but also for constant expressions. As before, please get
these with "Save as.." just to be sure you have the same files:
Program 1
Output 1
Program 2
Output 2
Program 3
Output 3
Program 4
Output 4
Again, please note that I did not prove my program correct, so
there might be a bug in one of these. Also, please don't try to
match my output perfectly since it depends on my particular data
structures. As long as you show "essentially" the same thing,
details really don't matter. Only if we can't tell at all that
you are doing it right, that might be troublesome...
-
Peter:
More test cases, also for instructions and all that. You know the
drill, get these with "Save as.." just to be sure you have the
same files:
Program 5
Output 5
Program 6
Output 6
Program 7
Output 7
Program 8
Output 8
All notes from a above and all disclaimers apply, as usual.
Enjoy!
Assignment 4: An Interpreter for Simple
- No notes available, check the mailing list archive.
Assignment 5: A Code Generator for Simple
-
Here is a bunch of
example programs
written in Simple, together with the object files produced
by Joe's compiler.
If there is time I will also post the output by my compiler,
but let's see.
The code you generate does not have to look exactly like this,
but it has to do the same things.
As always, there is no guarantee for correctness.
(Note that the file extension of these is ".sel" instead
of ".sim" for historical reasons...)
Copyright © 2001
Peter H. Fröhlich.
All rights reserved.
$Id: assignments.html,v 1.9 2002/01/08 18:50:02 phf Exp $
|
|