Lab 3: Grammars

Typing your grammar

Your Prelab is going to be extremely important for this lab session. The goal of this lab is to create your own original grammar and verify its correctness through the neat Random Sentence Generator program (aka RSG).

The first thing that you will need to do is to type your prelab grammar. Open up Eclipse. In your public_html/cps1 directory, create a directory called lab3 for storing new files related to this lab. Your grammar should be saved in a file named grammar.g in the directory you just created, public_html/cps1/lab3. The .g in your filename indicates that your file is a grammar file. Open Notepad, Eclipse, or your favorite text editor and type in your grammar.

A few notes regarding style and formatting when typing your grammar:

When you are done typing your grammar please remember to save it. From Notepad, you need to save it into your P: drive under your /cps001/lab3 directory as grammar.g. You need to select "All Files" from the "Save as type:" menu to ensure your file extension is correct.

A note on file types and file extensions: A file type is indicated by its extension. The extension on a file name can be used to identify a program the file is associated with. Association is your computer's way of telling which programs are to be used to open which types of files. For example, a file with a .doc extension can be opened and read by Microsoft Word, and a file with a .pdf extension can be opened and read by Adobe Acrobat. These are sometimes referred to as registered or reserved file types. If you try to open files with .doc or .pdf extensions in a text editor such as Notepad, you'll just see a bunch of crazy symbols interspersed with text - these symbols are actually instructions for the associated program on how to read and display the file. File extensions can also be user-defined. User-defined extensions are generally based on the file's name or content. Your grammar file is really nothing more than a text file. The .g extension is purely for your convenience to remind yourself that the information in grammar.g is a grammar rather than generic text.

Testing your grammar

Now that your grammar is in the computer, you can test its correctness with the nifty RSG program provided for you. You will find it here: Random Sentence Generator.

This page has enables a user to upload and run a grammar. There are two versions on this page, a standard version and a debugging version. The standard version just shows the results of expanding the grammar. The debugging program tells you how your grammar was read in and exactly how the recursive sentence generator generated a sentence from the given grammar. This version is particularly useful if you are having any trouble with your grammar. You should try the debugging version out first. Then, once you are confident you understand how the sentence generation works and that your grammar is being parsed correctly, you can use the standard version.

Incentive!

Do a great job on your grammar, and you could win the grammar contest! In each lab section, your TAa will select one outstanding grammar, based on effort, originality, and creativity. Next week in class you get to see the five top grammars and vote on the one you like the best. The winner will be awarded with extra credit.

Submitting

Submit your grammar.g file using Eclispe. See the Ambient submit instructions. You should submit under class cps001, assignment name lab3.


Jeff Forbes
Last modified: Mon Sep 19 13:18:10 EDT 2005