COE428 Lab 4: State Machine
1. IMPORTANT: Two week lab
Note that you have two weeks to complete this lab. This lab must be submitted at least
48 hours before the beginning of your next lab period.
2. Prelab preparation
Before coming to the lab you should:
• Read the lab. Try to prepare any questions you may have about the lab.
• Refer to Lab Guide.
• Create your lab directory for lab4. (i.e. use mkdir lab4 within your coe428 directory.)
• Change to your coe428/lab4 and unzip the lab4.zip file with the command:
• Ensure that you have downloaded properly by entering the command: make
No errors should be reported.
• Get a custom version of the State Machine you are supposed to implement with the
The command /home/courses/coe428/bin/getLab4 will execute properly only on a
Sun Workstation. If you are using a computer other than a Sun workstation, please ssh to
a Sun Workstation. (For example, ssh genesis.ee.ryerson.ca)
The requirements to complete the lab are summarized below.
1. Draw a diagram of your state machine.
2. Create an executable program simState (based on C source code) that is able to respond to
the commands described below.
3. Your program will be presented with zero or more commands from stdin (each on a line by
itself) and must respond precisely as specified for each command as listed below.
Before any commands are issued to your program, it should print out the starting state.
These commands (a `0′ or a `1′ on a line by itself) must print to stdout the name of the next
state given the supplied input, and update the current state.
The change command is invoked by the letter `c’ followed by a `1′ or a `0′ followed by the
name of a state (i.e. a single letter in the range A–H). This command modifies the state
machine such that the `0′ (or `1′) command applied to the current state will cause the
machine to change to the named state and that this change is the state machine
configuration will continue. This command should produce no output.
The print command is invoked with the single letter `p’. It should print to stdout the state
machine configuration as currently specified (i.e. including changes that may have been
made with change commands) in the same format that your state machine was specified
Garbage Identify command:
This command is invoked with the single letter `g’. It should identify all states that are
reachable or unreachable from the current state. It always produces output to stdout.
If all states are reachable, it should output No garbage. Otherwise, it should output
Garbage: <unreachable states> where <unreachable states> is the list of the state
names that are no longer reachable.
This command is invoked with `d’, optionally followed by the name of a state to delete.
When the ‘d’ command is invoked without the optional argument, it should delete (i.e.
mark as “deleted”) all un-deleted states that are unreachable. If there are no such
unreachable un-deleted states, it should print:
No states deleted.
Otherwise, it should print the message:
Deleted: <list of deleted states>
If the ‘d’ command is followed by an argument that it the valid name of a state, it should
print out either the message:
if the inp
A B C
B A A
C A D
D D C
f the state is
f a state is su
he print c
cription of a
put is `0′; and
mple, given th
draw a pictu
s not reacha
s the name o
he state mac
ure of the sta
able and no
deleted, it sh
nd it should
ne is given in
of the state b
e1> is the na
ate machine a
ure 1 Stat
t already de
hould no long
d be disallow
n a text file w
ame of next
ption and the
as shown be
ger appear in
wed as a fi
where each l
state if the i
rwise, it sho
n the list of s
line has the f
ate0> is the n
nput is `1′. A
n that the ini
ould print o
ent to the c
name of nex
All state nam
itial state is
Sample input and output is:
Interface Comment: Input or Output
c 0 C Input
A B C
B C A
C A D
D D C
No Garbage Output
c 1 B Input
Garbage: D Output
Deleted: D Output
A B C
B C A
C A B
Submit your lab
1. Go to your coe428 directory
2. Zip your lab4 directory by using the following command:
zip -r lab4.zip lab4/
3. Submit the lab4.zip file using the following command:
submit coe428 lab4 lab4.zip
by Ken Clowes, revised by Ivan Lee, revised by Olivia Das