ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 25 May 2017 My Price 9.00

CS 146 Assignment #5

This assignment requires you to build a program in C that works as a parser for a Unix Shell. I only need PART 1 of the attached prompt. (DONT need PART 2!). Please dont attempt to answer this question unless you are SURE you can do it! 

 

CS 146 Assignment #5 (Project)Due dates: Part 1: Thu. 19 May. (no extension, solution handed out on that date!!!);Part 2: Thursday of Week 10..Write a simple Unix command-line shell called "nsh".It will support, at the very least: shell scripts; the running ofarbitrary commands with arguments; the “cd” command; at least one pipe; and I/O redirection (including append).Beyond that, there is considerable choice as to what you decide to implement.The assignment is out of 30 marks,but bonus marks are possible.MINIMAL SHELL (30 points)You are to write a shell that is similar to a subset of the Bourne Shell.The syntax for everything that is implementedwill be identical to the Bourne Shell. So, for example, it needs to handle the following command lines:? who | fgrep -i .edu > foo? sort < foo | uniq -c >> bar? ^D$The prompt is '? ', ie., a question mark followed by a space; nsh should exit when it encounters EOF (which is ^D onthe keyboard).In addition, it must support shell scripting so that if precisely one argument is given, then that argumentis interpreted as an nsh shell script and the commands in it are run, without printing a prompt.If you implement thisfirst, it will facilitate easy testing of your nsh program as you develop it, because you can write test scripts and comparethe output of "nsh foo" with the output of "sh foo", since nsh is supposed to act just like the Bourne shell.You do notneed to perform syntax checking on the command line; incorrect command lines are allowed to crash your programwithout loss of marks on the assignment (I’m being easy on you because this assignment is hard enough as it is).Note there are spaces around every token; this makes it easier for you.You'll need to look (at least) at the followingmanual pages: fork(2), exec(2), pipe(2), open(2), creat(2), close(2), dup(2), dup2(3c).Note that you must be carefulwith files: you may be working with both Unix file descriptors (because those are the only things pipe(2) and dup(2)work with), and ANSI C (FILE *) pointers (because it will make some of the other stuff easier).You can, if you want,choose to work only with Unix file descriptors.For example, in the simple version of the shell above, the only thingyou ever need to print is the prompt, so you don't really need the functionality of printf(3c).You are free to useversions of exec(2) that search the PATH for you (eg., execlp, execvp); you don’t need to search it yourself.PART 1: The Parser(15 marks.Due Thu 19 May, when a solution will be distributed)Since this will be quite a large project, you will split it into manageable chunks and put each chunk in a separatelycompiled module, and then use a Makefile.However, the Makefile is not due until Part 2.In part 1 you will write the"parser".A parser's job is to break up the line into its constituent logical parts.That means it needs to figure out ifthere is any input/output redirection (the < and > characters),how many pipes there are on the command line (which isone less than the number of commands between pipes---eg., “who | wc” is two commands separated by one pipe),andwhat the command line arguments are to each command.You should create astructwhich will hold a full commandline with all this information, and put its definition into a file calledparse.h.The fileparse.halso contains a prototypefor the functionParse, which will be defined in the fileparse.c.Then createparse.c, which contains the code for theactual parser.The filemain.cwill contain a loop which (for now) just reads a line, pasess that line to the functionParse.Parsewill populate thestructwith the logical info on the commandline, and then yourmainprogram willprint out the parsed version of the command line.For example, given “cat –v <infile | grep foo | wc > outfile”, the Part1 version of your main program should print:3: <’infile’ ‘cat’ ‘-v’ | ‘grep’ ‘foo’ | ‘wc’ > ‘outfile’The ‘3’ represents the number of commands, and each “word” is printed with quotes around it.Input/output redirectionshould only be printed if they are present.So for example “who | wc” should give:2: ‘who’ | ‘wc’A correct executable of the parser is in ~wayne/pub/cs146/nsh-parser.You can use it to see what yours should outputfor Part 1 of the assignment.

Attachments:

Answers

(11)
Status NEW Posted 25 May 2017 03:05 AM My Price 9.00

-----------

Attachments

file 1495683234-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)