lab3 - The Shell Introduction The goal of this project is...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The Shell Introduction The 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 Debugger It 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 and future labs. 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 a more complete tutorial on gdb, google "gdb tutorial". First part: Lex and Yacc In this part you will build the scanner and parser for your shell. Download the tar file lab3-src.tar.gz , that contains all the files in lab3-src , to your home directory and untar it using the following command: gzip -dc lab3-src.tar.gz | tar xvf -
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Build the shell program by typing : make To run it type: shell Then type commands like ls -al ls -al aaa bbb > out Check the output printed Try to understand how the program works. First read the Makefile to learn how the program is built. The file command.h implements the data structure that represents a shell command. The struct SimpleCommand implements the list of arguments of a simple command. Usually a shell command can be represented by only one SimpleCommand . However, when pipes are used, a command will consist of more than one SimpleCommand . The struct Command represents a list of SimpleCommand structs. Other fields that the Command struct has are _outFile , _inputFile , and _errFile that represent input, output, and error redirection. Currently the shell program implements a very simple grammar: cmd [arg]* [> filename] You will have to modify shell.y to implement a more complex grammar cmd [arg]* [ | cmd [arg]* ]* [ [> filename] [< filename] Insert the necessary actions in shell.y to fill in the Command struct. Make sure that the Command struct is printed correctly. Run your program against the following commands:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 252 taught by Professor Gustavorodriguez during the Fall '11 term at Purdue.

Page1 / 10

lab3 - The Shell Introduction The goal of this project is...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online