Colorize Programming Assignment
CSSE 220
Correctness: 120 points       Style: 40 points

This is an individual assignment. You may get help with design and debugging from other people, but the code that you submit should be yours.

I suggest that you quickly read this entire document once to get an overview, then read it again slowly a couple of times to get the details.

Learning/Experience Objectives

Overview

From using Eclipse, you have seen that displaying different features of a pogram in different colors can make the program easier to read.

You are to write a Java application that reads a Java source code file and outputs an HTML file that (when viewed in a web browser)

For example:
 
// Opening comment.  Note that a "string" is ignored here because it is inside a comment. 
class /* Bad name */  Stupid { int x;
 String t = "A string with a /* in it";
 String p = "A string with a \" in it";
 boolean b = t.compareTo(p) < 0;

 public static void main(String [] args) {
   System.out.println("" + t + " " + p);
   System.out.println("Can you think of other interesting cases that your program should handle?");
 }
 /* Notice that comments /* do not "nest" in Java // */  
}

It is also important that you write your program in such a way that no possible input can cause the program to get into an infinite loop. The "Major Hint" below may help you to avoid that pitfall.

Learning HTML

You do not have to become an HTML expert in order to do this problem. The Stupid.html   file has examples of the small number of HTML tags that you need to know to complete this assignment. To see the code, either open the file in an editor (like WordPad) or open it in a web browser and choose View Page Source from the browser's menu. Pay special attention to the HTML code that generates the "less than" sign.

Your Program's Interface to the Rest of the World

Your Java application should expect one command-line argument, which will be a filename without the extension at the end. If the argument is XYZ, the program will read the file XYZ.java and create the file XYZ.html. For example,
      java Colorize MyClass
reads the input file MyClass.java, and produces the output file MyClass.html.

The testcases.zip file contains some Java source files that you can use to test your program.

It is important that your program should not use any graphical user interface objects, such as those in java.awt or  javax.swing. I will compile and run everyone's programs with a script, and your program will break that script if you use classes like JFrame, JOptionPane, JWindow, etc.

If you do not know how to tell Eclipse to use command-line arguments, see CommandLineArgumentsInEclipse.doc

Getting Started

A straightforward way to begin this program in Eclipse is to create a new project. Then add a Colorize class (specify that it should contain the main method) to the project, and other classes (if any) that you may need.

Hint on Recognizing Keywords in Your Program

All Java keywords contain only lowercase letters. When you see a lowercase letter, begin saving the letters in a string variable. When you get to the first non-letter, check to see if your saved string matches one of the keywords. If so, output the "word" in blue, otherwise output it in black. The declaration and code in the keywords.txt file may be helpful here. Of course, you should not colorize any keywords that are inside a comment or a string constant.

Major Hint

I strongly suggest that the main part of your code be a loop of the form "read a character, process that character". If you try to use nested loops or try to read and process multiple characters in a single time through the loop, it can get very difficult and involve many special cases.

The following code illustrates the process:

For another approach to input (one that predates the Scanner class, which was added to Java i nversion 5), see Lines 21-31 on page 56 or lines 12-13 and 21-34 on page 42 of the Weiss 3rd edition textbook.

Generating Proper HTML Code

A proper simple HTML file begins with <html> and ends with </html>. The actual program text, etc. to be displayed should come between <body> and </body> tags, My script looks specifically for those <body> and </body> tags, and only puts into the Summary.html file the part of your output that falls between those tags. Thus you must include them.

Suggestion

I suggest developing and enhancing this program incrementally, doing the most basic and easiest parts first. First, plan your program framework (mainly this means implementing a basic FSM) and get colorized comments working. Then add new FSM states for colorizing strings. Finally, add the mechanism for recognizing and colorizing keywords. Most of the correctness credit will be for colorizing comments and strings. Including colorized keywords is more difficult; can you see why?

Bounty for Good Test Files

If you post on the Colorize discussion forum Java source program to colorize that tests an interesting aspect of this program that is not tested by any of my sample files, I will give you a few extra points for this assignment, provided that you do it so I can post it at least 48 hours before the assignment is due..

Discussion Forum

There is an ANGEL discussion forum for this assignment. That is the best place to ask questions about this assignment. If you send me email with questions about the assignment, I may answer via that discussion forum, so that other students can read the answer also.

Useful Information Sources

In class, we will introduce Finite State Machines, begin drawing a FSM diagram for the colorizer, and discuss possible approaches to FSM implementation. Here are some more resources that you may find helpful:

 

 

Turnin and Grading Script Info

There is a folder in your CSSE 220 turnin folder on AFS called Colorize (/class/cs/csse220/csse220-200810/turnin/your-username/Colorize). In this folder, place your Colorize.java file and any other Java source files that it needs. Please do not place any other files in your Colorize folder.  For example, no project-related files, no .classpath files, no folders, etc. 

You can run the same script that we will run to test your program (we may use some different Java source files as input to your Colorize program, but the way we will call it will be the same).    In fact, you should try that grading script, so you can be sure that your program's interface is correct and that it works with our test files. Note also that you can also view a preliminary version of the grading checklist that we will use.

First, let me encourage you to try the mechanics of using the test script as soon as you have Java code that compiles and produces legitimate HTML output, whether or not it is completely correct output for this assignment. If you put off experimenting with running the script, you may end up having trouble at a time when you do not have anyone to ask. If you do have trouble getting the test script to work for you, I suggest that you go to my office or to the assistants' lab hours as soon as you can.

What the script is supposed to accomplish

First it will compile your program.  If that is successful, is executes your program with my test cases, and collects the results into a file called Summary.html. When it runs your program, any output that would normally go to the screen is captured in files that you can view. Then all of  these output files are collected into the Summary.html file so the grader can see them all at once.. 

Running the script

0. Wait for me to announce that the script is ready tio use.
1. Turn in your code, as described above assignment.
2. Using SecureCRT or some other ssh program, log in to addiator.rose-hulman.edu (use your Kerberos username and password)
3. Issue the following two commands:
   cd  /class/csse/csse220/csse220-200810      (be sure to use forward slashes)
   ./check  Colorize                           (be sure to include the period at the beginning)

What next?

If you do the above steps correctly and your program produces valid HTML files, the script will create extract and Results folders, and place a Summary.html file in the Results folder. This file will contain everything that appears between the <body> and </body> tags in your program's output files.

Problems with figuring out how to do the turnin?

See the instructor or the student assistants, post to the discussion forum, ask someone else in the class, or ask someone who has taken CSSE 230 recently.