Software Construction and Development: Dr. Nazia Bibi
Software Construction and Development: Dr. Nazia Bibi
Lab 07
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
What is JFLAP?
JFLAP program makes it possible to create and simulate automata. Learning about automata with
pen and paper can be difficult, time consuming and error-prone. With JFLAP we can create
automata of different types and it is easy to change them as we want. JFLAP supports creation of
DFA and NFA, Regular Expressions, PDA, Turing Machines, Grammars and more.
Setup:
JFLAP is available from the homepage: (www.JFLAP.org). From there press “Get FLAP” and
follow the instructions. You will notice that JFLAP have a .JAR extension. This means that you
need Java to run JFLAP. With Java correctly installed you can simply select the program to run it.
You can also use a command console run it from the files current directory with, Java –jar
JFLAP.jar.
Using JFLAP:
When you first start JFLAP you will see a small menu with a selection of eleven different
automata and rule sets. Choosing one of them will open the editor where you create chosen type
of automata. Usually you can create automata containing states and transitions but there is also
creation of Grammar and Regular Expression which is made with a text editor.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Now you should have an empty window in front of you. You will have a couple of tools and features at
your disposal.
The toolbar contains six tools, which are used to edit automata.
Attribute Editor Tool, changes properties and position of existing states and transitions.
State Creator Tool, creates new states.
Transition Creator Tool, creates transitions.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Creating an automaton is easy with the state and transition tools. Note that you need to change back
to the Attribute Editor Tool (first) to change states. Let’s try to add states with the State Creator Tool
(second).
When adding states they automatically get a name assigned to them, which can be changed using the
Attribute Editor Tool. Transitions are easily dragged between states with the Transition Creator Tool.
The automaton above only accepts strings containing b which end with a. To test this automaton you
can use any of the available tools under the Input menu.
The fastest in this case is to use Input → Fast Run. A menu where you can set your input string pops
up. Type the string “bba” and select “OK”. The program shows all the transitions that are done when
consuming the input string.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
If you want to test multiple inputs at once you can select the “Multiple Run” option. If you wish to
individually review single runs, it can be accessed by selecting the View “Trace”, which gives a view similar
to the “Fast Run” option.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
The first character consumed. Notice that the first letter is grayed out and the currently active state
have changed.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Now the last character is about to be consumed. This step shows the transition between q0 and q1. If
there happen to be multiple paths with the same character you will see them grayed out.
To restart the test you can select the reset button to start from the beginning or press the X button in
the top right corner to go back to the editor.
Task 01:
Create this Deterministic Finite Automaton. First start JFLAP and select “Finite Automaton” as a new
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
automaton. Use the toolbar to drag and drop states and transitions.
Select the transitions with the selection tool. Then type the input character for each transition. Remember
that initial and final states must be set to make the automaton run. State q0 is set as the
initial state which means the starting state. State q3 will be the final state which is a state that should
be active once the string is accepted and consumed. There can be more than one final state.
When you are done, the automaton should look like this.
To run this DFA select Input → Step By State, then choose an input string to run the automata with.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
You will see JFLAP’s simulation view where you can debug the automaton while it consumes the input
string. Use the Step button to step trough the string. Here the automaton have moved the active state
and have consumed all the b characters.
Once the whole string is consumed the automata should park at the final state and the stack turns
green. The string is accepted.
Try to use Input → Multiple Run instead. Which strings are accepted, and which ones are rejected?
Task 02:
The language is a string of 1 or more a's followed by a string of b's with more b's than a's.
UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Task 03:
The language is a string of 2 or more a's followed by 0 or more b's such that the number of a's is divisible
by 2 or 3, and the number of b's is divisible by 2 or 3.
Strings in the language include: aaaabbb, aaaaaabbbb, aaa
UET Taxila