CS355

Fall 2003

Assignment 1

Due: 10/2/2003

Files required for this assignment are found in ~zeil/cs355/Assignments/Asst1, or via anonymous ftp at ftp.cs.odu.edu at /pub/zeil/cs355/Assignments/Asst1.

Questions on Regular Expressions

/usr/dict/words on most, if not all Unix systems, is a file containing a listing of words, one per line, used as a "dictionary" for spell checker programs and the like.

"egrep" is a Unix command that scans text files for lines containing a string satisfying a regular expression.  For example,

egrep 't(h|r)' /usr/dict/words
would list all words containing a 't' that is followed by either an 'h' or an 'r'.

Read the man page on egrep and on regexp (i.e., use the commands "man egrep" and "man regexp"). Then answer the following (you can check your answers by actually running egrep, of course):

  1. I'm enchanted with my own initials. What egrep command would list all words containing an (upper or lowercase) 's' somewhere in he word, followed by an (upper or lowercase) 'z', possibly with other letters in between?
  2. Suppose that you were working a crossword puzzle and discovered that you needed a 6-letter word beginning with 'r' and with 'i' as the next to last letter. (Again, both upper and lowercase are acceptable.)
  3. You're playing a wordgame (e.g., Scrabble) and have drawn the letter 'q' but do not have a 'u' to go with it. You remember having learned that 'u' always follows 'q' in the English language, but you suspect that, as woth so much else in the language, there may be exceptions. What egrep command would list words containg an (upper or lowercase) 'q' without a 'u' immediately after?

Answer the above questions in files q1.txt, q2.txt, q3.txt, each containing a single line that, if typed in at a Unix console, would run the egrep command. For example,

egrep 'your*Regular+Expression' /usr/dict/words

[Hint: to match an entire word rather than portions of a word, your regular expression must begin with ^ and end with $.]

Questions on Grammars

dgl is a program that reads grammars and produces programs that emit randomly selected strings chosen from the language described by that grammar. For example,

 ~zeil/bin/dgl < functions.dgl >! functions.c
 gcc -o functions functions.c -lm

will produce a program named functions that, when run, spits out C-style function calls (e.g., f(x), g(f(x), z), etc.). dgl is intended for use in generating test data that matches the expected input format of a program under development. The dgl manual is available here. [Only sections 1-5 and 9 are relevant to this assignment.When compiling , you may get some warnings about nrand48. Ignore them.]

  1. Add productions to the file real.dgl to produce a grammar for real numbers (no leading +/- signs or trailing power-of-10 notation) that accepts numbers like 1.012, 3.14159, 0.5, .5, 52., etc. In other words, either the integer portion or the decimal portion, but not both, may be empty.
  2. Add productions to the file timerange.dgl to produce a grammar for expressing ranges of time in the format H:M-H:MC, where H is an integer from 1-12, M is a 2-digit integer, evenly divisible by 5, I nthe range 00-55, and C is either AM or PM. An example would be 12:20-2:05AM
  3. Add productions to the file courselisting.dgl to randomly generate reports like the following:
    Art
       35779        039     M       12:55-2:25AM      Practicum
       66792        541     MWF     9:55-1:00PM       Social Implications
    
    Computer Science
       69411        364     MWF     3:35-2:00AM       Introduction for Majors
    
    English
       78373        443     F       9:30-1:25PM       Intermediate Topics
       09911        103     MWF     2:15-10:55PM      Intermediate Topics
       84460        995     MWF     2:45-6:00PM       Social Implications
    
    [The columns in this report are separated by single tab '\t' characters.]

    Note that your grammar from question 5 will become a portion of your answer to this question.

Submitting Your Work

The button below will allow you to submit your solution, either from your Unix account or from whatever machine is running your web browser. Shortly after submitting, you will receive an email with a preliminary grade for the assignment. You may, if you wish, make corrections and resubmit, without penalty, up until the due date of the program.

You may also, from the pages accessed by that button, view my solution to the assignment (once the due date is past).