Spring 2007 |
Clay Shields |
Project 1 - Part 1: Writing a User Shell |
Project 1: The ShellIntroductionThe goal of this project is to build a shell interpreter like csh. The project has been divided in several parts. Some sources are being provided so you don't need to start from scratch.Using the DebuggerIt is important that you learn how to use a debugger to debug your C and C++ programs. If you spend a few hours learning how to use gdb, it will save you a lot of hours of development in this lab.To start gdb type gdb program. For example, to debug your shell type: csh> gdb shell Then type (gdb) break main This will make the debugger stop your program before main is called. In general, to set a breakpoint in a given function type break <function-name> To start running your program type: (gdb)run Your program will start running and then will stop at main. Use "step"or "next" to execute the following line in your program. "step" will execute the following line and if it is a function, it will step into it. "next" will execute the following line and if it a function it will execute the function. (gdb) next- Executes following line. If it is a function it will execute the function and return. or (gdb) step- Executes following line. If it is a function it will step into it. An empty line in gdb will rerun the previous gdb command. Other useful commands are: print var- Prints a variable where- Prints the stack trace quit- Exits gdb For more complete tutorials on gdb see: GDB Tutorial
1
First part: Lex and YaccIn this part you will build the scanner and parser for your shell.
gunzip shell-src.tar.gz tar -xvf shell-src.tar makeTo run it type: shellThen type commands like ls -al ls -al aaa bbb > outCheck the output printed cmd [arg]* [> filename]You will have to modify shell-src/shell.y to implement a more complex grammar cmd [arg]* [ | cmd [arg]* ]* [< filename] [ [> filename] [ >& filename] [>> filename] [>>& filename] ] [&] ls ls -al ls -al aaa bbb cc ls -al aaa bbb cc > outfile ls | cat | grep ls | cat | grep > out < inp ls aaaa | grep cccc | grep jjjj ssss dfdffdf ls aaaa | grep cccc | grep jjjj ssss dfdffdf >& out < in httpd & ls aaaa | grep cccc | grep jjjj ssss dfdffdf >>& out < in The deadline of this part of the project is February 13th, before class. Follow these instructions to turnin your part one. 1. Login to trogdor.cs.georgetown.edu. 2. cd to shell-src and type make clean 3. Type make to make sure that your shell is build correctly. 4. Type make clean again. 5. cd one directory above shell-src by typing "cd .." 6. Create a tar file named <user_name>.tar, where <user_name> is your trogdor.cs.georgetown.edu login, by typing tar -cf <user_name>.tar shell-src 7. Gzip the tar file by typing gzip <user_name>.tar 8. Since this timestamp will be used to verify whether the work was completed on time or not, you should set the permissions on the file you submitted to make sure that the file timestamp is not changed. So this by typing: chmod a-w <user_name>.tar.gz 9. Finally, mail the gzipped tar file to clay at cs dot georgetown
dot edu as an attachment. We need to do this so I have a record in
case the machine crashes. This will also allow you to make a backup to
your own system in accordance with the class policies.
ResourcesInformation about lex and yacc can be found here. You can also find information on Google. |