The main purpose of this assignment is to introduce you to Eclipse, an integrated development environment (IDE) used mostly to write Java applications. The secondary purpose is to give you some hands-on experience with debugging applications.
All subsequent assignments in this course will require you to read, write, and modify
Java code; thus, it is imperative that you learn right from the start how to properly organize Java files and how to debug erroneous Java code.
to provide interactivity. This programming language includes a rich set of features, designed in part to simplify its interaction with the Document Object Model (DOM), which
is a tree-like structure representing the elements found in a webpage.
defining the syntax of the language. Throughout this course, you will be developing a
Preliminaries: Background on Lexing
Lexing is the process of generating tokens when compiling or interpreting code. These
tokens must be generated in order for code to be parsed and, eventually, compiled/executed. Tokens, in essence, are numerical identifiers representing symbols that are
x = foo(a,b);
When the above JS code is lexed, the tokens generated will be as follows:
Note that ASSIGN refers to the “=” (i.e., assignment operation), LP refers to the left
parenthesis, RP refers to the right parenthesis, and SEMI refers to the semicolon. In addition, variables and function names are identifiers, and are assigned the token NAME.
This program, which generates tokens as described above, will contain four bugs. Your
task is to identify these four bugs using Eclipse debugging techniques and fix the token
stream generator code.
1. Download and install Eclipse at http://www.eclipse.org/downloads/
2. Read the Eclipse tutorial (Lab 1). The tutorial can be found in the course website.
This tutorial will teach you the basics of organizing Java packages in Eclipse, as well
as debugging in Eclipse.
3. Download the file eece310_assn1.zip. Once you’ve unzipped the file, add the folder
eece310_assn1 as a project to Eclipse. (see “How to Add Existing Projects to Eclipse”
in the tutorial)
4. Once you have set up the Eclipse project browse the code. To this end you can click
on the triangle beside the project name under the “Package explorer” pane to expand
name (e.g., Token.ADD, Token.ASSIGN, etc.) rather than by number.
Kit.java: For the purpose of this assignment, this is a helper class containing functions
that will assist in the lexing.
ObjToIntMap.java: For the purpose of this assignment, this class helps us associate the
NAME token with its corresponding identifier name (i.e., variable name or function
UniqueTag.java: This is a helper class to ObjToIntMap containing tags for special object values.
TokenStream.java (Note: this is the only class you’ll have to modify for this assignment). This class is where the lexing takes place. When a new TokenStream object
member of the TokenStream class). Once the TokenStream object is created, each call
above, the first call to getToken() generates the token NAME, the second call generates
the token ASSIGN, the third call generates NAME, the fourth call generates LP, etc.
How does getToken() know what the next token is? The answer is that it parses the
any combination of characters forms a syntactically meaningful symbol. For instance, if
the character ‘+’ is encountered, getToken() first peeks at the next character. If the next
character is another ‘+’, then an increment operator (i.e., ++), represented by token INC,
is returned. If the next character is a ‘=’, then an addition assignment operator (i.e., +=),
represented by token ASSIGN_ADD, is returned. Otherwise, no meaningful symbol
goes with the ‘+’ character, so an addition operator, represented by token ADD, is returned.
Identifiers and numbers are also identified character by character; however, they are a
little trickier to lex. It is your task to read through the TokenStream.java code and try to
understand how these are lexed.
GenerateTokenStream.java: This class contains the main function, which creates a TokenStream object, calls getToken() repeatedly in a loop to generate tokens one by one,
and prints the generated tokens to standard output. When the main function is run, you
exception will be thrown. This is caused by one of the bugs introduced in TokenStream.-
Please note that only TokenStream.java contains bugs. As a result, only TokenStream.java should be modified, and all other files should remain unchanged.
You will submit only your corrected version of TokenStream.java. We will test your code
on the following inputs:
The first three inputs (and their corresponding outputs) are made available to you, but
the fourth input is not. If you have identified and corrected the bugs properly, your code
will generate the correct tokens for all four inputs.
one of the bugs.
Your mark will be based on the correctness of your code, as follows:
Create a zip file (with extension .zip) containing only your modified code for TokenStream.java (i.e., the zip file should not contain code for other classes). Submit the zip
file as mentioned in the email guidelines.