Informatics 42 • Winter 2008 • David G. Kay • UC Irvine
Lab Assignment C
This assignment is due at the end of lab on Wednesday, February 20.
The problem: Complete Alex Thornton's version of the ICS 22 lab assignment, "Signal to Noise," available at http://www.ics.uci.edu/~thornton/ics22/LabManual/SignalToNoise/. You'll write a program that reads a grammar and generates a specified number of sentences using this grammar. Before you work on your own program, you can get a broader idea of what's possible by trying out the applet at http://www-cs-faculty.stanford.edu/~zelenski/rsg. The "Extension Request" grammar (the default) is pretty funny; also try out "CS assignment," "Programming bug," and "Math expression," along with any others that strike your fancy. Then follow the "Directory of the collected grammar files" link at the bottom of the page. For an idea of your program's possible input, pick some of those grammars to look at; "Math expression" is the easiest to follow. (There may be slight differences in grammar format between what's shown here and Alex's assignment; follow the assignment in that case.)
Entertainment isn't the only application of this program. Sometimes we need to test our software with a lot of data, more than we can conveniently generate by hand. With a program like this, we only need to create a grammar describing our test data an we can produce as much as we want.
Take note of these three additions/enhancements/clarifications to Alex's writeup:
When you face a program like this one (or the one you wrote in the last lab assignment), it's important to take it in stages. It's a bad idea to try to work on everything at once, nor is it a good practice to wait until you think you've got everything working before you start running and testing your program. One of the skills that you will begin to develop as you work on ever-larger programs is the ability to carve up a large program into smaller pieces that can be tested individually.
As you work on this lab assignment, consider working on it in the following stages.
Rule
variable: program
RightHandSide
variable: statement
terminal: NL
terminal: .
terminal: NL
RightHandSide
variable: statement
terminal: NL
variable: program
...
RightHandSide
variable: statement
terminal: NL
variable: program
Rule
variable: statement
RightHandSide
terminal: LET
variable: variableName
variable: number
...
Don't feel that you have to get the output looking exactly like what you see above; in particular, don't worry about spacing it the way I did, unless you're inclined. Ultimately, you'll take out the code that writes this test output. It might feel downright wrong to write code that you intend to throw away, but this is a valuable technique, because it is one way to ensure that one part of your program works without depending on the others. When your program can write output like the example above for any input file, you know that you're done dealing with reading from the input file, and you can move on safely to the next stage.System.out.println(grammar);Your output can look much like the output that you wrote previously, but instead of testing the parsing of the input file, you'll be testing whether you've built up the objects representing the grammar correctly.
Submit your own grammar files along with your code. Aside from that, the usual warnings, advice, policies, and practices apply to this assignment:
Written by David G. Kay, Winter 2005; modified by Alex Thornton, Winter 2007, and by David G. Kay, Winter 2008.