State Machine Simulator

(rated by JARS on DEC/1995, #B011212-3)

This applet uses Beta API, so you need to be looking at this page with Netscape 2.0 Beta 2 or higher to see the applet. Click here to see the source and the design document. Feel free to use or distribute them any way you want.



Click below for help on the command buttons
New Load Save About Quit
Add State Del State Mark Initial Mark Accepting Mark Normal
Add Transition Del Transition Input String Run Stop

About this applet

I developed this applet as a term project for the Object Oriented Programming class, that I took at OGI in Fall, 1995. The applet is supposed to be a finite state machine simulator and I hope it comes close to being one :) It can handle 10 states (numbered 0 through 9) and 26 tokens (a through z). All commands are accessed through the buttons on the top part of the applet. Instructions on the bottom part of the applet guide you through the operations. Be careful with some of the buttons, I have not implemented the confirmations for some of them yet (like New).

New
Start a new state machine. Selecting this button will delete the current state machine and start over. Be careful, as you will not be presented with the confirmation dialog (yet).

Load
Load a previously saved state machine. You will be presented with the dialog, where you can type in the name of the file. Java's FileDialog threw exceptions at me under NT for some reason, so I gave up on it and implemented it in this naive way. Note that file operations do not work if the applet was loaded from the Internet. To use this feature you will have to get Sun's AppletViewer that comes with Java Development Kit, get the Simulator classes on your machine and run it locally there. I suppose you can also use Netscape to view it locally.

Save
Same dialog as above, but now you can save your state machine. Input string also gets saved. This is useful for demos and simply to remember which strings work with which state machines. The above comments regarding security apply here too.

About
Pops up a simple window that reminds you what this applet is and who is that great guy who implemented it :)

Quit
This does nothing within the browser and is only useful when running the applet in standalone mode. As you might have guessed it exits the program. This command is nice enough to confirm the termination with you.

Add State
Lets you add a new state. After pressing the button, click where you want the new state to appear. Watch the help line on the bottom for hints and instructions. You can also drag already existing states around with the mouse.

Del State
After selecting this button, click on the state you want to delete. All transitions to and from this state will be deleted also.

Mark Initial
Lets you mark a state as initial state. A rectangular box will be drawn around the state to signify that. Note that there could be only one initial state in the state machine. Simulator will reject any attempts to mark initial states if one is already present. Initial state can be also marked as accepting state.

Mark Accepting
Marks the state you click at as accepting. Accepting states are denoted by double circles. A machine can have any number of accepting states.

Mark Normal
Removes the initial and accepting attributes from the specified state, making it normal again.

Add Transition
After pressing the button, click on the start state (it will turn blue) and then on destination state. A token selection dialog will pop-up. You can select the tokens for which this transition is taken by clicking on the associated boxes. You can select any number of tokens. To select all tokens, click on the 'All' checkbox. If you do not select any tokens no transition will be added. If another transition already exists between these two states, the newly selected tokens will be added to that transition, and no new transition will appear. Thus there is only one transition between any two states, but it can fire on any number of tokens. You can also add transitions where source and destination states are the same, by clicking on the same state twice.

Del Transition
Click on source then on destination states. A transition between them will be deleted.

Input String
A dialog, allowing you to enter the input string for the state machine appears. You can enter any number of tokens. Note that valid tokens are 'a'-'z'. The tokens are not checked for being valid until the simulation stage, so if you enter and invalid string it will be accepted for now. Input string is displayed in blue underneath the control buttons. The current token is displayed in red.

Run
Allows you to run the simulation step by step. To advance to the next token click with the mouse anywhere on the screen. Current state and transition taken are marked in red. You will also see the current token marked in red in the input string. Simulation aborts if an error condition occurs. Watch the status line on the bottom for the explanations. An invalid token, ambiguous grammar (more than one transition can be taken for the given token) or absence of the transition for the current token are all considered to be error conditions. When the end of the string is reached the status line will inform you if the string was accepted by the machine or not. If the last state is marked accepting it will be highlighted in blue, signifying acceptance.

Stop
Aborts the current simulation in progress and returns to editing mode.

Feel free to send me your comments and suggestions at the address below.

Last Updated: Sunday, January 7, 1996 by Kyril Faenov (kxf@valence.com).