|
Assignment 1
|
|
|
Scanner
|
Due: October 2
|
Objectives
In this course you will be developing an interpreter for a high-level
language, called HL, which manipulates lists and strings.
In this assignment you will be using JavaCC to build HL's scanner.
This should familiarize you with the use of lexer generators
and the scanning process.
The
learning objectives
addressed in this assignment are
2Cc (which includes 2De), 2Ba, and 2Aa.
Preparation
Before you start your assignment, you will need to set up the environment under which you will be working.
You can develop your assignment on whatever platform you prefer.
However, we will only test it on the moons,
so you should verify your work on this platform before submitting it
to make that no technical problems will interfere with the assessment of your work.
Here is how you should prepare your environment on the moons:
- Create a directory where you will do your work, with a subdirectory called Tests.
- Copy all the files in the
Handouts directory
into your working directory.
These files are located on the moons at ~cps710/public_html/doc/F2024/A1/Handouts
and you can copy them into your current directory with the command:
cp ~cps710/public_html/doc/F2024/A1/Handouts/* .
cp ~cps710/public_html/doc/F2024/A1/Handouts/src/* .
Here are the files:
- A skeleton version of
HL.jj
that you can start your work with.
- Two files containing the main program for your assignment,
which is in the class TestHL.
This program is a fairly standard main program to test javacc scanners.
Do not modify the contents of these files as we will be using
the posted ones to test and grade your scanner.
Both files define the TestHL class:
- TestHLC.java
is for testing learning objective C only.
This file works properly when STRING tokens,
which are in the B learning objectives, are not yet implemented.
- TestHLB.java
is for testing all learning objectives.
It includes special code for STRING tokens.
- There is a third file,
TestHL.java
but it is just a copy of TestHLC.java which is the one that you
will need at the beginning of the assignment before you start implementing strings.
- The makefile that will be used to compile your program on the moons.
This is a minimal make file for the C learning objective.
It will need to be modified to support the additional files needed for the B learning objective.
You can learn about the make program
by typing "man make" on the moons or from the
GNU Make Manual.
- Two testing scripts,
t and
runtests.
They will be described in the Testing section below.
- Make the two testing scripts t and runtests executable by giving them user x perms.
This is done with the command:
chmod u+x t runtests
- Get rid of the two TestHL source files that you will not need at first
(you will be left with TestHL.java which is a copy of TestHLC.java):
rm TestHLC.java
rm TestHLB.java
- Compile everything once to make sure that your compilation settings are correct.
This is done with the command:
make
This will also generate additional files that you can modify later.
- Test that your program is running properly by typing
java -classpath . TestHL
and typing the strings "else" and "for".
Your development and testing environment on the moons is now ready.
If you wish to develop your program in a different environment,
you will need to also do something similar for that environment.
Assignment
Once you have set up the environment, and verified that it runs smoothly,
you can start your assignment.
If you are planning to implement the B learning objectives in this assignment,
then you will need to replace TestHL.java by TestHLB.java after you have implemented
STRING tokens:
cp ~cps710/public_html/doc/F2024/A1/Handouts/src/TestHLB.java ./TestHL.java
Testing your Assignment
As described in the preparation section, there are two possible TestHL programs for your assignment:
TestHLC.java which will be used to test submissions which only implement the C learning objective,
and TestHLB.java which will be used to test all other submissions.
To run your own tests, be sure to copy the appropriate one for your situation and rename it TestHL.java.
The testing files used to test your submissions are in the
Tests directory.
If you are doing your testing only on the moons, you do not need to copy these files
because the test scripts access them directly.
However, if you need to copy them for any reason,
the direct path on the moons of the Tests directory where you can retrieve them from is
~cps710/public_html/doc/F2024/A1/Tests
The test files have prefixes describing the learning objective tested.
Some learning objectives are tested with multiple files.
You can see the order in which the tests are run in
runtests.
Each test consists of two files, an .hl file for the input,
and a corresponding .expected file for the expected output
against which your output will be compared using the testing scripts:
-
runtests
runs all the tests for all learning objectives one by one using the t script.
If your submission only deals with the C learning objective,
then you should remove the tests for the B and A learning objectives
when you do your own testing.
- t is a script for running one test file.
As you can see in runtests, and in t itself, t takes one parameter ($1) which is the name of the test.
It
- runs your program on that test.
(Your java program files are assumed to be in the same directory as t and runtests)
- creates an output file for that test with a .out extension
in the Tests subdirectory of your working directory
- compares your output file with the expected output.
When your submission passes a test, all that will be printed is the test name.
Otherwise you will see the diff of your .out file with the .expected file for that test.
Submitting your Assignment
The name of the file that you submit will indicate to us which learning objectives to test,
so please follow the directions below carefully.
Once you have verified that your source does compile and run properly on the moons:
- If you are submitting work for the C learning objective only:
- zip up your
HL.jj file into a file called A1C.zip
You can do this on the moons, by simply typing
zip A1C HL.jj
- Submit electronically on the moons A1C.zip
Simply put, you can do this on the moons by typing
submit-cps710 A1C.zip
- Otherwise: (we will run all B and A tests):
- zip up your
HL.jj, Token.java, NumberToken.java, IdNumToken.java, IdSetToken.java, IdBoolToken.java and StringToken.java files into a file called A1A.zip
You can do this on the moons, by simply typing
zip A1A HL.jj Token.java NumberToken.java Id*Token.java StringToken.java
- Submit electronically on the moons A1A.zip
Simply put, you can do this on the moons by typing
submit-cps710 A1A.zip
References
- CPS710 Material
- Explanations
The following provide overviews of scanning with Javacc and are good places to get started because they have enough information to help you produce
a very basic JavaCC file that detects the simple tokens and skips whitespace.
- Main JavaCC site provides an overview of JavaCC.
-
JavaCC [tm]: TokenManager MiniTutorial
gives a good overview of how JavaCC handles tokens and how to write a JavaCC program.
- Wikibooks'
Compiler Construction also gives a
good overview: read the Lexical Analysis section.
The comment section will get you properly started with comments.
- Chapter 2 of the JavaCC textbook by Tom Copeland are quite thorough.
- Specific References
This page is maintained by
Sophie Quigley
(cps710@cs.torontomu.ca)
Last modified
Wednesday, 25-Sep-2024 11:14:09 EDT