See the assignment turn-in page (last modified on 14 January 2006) for instructions on turning in your assignment.
For this assignment, a regular expression is a sequence of items. Items otherwise unidentified in the syntax are copied as is:
An option item is a question mark followed by an item; it indicates that the item may or may not appear in strings:$ echo "a b c" | regexp-gen "a b c" $
Note that the question mark precedes the optional item rather than following it as is usually done. This is true for all the regular-expression operations.$ echo "a ? 1 b" | regexp-gen "a 1 b" "a b" $
A choice item is a bar followed by two items; it indicates that exactly one of the two items may appear in strings:
A repetition item is a star followed by an item; it indicates that zero, one or two copies of the item in succession may appear in strings:$ echo "a | 1 2 c" | regexp-gen "a 2 c" "a 1 c" $
Normally repetition generates infinitely many strings when applied to a non-empty item; quasi regular expressions restrict repetition to the three shortest strings.$ echo "a * 1 b" | regexp-gen a 1 b a 1 1 b a b $
Parentheses group a sequence of items into a single item:
Empty parenthesis and choice make option redundant:$ echo "a ( b ( c ) ) d" | regexp-gen a b c d $ echo "a ? ( b c ) d" | regexp-gen a b c d a d $ echo "a * ( b c ) d" | regexp-gen a b c d a b c b c d a d $ echo "a | b ( c d )" | regexp-gen a c d a b $
$ echo "a | b ( )" | regexp-gen a a b $
For parsing convenience, adjacent items have at least one space character
between them; a space character is any character for which
isspace()
returns true.
!
", an exclamation mark
followed by a space.
regexp-gen
is available in the class assignment directory
/export/home/class/cs-503/a1
. Remember the purpose of this assignment is to implement
a correct solution, not to copy the behavior of my solution. If my solution's
wrong and you copy the incorrect behavior, you're going to lose points.
You'll also find a simple testing script called tests
in the class
assignment directory. It's a text file so you can read it using more
(for
example) or your text editor.
When you run the garbage test, you might want to send the output to
/dev/null
like so:
This will keep your terminal from being corrupted.$ ./regexp-gen < regexp-gen > /dev/null
This page last modified on 14 January 2007. |
|