CSCI 136 :: Spring 2021

Data Structures & Advanced Programming

Home | Schedule | Labs | Handouts | Links | CS@Williams

Lab 5: P.S. It's Just a Stack!

In this week's lab (described in Section 10.5 of Bailey) we will implement a small portion of the stack-based language Postscript, a language designed to describe graphical images. When you create a Postscript file or print to a PostScript printer, you actually create a file that contains a program written in this language. A printer or viewer interprets that program to render the image described by the file.

Pre-lab Task: Explore the Starter Code

For this lab, we provide you with several useful classes to serve as building blocks for your implementation. These starter files are well documented, but sometimes reading source code can be daunting. To help out, we will use the javadoc program to generate Javdoc-formatted webpages that we can use to get a handle on the ways these classes can fit into our lab program design.

To create Javadoc documentation from the files in your repository, we can use the javadoc program that is included with our Java installation. By default, javadoc will process the Javadoc-formatted comments in a source file and generate a series of webpages and resources in the current directory. We don't want to clutter our repositories, so we will tell Javadoc to place its output inside the javadoc/ folder that we have created. The command we suggest that you use is:

              $ javadoc -d javadoc/ *.java

Some notes on this command:

After you are done, you should see many new files in your javadoc/ directory:

          $ ls javadoc

            Interpreter.html         help-doc.html            package-tree.html
            Reader.html              index-all.html           resources
            SymbolTable.html         index.html               script-dir
            Token.html               member-search-index.js   script.js
            allclasses-index.html  search.js
            allpackages-index.html   overview-tree.html       stylesheet.css
            constant-values.html     package-search-index.js  system-properties.html
            deprecated-list.html type-search-index.js
            element-list             package-summary.html

If I want to view my newly created documentation, I would open the file index.html. This is the webpage that forms the "root" of my Javadoc websites. In macOS, I could use the open command:

          $ open javadoc/index.html

This will open the javadoc page for your Interpreter class. To see the javadocs for all four classes, try:

          $ open javadoc/allclasses-index.html

I can also use my browser of choice (e.g., Firefox, Chrome, Safari, Edge, etc.) to open that local file.

Before lab, please do the following:

Lab Assignment

Complete Laboratory Assignment 10.5, which begins on page 247 of Bailey (PDF excerpt here). We have provided additional notes below.

In addition, answer the following Questions from page 246 of your text in, and submit it with the rest of your code this week. Note that we have added additional text in italics below to help clarify the questions.

Helpful Notes

checkstyle requirements:

For this lab, we will be not be adding any new checkstyle rules to the set of rules that we have used in previous weeks. Last week we requested that you include Javadoc-style comments for each public method, and this week we are asking you to use the javadoc program to produce real Javadoc webpages. We hope that you generate these webpages using your comments in, and use the generated files to help you improve your documentation.

We STRONGLY ENCOURAGE you to run checkstyle early and often when developing your code, and try to program in a way that minimizes WARNING messages. The checkstyle rules that we use in this course are based on real-world style guides; internalizing good style practices will help us write more readable code.

In total, checkstyle will enforce the following guidelines:

To run checkstyle, you would type the following command at the terminal:

          $ ./checkstyle

The ./ is peculiar to Unix: it tells the terminal to look for the checkstyle program in the current directory. This command will run checkstyle on every Java program in your directory. To run checkstyle on a specific Java file, type:

          $ ./checkstyle

Lab Deliverables

For this lab, please submit the following:

If you worked with a partner, submit your collaborative solution in your shared repository.

As in all labs, you will be graded on design, documentation, style, and correctness. Be sure to document your program with appropriate comments, including class-level and method-level comments (with pre- and post-conditions where appropriate). Also use comments and descriptive variable names to clarify sections of the code which may not be clear to someone trying to understand it. The CS136 Style Guide may be helpful.

Whenever you see yourself duplicating functionality, consider moving that code to a helper method. There are several opportunities in this lab to simplify your code by using helper methods. Think carefully!

Submitting Your Lab

As you complete various milestones, you should commit your changes and push them. Commit early and often. When the deadline arrives, we will retrieve the latest version of your code. If you are confident that you are done, please include "Lab Submission" as the commit message for your final commit. If you later decide that you have more edits to make, it is OK. We will look at the latest commit before the deadline.

We will know that the files are yours because they are in your git repository. Do not include identifying information in the code that you submit. Our goal is to grade the programs anonymously to avoid any bias. However, in your file, please cite any sources of inspiration or collaboration (e.g., conversations with classmates). We take the honor code very seriously, and so should you. Please include the statement "I am the sole author of the work in this repository." In the comments at the top your file.

Late Days

Remember that if‐for any reason‐you will be submitting your lab beyond submission deadline, you'll need to fill out the Late Lab Form. That form contains a description of the late lab submission policy for the course