Homework 7

22C:50 Section 2, Fall 2000

Due Monday Oct 16, 2000, in class

Douglas W. Jones

  1. Consider the following UNIX shell script, stored in the file script.csh:
    # file script.csh   
    echo "begin $*"
    if ("$1" != "") then
       csh script.csh $*
    echo "end"
    Explain what happens when you execute this script using the command:
    csh script.csh E F G
    Specifically, how many copies of the command interpreter (the C-shell) are loaded in memory, what parameters are passed to each, and how do the different copies come to be executed?

    The man csh command will give you the official documentation on the C-shell; you may be able to figure out the shell by experimenting with it, but if you have difficulty, the "man page" may be helpful.

  2. Write a shell script for the UNIX C-shell that takes a short list of files as parameters and concatenates them into one output file, with a block of text added before each file included in the output giving the title of the file. You can base this on the script from problem 1; the only feature of the C-shell you need that isn't listed in problem 1 is the following UNIX shell command: Note; if you want to make your program (or any UNIX program) send its output to a file instead of sending it to the screen, use the > feature of the shell for output redirection.

Machine Problem 3

Due Monday Oct 23, 2000, in class

Modify your solution or the example solution to MP2 so that it accepts expressions as operands using the grammar of Figure 5.11.

If you want to work incrementally toward this, first solve the problem with the grammar of Figure 5.5, and then work your way up towards the final version.

You should only turn in a listing of the only source file you had to change in order to solve the problem! Your changes should fit seamlessly into the source that was distributed. Your changes should conform to the "house style" for C programs.

Keep a clean on-line copy of your solution that you have not edited since the due date. This can be used as proof of successful completion of the assignment in the event of any questions about your solution! In the absence of such questions, your score will depend only on the listings you turn in, with special attention paid to clear acknowledgements, in header comments, of any known deficiencies in your solution.