0% found this document useful (0 votes)
410 views7 pages

Introduction To Jflap - Jar and Finite State Automata: Theory of Computation (Cs 333) Spring Term, 2011 (Prof. Mckelvey)

This document provides instructions for using the JFLAP software to build and test finite state automata (FSA). It describes how to download and install JFLAP, which is a Java application for designing FSAs. It then explains how to use various tools in JFLAP to create states, transitions, and classify states as initial or accepting. As an example, it walks through building an FSA that accepts strings from {a,b} ending in b. It also demonstrates how to test strings by stepping through the state transitions in JFLAP.

Uploaded by

suhailll
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
410 views7 pages

Introduction To Jflap - Jar and Finite State Automata: Theory of Computation (Cs 333) Spring Term, 2011 (Prof. Mckelvey)

This document provides instructions for using the JFLAP software to build and test finite state automata (FSA). It describes how to download and install JFLAP, which is a Java application for designing FSAs. It then explains how to use various tools in JFLAP to create states, transitions, and classify states as initial or accepting. As an example, it walks through building an FSA that accepts strings from {a,b} ending in b. It also demonstrates how to test strings by stepping through the state transitions in JFLAP.

Uploaded by

suhailll
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Theory of Computation (CS 333) Spring Term, 2011 (Prof.

McKelvey)

Introduction to JFLAP.jar and Finite State Automata


This document gives instructions for using the freeware Java software named JFLAP to build and use deterministic finite state automata (FSA). It was developed as part of the Theory of Computation (Math 333) offered during the spring semester of 2011 at St. Olaf College.

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&

Defining FSAs With JFLAP


JFLAP is a graphical tool for designing and using finite state automata. Each state is represented as a node in the FSA, shown as a circle in the graphical interface. There are three types of states in an FSA: 1. A single initial state. 2. One or more accepting states. The initial state may also be an accepting state. 3. Zero or more states that are none of the above. Slightly different icons, all circular, are used to indicate graphically in which class or classes a given state resides. When first launched, the following window appears.

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.

Using a JFLAP Finite State Automaton


Once an FSA has been created, it can be used to accept or reject strings. As an example, consider the string aab. Ending in b, this string should be accepted by our FSA. To watch the state transitions generated by this input string, click on the Input selection on the top JFLAP menu, and select the State-by-State option. A small input window will appear. Enter the string you want to consider, aab in this example, into the blank text box in this window and click on OK. The JFLAP window will be updated to show two horizontal windows. The top window will show the schematic of the FSA we are using, and the bottom will show the initial state and the input string. To run this string through the FSA transitions, click on the Step button on the bottom row of the JFLAP window. This will show the processing of the first character of the string, the initial a. Both the schematic and the lower part of the JFLAP window show that the FSA has transitioned to state q1. Also note that the first character of the input string is no longer rendered in full black, but has been greyed out, indicating it has been fully processed. Hitting the Step button again will process the second character of the input string, another a, which leaves the FSA in state q1. Hitting Step a third time processes the last character, the terminating b, causing the FSA to transition from q1 to q2, leaving the FSA in an accepting state. Note that acceptance is indicated in the lower part of the window with a greenish background hue.

You might also like