You are on page 1of 9

Introduction to JFLAP

Prelude to the Workshop on JFLAP

 Computers are used everywhere – Processing numbers, data, images and controlling
the operations of various devices
 Are computers capable of computing anything? If computers cannot do everything,
what are they and why? In essence, what is computation?
 To study limitations of computations we study the essence of computers rather than
studying varieties of computers.
 The essence of computation is Turing Machine – conceived by Alan Turing in early
20th Century. It s a simple device but every task performed by modern computers can
be accomplished by Turing Machine.
 Before studying Turing machine a simple device called finite automata can be
studied, which can model a large number of systems used in practice.
 To learn about the fundamental capabilities and ultimate limitations we look to the
theory of computation or theoretical computer science.

Theory of Computation

 Theory of computation includes Automata Theory, Formal Languages and Grammars,


Computability and Complexity.
 Using Automata, Grammars and Computability we study of what can be done by
computers in principle and Complexity tells what can be done in practice
 The most basic model of a computer is the finite automaton. An automaton models
the hardware of a computer. It has all the essential features of a computer. It accepts
input, produces output, may have some temporary storage and can make decisions in
transforming the input into the output. In other words this is a computer without
memory or rather the amount of memory s fixed, regardless of the size of input.
 A formal language is an abstraction of the general characteristics of programming
languages. A formal language is the set of all sentences permitted by the rules of
formation.
 Languages recognized by Finite Automata are regular languages
 Languages recognized by Turing Machine are called phase structure languages
 Other two languages are context free languages and context sensitive languages. All
these four languages are called formal languages

Specifications of a Language:

 A set ‘S’ consisting of ‘Words’


 A Subset S* (Set of all finite strings of elements of S), consisting of all possible
‘Properly Constructed Sentences’
 A method to determine which of the ‘Properly Constructed Sentences’ are meaningful
and what the meaning is
Example 1: English Language
 S is the set of all English Words
 The complete rules of English Grammar help us to find out all properly constructed
sentences.
 The meanings of the properly constructed sentences are determined by the grammar
and by the meanings of the words (and of course by the context)

Example 2: Arithmetic Expressions


 S is the set of all integers and operators
 The usual rules of parenthesis and operators help us to find out all properly
constructed arithmetic expressions.
 All properly constructed arithmetic expressions are meaningful except those involving
division by zero.

Example 3: Miniature Language


Words: Ram, Sam, drives, jogs, rapidly, frequently
Symbols: sentence, noun, verbphrase, verb, adverb
Productions:

sentence noun verbphrase; verbphrase verb adverb; noun ram, sam;


verb drives, jogs; adverb rapidly, frequently

Sentence Formation:

sentence noun verbphrase Ram verbphrase Ram verb adverb


Ram drives adverb Ram drives rapidly

Example 4: Finite Grammar generating Infinite Language

Words = {a,b,c}; Symbols = {v0,w}; v0 aw; w bbw; w c

Sample Sentences: ac, abbc, abbbbc…….Language: a(bb)*c

Importance of strings

The input to our computers is always strings. Everything can be converted to questions about
strings. Hence we will be concerned with acceptance or non acceptance of strings.

From “Introduction to Automata theory, Languages and Computation” – Hopcroft et al

Automata theory is the study of abstract computing devices, or "machines." Before there were
computers, in the 1930's, A.Turing studied an abstract machine that had all the capabilities of
today's computers, at least as far as in what they could compute. Turing's goal was to describe
precisely the boundary between what a computing machine could do and what it could not
do; his conclusions apply not only to his abstract Turing Machines, but to today's real
machines.

In the 1940's and 1950's, simpler kinds of machines, which we today call "finite automata,"
were studied by a number of researchers. These automata, originally proposed to model brain
function, turned out to be extremely useful for a variety of other purposes. Also in the late
1950's, the linguist N. Chomsky began the study of formal "grammars." While not strictly
machines, these grammars have close relationships to abstract automata and serve today as
the basis of some important software components, including parts of compilers.

All of these theoretical developments bear directly on what computer scientists do today.
Some of the concepts, like finite automata and certain kinds of formal grammars, are used in
the design and construction of important kinds of software. Other concepts, like the Turing
machine, help us understand what we can expect from our software.

Finite automata are a useful model for many important kinds of hardware and software like

 Software for designing and checking the behavior of digital circuits.


 The "lexical analyzer" of a typical compiler, that is, the compiler component that
breaks the input text into logical units, such as identifiers, keywords, and punctuation.
 Software for scanning large bodies of text, such as collections of Web pages, to find
occurrences of words, phrases, or other patterns.
 Software for verifying systems of all types that have a finite number of distinct states,
such as communications protocols or protocols for secure exchange of information.

There are many systems or components, such &s those enumerated above, that may be
viewed as being at all times in one of a finite number of "states." The purpose of a state is to
remember the relevant portion of the system's history. Since there are only a finite number of
states, the entire history generally cannot be remembered, so the system must be designed
carefully, to remember what is important and forget what is not.

The advantage of having only a finite number of states is that we can implement the system
with a fixed set of resources. For example, we could implement it in hardware as a circuit or
as a simple form of program that can make decisions looking only at a limited amount of data
or using the position in the code itself to make the decision.

