COM3336
Programming Assignment I

Due:

October 12, at the start of class time: 6 p.m.

PART 1

PART 1 is from Professor Solomon, modified by Professor Casey

PART 2

Part 1 does not show you what kind of data structures are needed in an operating system. A complete operating system has many of them and here we focus on data structures needed to describe a simple file system. File systems are an important part of operating systems and your text book has an entire chapter about them.

In part 1 we actually ran the commands like "mkdir a" and it created a directory "a" on a server. After the program exited, the directory "a" existed. Part 2 of the assignment is to simulate an operating system. Therefore, NOT TRULY create a directory with the mkdir command on the system but internally to the program. AFTER the program exits, nothing on the server should have changed. For example, even though you do a "mkdir a" within the script, directory "a" on the UNIX server should NOT exist.

For Part 2, we simulate a few file management commands by building our own data structures that represent what the commands do. You are not allowed to use Runtime and Process objects in this part. Your program should be able to handle inputs like:

mkdir a 
mkdir b
cd a
mkdir c 
mkdir d 
cp -r ../* . 
cd .. 
echo "before_du" 
du & mkdir e 
find . -name c -print
du
and produce the same output as UNIX, except that the disk usage command du prints only the file structure and no sizes. More precisely, your program should be able to execute a list of commands as defined by the Extended Backus-Naur-Form (EBNF) grammar below:
Command = Simple | Compound.
Simple = MakeDirectory | ChangeDirectoryUp | ChangeDirectoryDown | 
  RecursiveCopy | DiskUsage | Find | Echo.
MakeDirectory = "mkdir" DirectoryName.
ChangeDirectoryUp = "cd ..".
ChangeDirectoryDown = "cd" DirectoryName.
RecursiveCopy = "cp -r ../* ." .
DiskUsage = "du .".
Find = "find . -name" DirectoryName "-print".

Echo = "echo" Message.
// You may assume that Message does not contain any spaces to simplify parsing

DirectoryName = Ident.
Message = String.
Compound = Command "&" Command. 
// two commands separated by & are executed in parallel
// use two separate Java threads
CommandList = Command {EOL Command}.
// a command list consists of one or more commands separated by end-of-lines
// EOL is end-of-line.
This grammar notation is similar to the grammar notation used in the Java Language Specification by Gosling, Joy and Steele. There are a number of grammar notations used and once you understand one you understand all. For the input above, your program should produce an output similar to:
before du
      ./a/c
      ./a/d
      ./a/a/c
      ./a/a/d
      ./a/a
      ./a/b
      ./a
      ./b
      .
./a/c
./a/a/c
      ./a/c
      ./a/d
      ./a/a/c
      ./a/a/d
      ./a/a
      ./a/b
      ./a
      ./b
      ./e
      .
It is important to do this part in stages. You get full credit if your program works correctly for the sublanguage that includes the commands
Simple = MakeDirectory | ChangeDirectoryUp | ChangeDirectoryDown | DiskUsage .
For example, for the input:
mkdir a 
mkdir b
cd a
mkdir c 
mkdir d 
cd .. 
du
your program should produce the output:
      ./a/c
      ./a/d
      ./a
      ./b
But you should write your program in such a way that it would be easy to add the rest of the commands. Note that RecursiveCopy, DiskUsage and Find have significant common behavior that you should factor out.

For part 2 you should focus your efforts on correct inputs as described by the above grammar. It is not important that you give a good error message in case of a syntax error. But your program needs to handle correct inputs correctly.

Operating systems are widely reused software packages. In this homework you should also practice reuse by reusing the software from part 1 that does the parsing of commands. No need to write that software again. What is the best way to encapsulate your parsing code so that you can reuse it in both parts?

To represent your file system you may want to use Java classes similar to the ones described below.

class File is superclass of SimpleFile and CompoundFile.
class SimpleFile has member FileName called f.
class CompoundFile has member FileName called fn and 
		       member FileList called contents.
class FileList is a collection of File.
FileName has member Ident called i.
To represent the list use a suitable class from the Java Collection Framework http://java.sun.com/products/jdk/1.2/docs/guide/collections/.

Grading

You turn in your solution by sending mail to com3336-grader as described in Part 1. Turn in your Java files (no class files!) and a transcript similar to part 1.