Princeton University
COS 217: Introduction to Programming System

Precept 22:  Ish Overview

Purpose

Describe the functionality and design of ish, and the stages of program development

Ish Functionality

ish:  a simple but realistic UNIX shell

Show file sample_ishrc.txt (from the assignment statement) 

Contains examples of the kinds of commands that ish must interpret

Line 1:  echo

Executable binary commands

Relative path names

Line 2:  echo "*** SIMPLE COMMANDS"

Command line arguments, double quotes

Line 4:  cd

Shell built-in commands

Line 11:  /bin/date

Absolute path names

Line 14:  ls > 217test.1

Redirection of stdout

Line 15:  cat < 217test.1

Redirection of stdin

Line 20:  date | wc

Pipelines containing two commands

Line 21:  date | wc | cat | grep 1

Pipelines containing more than 2 commands

Line 25:  cat < 217test.1 | grep 217test.1

Combinations of redirection and pipes

Line 26:  cat < 217test.1 | grep 217test.1 > 217test.3

Redirection of stdin of first command, and stdout of last command of a pipeline

Line 31:  setenv FOO bar

Shell built-in command

Setting of environment variables

(bash uses more complex "export" command

Line 32:  printenv

Executable binary command to examine environment variables

Line 33:  unsetenv FOO

Shell built-in command

Unsetting of environment variables

Line 37:  notfound

No such command

Line 38:  ls "<" 217test.3

Quotes to change special character into an ordinary one

Error:  no such file

Another example:

echo one > two
echo one ">" two
Line 39:  date > 217test.4 | wc

Error:  can redirect stdout of only last command of pipeline

Study the assignment statement for details

Ish Design

Draw diagram on board showing::

Lexical Analysis Phase

Input:  a line (i.e. a character sequence)

Output:  token list

Syntactic Analysis Phase (i.e. Parser)

Input:  token list

Output:  pipeline -- a structure containing commands

Execution Phase

Input:  pipeline

Output:  The execution of the pipeline

Example 1:

Input line:

echo one > myfile

Token list:

token 1:  echo
token 2:  one
token 3:  >
token 4:  myfile

Pipeline

command 1:
   arg 1:  echo
   arg 2:  one
   stdinredirect:  NULL
   stdoutredirect:  myfile
   (other)

Note:  Your implementation of pipeline may be different; in particular, it may (eventually) contain more data

Example 2:

Input line:

echo "one two" three

Token list:

token 1:  echo
token 2:  one two
token 3:  three

Pipeline:

command 1:
   arg1:  echo 
   arg2:  one two
   arg3:  three
   stdinredirect:  NULL
   stdoutredirect:  NULL
   (other)

Example 3:

Input line:

ls -al | more

Token list:

token 1:  ls
token 2:  -al
token 3:  |
token 4:  more

Pipeline:

command 1:
   arg 1:  ls
   arg 2:  -al
   stdinredirect:  NULL
   stdoutredirect:  NULL
   (other)
command 2:
   arg 1:  more
   stdinredirect:  NULL
   stdoutredirect:  NULL
   (other)

Ish Development Stages

See the Assignment 6 Development Stages handout

Copyright 2002 by Robert M. Dondero, Jr