Recitation R2 - Scanners, Parsing, Pre- and Post- Conditions and Grammars
Fall 2014

CS200: Introduction to Algorithms


The goals of this lab are as follows:

The Scanner Class and String Parsing.

The Scanner class does some low-level parsing. It can give you many different things, including tokens, lines, integers, reals, etc. (p.s. what are these?)

Create a new project in eclipse titled "R2".
Import Parse.java into the src directory of your eclipse project.
This class parses simple prefix expressions where (* , + , - , \) are the only legal operators and (a , b , c) are the only legal operands.
For an example (* a b) is legal while (* a b c) is not legal.
Modify this code so that the only legal operands are any integer.
Thus, (* a b) is no longer a legal. (* 10 3) will now be legal and (* 10 3 2) will be illegal.


Pre- and Post- Conditions

These are conditions that apply to running a method or a code segment.
The precondition tells users what must be true before they call a method. The post-condition tells users what will be true after they call the method.
These conditions may be "true" meaning that there is no meaningful condition that applies (true is always true).
For example, System.out.println(String s) might have as its precondition that there must be a console to print to, and its post-condition might be that s has been printed.

In Parse.java leave a comment at the top of the "ID(String indent)" method that describes the pre- and post- conditions of this method.


Discreet Math: Grammars

The TA will now go over a couple exercises on the board from this PDF file. Afterwards go over the additional exercises on your own.
© 2014 CS200 Colorado State University. All Rights Reserved.