CSE 401, Winter 2014
Robert R. Henry
Due via dropbox Friday January 17th 2014
In this assignment you will be writing a number of Mini Java programs designed to test your Mini Java compiler. The goal is to have you think about what is in Mini Java, and become familiar with the Mini Java coding straight-jacket, and understand what each feature of the language does, and how it might be implemented. You’ll also learn how to run the makefile and the ant build mechanisms.
When writing the Mini Java compiler, we’ll be adding many small things to the pre-existing “bones” of the compiler. These bones are primarily the AST data structure, but include the lexer specification and the parser specification.
By writing test programs now, you are engaged in a slowed-down version of a process called “Test Driven Development” (aka TDD) http://en.wikipedia.org/wiki/Test_driven_development. You write the tests now, and then write the code in the Mini Java compiler needed to make the tests work. Eventually your tests will all work. You will have to rewrite or extend your tests as you go along, based on new information about the language, the compiler, or the way in which you are staging your extensions. I fully expect that you will have to rewrite some or all of these tests in the course of the quarter.
Our compiler is simple enough that there’s very little interaction between most of the extensions, and there is no cleverness or trickiness. Consequently, you can write a simple test for one extension more or less in isolation from tests for other extensions. Simple is good! If it works in a simple way, then we’ve built the compiler and runtime so that concatenation of simple things yields overall correct results. It may not be efficient, but that’s a non-goal. You can probably test many related things in the same test file, such as a single test file that tests all integer arithmetic operations.
Your tests should test things and output something that tells you what test was run, and whether or not the test passed or failed. Since our Mini Java program can only print integers (and eventually doubles), you’ll have to encode the test results in some stream of integers or doubles. Remember, since Mini Java is a subset of Java, you can rely on Java to give you the “known-good” expected answers.
Keep in mind some of the common coding errors you might make, or coding errors common when writing this kind of a compiler:
Together with your project partner, write about 20 small test programs, where a “small” program is 50 lines or (much) less long. The value of “20” is somewhat arbitrary.
You will write two kinds of test programs: one kind should compile and execute without errors. The second kind should contain compile-time or run-time error(s).
Most of these programs should compile and execute without errors. Here’s some examples:
The remainder of the test programs should contain semantic errors that your compiler or runtime should catch. (Lexical and syntactic errors are not that interesting for us.) Since your compiler and runtime will have neither error repair nor error recovery, only test one kind of thing in each of these “broken” programs. Some examples might be:
Write your test programs using the following file (and class) naming conventions:
For example, I might have a file named “cs401admin_correct_24.java”.
With this naming scheme we can combine all test files into a single massive test repository without fear of file naming collision.
Make an estimate (you will not be graded on you estimate!) now of what fraction of the lines of code in your compiler your test suite will execute. We’ll hopefully show you later in the quarter how to get this information from the Java RunTime, or from the C-runtime (eg, the Mini Java Runtime).
There is a top level Makefile that has rules to compile and run a Mini Java program in one of two different ways. Compiling with the regular Java system produces the “expect” output. Compiling with your Mini Java compiler produces the “actual” output. The goal is to have the “expect” output eventually match the “actual” output.
Suppose you put your tests into a subdirectory named “tests”. Suppose you have a test program named “cs401admin_correct_00.java”. The following invocation of “make” would run the Mini Java tool chain on this program:
make SAMPLEDIR=tests tests/cs401admin_correct_00.actual
would produce interesting files:
make SAMPLEDIR=tests tests/cs401admin_correct_00.expect
would produce these interesting files, plus others (take a look!):
make SAMPLEDIR=tests tests/cs401admin_correct_00.diff
would difference the expected and actual output. Ultimately, there should be none.
Since you don’t yet have a Mini Java compiler that implements a true subset of Java, you’ll have to wait a bit before you can difference the output of the two compilers.
The Mini Java project code you start with already has a number of test cases already in the directory SamplePrograms/SampleMiniJavaPrograms. There are programs to do:
But all of these “real” programs require that many small things already work.