|
|
|
|
CSE 303 Homework 3
Due: Wednesday 1/23/08 11:59PM
Turnin: online - turnin instruction
FAQ
HW3 Q&A Wiki Page
Updated skeleton code for hw3D.c and hw3Dfsa.h.
(1/19/2008, 12:47AM)
If you hadn't yet fetched the code as of the post time of this update,
the instructions on this page have been changed so that you will be an updated
set of files by following them - no need to apply the patch. If you had already fetched them, follow the link for instructions.
Added a page describing finite state machines
and linked it from various places in this document. (1/19/2007 2:44AM)
Added a page explaining
what 'character,' 'word,' and 'line' mean,
in this assignment. (1/19/2007 3:00AM)
Overview
This assignment is an introduction to programming and "building"
(compiling and linking) C programs. There are rougly a million
things that can go wrong, even if all you're trying to do is
build a program you know works already. It is designed to be
a sequence of small steps. It is also designed so that you can
read, build, and run some working code before you have to try to
write, build, and run similar code yourself. The purpose of that
is to let you run into whichever problems you're going to run into
(and there are a billion, so it's hard to guess which ones you'll
see) in small steps, and to give you an example of how to do things
rather than requiring that you read rely solely on the sometimes difficult to
understand man pages and other documentation.
There are eight parts to the assignment. The first
is an exercise that tries to make clear what the C preprocessor
does. To really understand what it does, it's useful to keep in
mind that it is NOT (very) aware of what the C language is. The
exercise is intended to make that totally clear.
Name | Description | Status
| hw3-cPreprocessor | Explanation of the C preprocessor's function by example (plus a tiny introduction to "thinking like a Unix programmer"). | Deployed.
|
The remaining seven parts involve implementing
a sequence of programs that are very similar to the standard
Unix word count (wc - man wc) program.
(Note: hw3G takes a tiny step towards an implementation
of sed , an editor.)
Name | Description | Status
| hw3A | Straightforward implementation of word count that reads stdin only. | Skeletal - counts characters only.
| hw3B | hw3A, but the user names an input file on the command line. Character, word, and line counts for the contents of that file are printed. | Skeletal - like hw3A but with some C code hinting at how to implement the "reads from a file" modification. Contains debugging output code that should eventually be removed.
| hw3C | Implements a modified definition of word count - characters and words in C '//' style comments are ignored. | Unimplemented. Start from your working solution to hw3B.
| hw3D | A solution to basic word count structured as
a finite state machine. | Fully implemented and working.
Fully implemented and working in updated hw3D files.
| hw3E | hw3D modified to not count characters or words inside C '//' style comments. | Not implemented - just a copy of hw3D.
|
Another intention of this assignment is to show you the
finite state machine
approach to implementation, which can be very effective for some kinds of
problems (including this one). The two colors in the table above
group programs by solution style: yellow for "no particular style" and
green for "finite state machine".
There are two more parts.
Name | Description | Status
| hw3F | hw3E with the code broken into multiple source files. | Nothing - not even skeletal. Start with your solution to hw3E.
| hw3G | Performs the word count function, ignoring characters and words in '//' style comments, PLUS outputs the input text with those comments removed. | Nothing - not even skeletal. Start with anything you want.
|
Not Exactly Word Count
We ususally think of word count as counting the number
of characters, words, and lines in its input.
If you read the documentation closely, what it counts is the
number of characters, words, and newlines in its input.
We want to count the number of lines (e.g., that would appear
if the input file (assuming its a file) were displayed in emacs
in an infinitely wide window).
Getting Started
Get a "tar" of The Assignment Files
Copy the file /cse/courses/cse303/08wi/hw3DistV1.1.tar.gz
to the directory in which you want to create a directory that will
hold all the assignment files.
- If you're working in a shell running on attu, just say
cp /cse/courses/cse303/08wi/hw3DistV1.1.tar.gz .
- If your shell is runing on a lab Linux workstation, that
command may work as well. (I'm not sure whether or not that part of
the file system is "mounted" on lab Linux boxes.)
- From any shell, anywhere, you can do this:
scp yourattulogin@attu:/cse/courses/cse303/08wi/hw3DistV1.1.tar.gz .
Note the period at the ends of both of those commands.
(Note for cygwin
users: scp (and ssh) aren't installed by default with cygwin. If your
install doesn't have them, rerun setup.exe. Hit OK until you get to the
dialog box that is offering things to install. Hit the View button in the
upper right until you see an alphabetized list of all available packages.
Look for openssh (I think it is...). Click on the "Not Installed"
(I think it is -- all the way on the left) and it should change to a version number. Now hit OK and openssh should be installed, providing you with scp
and ssh commands.)
Check What untar'ing Will Do
Run the command:
tar tzf hw3DistV1.1.tar.gz
That will print the names of the files contained inside the tar file.
Those files, including directories, will be created when you untar in
the next step. Note that this tar file creates a directory in which
all of its files go. Not all tar files do that, so it's handy to check
before untar'ing so you don't end up with 1500 files in the current
directory when that's not what you wanted.
untar
Run the command:
tar xzf hw3DistV1.1.tar.gz
That will create a directory hw3Dist containing
some other directories containing some files.
Guide to Starter Files
Directories
hw3-cPreprocessor : has the preprocessor exercise. Go
there and rummage around.
hw3AtoE : has source files hw3A.c, hw3B.c, etc. Their
status is described in the table above. It also has a shell script,
run , described below, and a text file, problemFile .
hw3F and hw3G : put all files for your solutions to
those problems in this directories (in the obvious way).
The run Script
I wrote a shell script that compiles and runs all of
hw3A through hw3E. You invoke it as in this example:
./run testInputFile1 testInputFile2 ...
(Of course, you have to supply the names of files that actually
exist.)
For each file named in the command line, the script first runs
the Unix wc program, then each of hw3A through hw3E.
This is intended to help with debugging - you can conveniently
compare the output of each of your programs against what wc
says (remembering that our definition of the problem differs slightly
from what wc actually computes).
There are otherwise useless implementation files (e.g., hw3E.c)
in the distribution to help simplify this script -- it doesn't
check whether or not the file exists and can be compiled, it just
goes ahead and tries to compile it.
You do not have to use this script. I can't imagine why
you wouldn't, but if it's causing you problems you can just
compile manually. To do that, issue a command like this:
gcc hw3B.c -o hw3B
If the compile succeeds, it will leave the executable in a file whose
name depends on what kind of system you're running on: hw3B (Unix),
or hw3B.exe (cygwin).
What to Do
For the most part, what to do is to complete the implementations
as described in the table above.
Here is a bit more information on parts E-G.
Part E
You should ignore (i.e., not count) characters and words from the first
token on a line beginning '//' to the end of the line. You should
count the line, even if all it has is a comment, and you should
count any characters and words that precede the '//'.
If '//' is embedded inside a token (or at the end) it is NOT considered to
start a comment. (That is just to make things a little easier.)
For example, if the full input is this (without the quotes --
they're just there because counting leading spaces would be hard without them,
and there are no trailing spaces, just the \n at the end of the line):
"This is a test // this part is ignored
"
the output should indicate that there are 16 characters, 4 words, and
1 line. (Since we're counting this as a line, it makes sense to count the '\n'
that ends the line as a character as well. That's how we end up with 16 characters.)
Part F
Take the code for the function that initializes the FSA
out of hw3F.c and put it in its own file, hw3Ffsa.c. Now just
get it to build. When you're done, this command should work:
gcc hw3F.c hw3Ffsa.c -o hw3F
To get this to work, the C compiler is going to need the type signature
of the function you just moved while it's compiling hw3F.c. To
arrange to tell it that, put the signature in hw3Ffsa.h. You'll need to
use the extern keyword. Here's an example line that might
go in a .h file, but for
a completely different function:
extern void myFunc(int id, char c);
Part G
This modification does two things: prints the counts, ignoring
'//' comments for character and word counts,
and prints the input it was counting with all '//' comments removed.
Warning: this part is a test of design as much as it is a test of coding.
You should end up with something I (me) can sensibly use. Think about
what that might be (e.g., how and when can I use your
program) and try to make your solution both flexible and convenient.
Modify the README.txt file in this directory to contain a very
short description telling us (a) what your solution is, and (b) exactly
how to invoke it.
Your solution must build with this command
gcc *.c -o hw3G
|