There are two important notations that are not automaton-like, but play an important role in
the study of automata and their applications.

1. Grammars that are useful models when designing software that processes data with a
recursive structure. An example is a 'parser’, the component of a compiler
2. Regular Expressions that denote the structure of data, especially text strings.

What is JFLAP

JFLAP is a package of graphical tools which can be used as an aid in learning the basic
concepts of Formal Languages and Automata Theory.
Regular languages - create

 DFA
 NFA
 regular grammar
 regular expression

Regular languages - conversions

 NFA -> DFA -> Minimal DFA


 NFA <-> regular expression
 NFA <-> regular grammar

Context-free languages - create

 push-down automaton
 context-free grammar

Context-free languages - transform

 PDA -> CFG


 CFG -> PDA (LL parser)
 CFG -> PDA (SLR parser)
 CFG -> CNF
 CFG -> LL parse table and
parser
 CFG -> SLR parse table and
parser
 CFG -> Brute force parser

Recursively Enumerable languages

 Turing machine (1-tape)


 Turing machine (multi-tape)
 Turing machine (building
blocks)
 unrestricted grammar
 unrestricted gramamr -> brute
force parser

L-Systems

 Create L-systems

JFLAP Main Menu

JFLAP can be downloaded from www.jflap.org. JAVA is needed to run JFLAP


Examples and Exercises:

A finite automaton has a finite set of states with which it accepts or rejects strings. “Program”
prescribes how symbols read affect current state. Final state is state FA is in when finished
reading the input string. There are ACCEPT states (double circle) and REJECT states. A
finite automaton accepts input string if final state is accept state; otherwise it rejects.

1. The simplest nontrivial finite automaton is an on/off switch. The device remembers
whether it is in the "on" state or the "off" state, and it allows the user to press a button
whose effect is different, depending on the state of the switch. That is, if the switch is
in the off state, then pressing the button changes it to the on state, and if the switch is
in the on state, then pressing the same button turns it to the off state.

2. Finite Automaton to accept (1+01)*00(1+0)* (Note that the string should have 00 to
be accepted. Other variants – 1 or 01 any number of times can precede 00 and any
combination of 1 and 0 can succeed 00. But minimum string accepted is 00)

3. Finite automaton to accept (0*10*1)*0*10* (Note that the string should have a 1, or
odd number of 1’s to be accepted. Other variants – any number of 0’s followed by a 1,
followed by any number of zeros, followed by a 1, or any number of repetitions of
this combination (0*10*1), followed by any number of zeros, followed by a 1,
followed by any number of zeros)

Alphabet is a set of symbols. Language is a set of strings. Language of a finite automaton is


the set of accepted strings. Length of a string is the number of symbols. Empty string is also
allowed.

4. An automaton that ends with 00


5. An automaton that starts with 00

A trap is state that once entered, one can never leave. A trap state is used to reject partly read
strings that will never be accepted, or to accept partly read strings that will definitely be
accepted.

6. An automaton with a trap state to accept strings with alternating 0’s and 1’s

7. Another design of the automaton to accept strings with alternating 0’s and 1’s

8. Automata to accept a) All binary strings with at least one 0 b) All binary strings
with at most one 0 c) All binary strings starting and ending with 0 (and single-0
string counts) are illustrated below:
9. A vending machine designed to give soda if coins, in any combination of 1, 2 or 5,
amount to 5 and to eject coins if the amount is less or more.

10. Automaton to find all occurrences of 1001 (String Processing)

11. Think of real world situations where we come across acceptance or non acceptance of
strings – An ATM machine which declines transactions given three consecutive
wrong PIN can be thought of rejecting strings with three consecutive zeros. Think of
other situations and try to model them with JFLAP – like the standard task to find all
occurrences of a short string, called the pattern string, within a long string, called the
text string – String Processing.
Exercises for the Hands on Session:

1. Construct an automaton to accept valid integers like +989, -978, 980 etc

2. Construct an automaton to accept expression (x+y), (x-y), (x*y), (x/y)

3. Construct an automaton to accept expressions like (x+y), (x-y), (x*y), (x/y), x, y, z

with or without brackets

4. Construct an automaton to count the number of occurrences 1001

5. Construct an automaton that accepts only the string 0110

6. Construct an automaton that accepts only binary strings of length 3

7. Construct an automaton that accepts any string of 0’s and 1’s

8. Construct an automaton for each of the following languages

a. All binary strings with at least three 1’s


b. All binary strings with and odd number of 1’s
c. All binary strings without 111 as a substring
d. All binary strings where every odd position is a 1
9. Construct an automaton that accepts all binary strings with precisely three 1’s

10. Construct an automaton whose language is the set of strings of a’s and b’s and c’s that
contain abc as a substring

11. Construct an automaton that accepts all strings of {a, b, c} whose symbols are in the
alphabetical order like aaabccc and not like abca or cb

12. Construct an automaton that accepts all binary strings with an even number of 0’s and
and the number of 1’s is a multiple of 3.

Reference – Introducing Theory of Computation by Wayne Goddard

You might also like