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 a xterm window. In your cps001 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, /cps001/lab3. The .g in your filename indicates that your file is a grammar file. Open Notepad (or your favorite text editor) and type in your grammar.
A few notes regarding style and formatting when typing your grammar:
Make sure you use the same format and style of
defining objects as in the examples. Correct style can be found here.
You cannot put periods next to angle brackets without a space between them. " >. " will not work. " > . " will work.
Refrain from using 'apostrophes' in your grammar. RSG does not seem to recognize them.
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.
Now that your grammar is in the computer, you can test its correctness with the nifty RSG program provided for you, courtesy of Professor Forbes. 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.
To use either, click on the "Browse" button. A window will pop up. From the "Look in:" menu click on the little down arrow and select the P: drive (your acpub account).
Now double click on the file named grammar.g. This will load your grammar file into the RSG program, and make the window disappear.
Click on the "Submit" button.
The RSG program should output sentences that come from your grammar (and that make sense). If there seems to be a problem, you probably need to debug your grammar. You can do this with debugging version of RSG at the bottom of the RSG program page.
Please test your grammar several times to make sure it is correct. The RSG program will output different sentences every time.
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 (one per section) and vote on the one you like the best. The winner will be awarded with extra credit.
Go to your xterm window. Your file should be named
grammar.g and should be saved in your directory (which you created at
the start of lab) /cps001/lab3. Before you try to submit, make
sure you are in the right directory and that the file is in that directory.
Go ahead and submit your grammar:
submit_cps001 lab3/sec# grammar.gRemember to replace # with your actual section number. Please make sure to submit your file to the right place! Also make sure to type in YOUR actual filename ... if you didn't call it grammar.g.