Introduction To Jflap - Jar and Finite State Automata: Theory of Computation (Cs 333) Spring Term, 2011 (Prof. Mckelvey)
Introduction To Jflap - Jar and Finite State Automata: Theory of Computation (Cs 333) Spring Term, 2011 (Prof. Mckelvey)
McKelvey)
Introduction
JFLAP is a freeware application written in the Java language, distributed as a *.jar file. We will use this application to experiment with several of the formal computational models we cover in our class. The home page for the JFLAP project is: http://www.jflap.org/ From this website comes the following description of the software: JFLAP is software for experimenting with formal languages topics including nondeterministic finite automata, nondeterministic pushdown automata, multi-tape Turing machines, several types of grammars, parsing, and L-systems. If you want to download the JFLAP software from the web, the site above makes it simple to do so. You should know, however, that the software is already available on the CS333 L: drive folder in the Class Materials folder. On St. Olaf Linux systems this folder (directory) is: /home/classes/201011\Semester\2/cs333/Class\Materials The backslashes are necessary to escape the blanks that appear in the various folder names. The easiest way to install JFLAP is to use the jflap.jar file directly from this folder, or to copy it to your favorite computer(s) for later use. The same application file works on Microsoft Windows, Apple OS X and Linux operating systems. On Microsoft and Apple Systems, and some Linux systems, all that's necessary to run the JFLAP application is to double click on the jflap.jar icon. On Linux systems a command line approach might be needed, in which case the command that usually works is: javajarjflap.jar&
We are interested in creating finite automata, so the next step is to click on the button labeled Finite Automaton. This will result in the window, shown below, upon which we will draw our FSA.
Note the Editor tab as well as the six icons immediately below the editor tab. As we build multiple FSAs and save them, additional tabs will appear, one for each machine. The six icons allow us to create and editor the graphical representation of the FSA we are interested in. The functions of the icons are listed listed below: Icon Function Attribute Editor: Sets the state attribute as being the initial state, an accepting state, both, or neither. State Creator: Creates a new state and places it, unconnected, onto the graphical interface. Transition Creator: State transitions, based on the next character in a string, are represented by labeled links, the label indicating the character causing the transition. This icon creates and labels these links. Deleter: When selected, this tools deletes picture elements. Place the cursor over the elenent of interest and click to delete the element. Undoer: Both of these icons undo the most recent action taken in the construction of the FSA graphical representation.
To see how when can use JFLAP to create a simple FSA, consider the language L of all strings from the alphabet ={a,b} that end in b. The empty string is not in L.
In this FSA, let q0 be the initial state which will only correspond to the empty string. Let q1 be the state we transition to whenever an a is encountered, and state q2 be the state we transition to whenever a b is encountered. The state q2 will be the only accepting state in this FSA. We note that our FSA has three states. We begin building the graphical representation of this FSA by clicking on the state creator icon. Next, we move the cursor to a convenient place on the JFLAP canvas and left click, causing a circular figure labeled q0 to appear. Clicking at two other locations creates nodes labeled q1 and q2 to appear. Your JFLAP window should now look something like the figure on the next page. The next step is to classify these states as being the initial state or an accepting state. This is accomplished using the Attribute Editor. To indicate that q0 is the accepting state, click first on the Attribute Editor icon. Then move the cursor to the state node you wish to classify, state q0 for now, and right-click on that node. A sub-window will appear giving you a menu of classification choices. Since we want q0 to be the initial state, left-click on the Initial box. A fairly large triangle should appear to the left of the q0 node, indicating it is now the initial state of our FSA. To indicate that q2 will be an accepting state, move the cursor to q2, right-click, and left-click on the Final box. This indicates that q2 is an acceptable final state, meaning the input string will be accepted. Graphically, this characteristic of q2 is shown by rendering q2 as a double circle.
After classifying the initial and accepting nodes, the JFLAP canvas should look something like this:
We finish building our FSA by inserting the links into the picture that represent transitions. In our FSA every possible input string will result in a transition. In more complicated situations only some of the possible transitions will be explicitly shown. If a possible transition is not shown on the canvas, the input string is immediately rejected. In our FSA, state q1 is entered whenever an a is encountered, and q2 is entered whenever a b is encountered. To create the transition from q0 to q1 in the event that the first character in the input string is an a, we select the Transition Creator tool by clicking on its icon. We then move the cursor to somewhere within the q0 circle, press and hold the left mouse button, and drag the cursor to q1, releasing the mouse button. A highlighted rectangle, possibly containing a (lambda), will appear midway between q0 and q1. Type the letter a into this rectangle, indicating the link under construction corresponds to a transition for the character a. Hit Enter (perhaps twice) and an arrow will appear, labeled with an a. This indicates the transition has been created. The JFLAP canvas should appear like this:
To create a transition from a state back to itself, for example moving from q1 to q1 if two a's appear together in an input string, just click and release the Transition Creator tool over the state, without dragging the cursor at all. We use these instruction to complete the graphical depiction of our FSA.