Uploaded by NIVESH PRITMANI

JFLAP EXPERIMENTS

advertisement
EXPERIMENT 4:
Aim: Study the DFA and Design DFAs based on the Exercises
Theory:
A Deterministic Finite Automaton (DFA) is a finite state machine that accepts or rejects
finite strings of symbols and produces the same unique computation for each unique input
string. For any given finite input string, the DFA will halt and either accept or reject the
string. A DFA, M, is said to recognize a language, L(M), which is the set of all strings that M
accepts.
Formally, a DFA is described by a 5-tuple (Q, Σ, δ, q0, F) in which
 Q is a finite set of states,
 Σ is a finite set of input symbols also known as the alphabet,
 δ is a state transition function (δ : Q × Σ → Q),
 q0 is the start state (q0 ∈ Q), and
 F is a set of accept states (F ∈Q)
Examples:
1. Build a DFA for the following language L over the alphabet = {a,b}
16
2. Build a DFA for the following language L over the alphabet = {a,b}
3. Construct a DFA for L = {abnam : n ≥ 2, m ≥ 3}
17
EXPERIMENT 5:
Aim: Study the NDFA and Design NDFs based on the Exercises
Theory:
In a non-deterministic finite automation, for a given state and input symbol, none or several
choices may be available for the next state. Nondeterminism is a powerful concept in
computation which also has many practical applications.
Examples:
1. Define an NFA that recognizes the following language L over Σ = {a, b}: L = { w | w ends with aa }.
18
2. Construct an NFA that accepts the language {ab, abc}*. This is the set of strings where ab and abc may be
repeated. Example strings include abcab, ababcab, abcabcabc, and the empty string.
3. Define an NFA that recognizes the following language L over Σ = {a, b, c}: L = { w | w ends with abc or w ends
with abc }.
19
EXPERIMENT 6:
Aim: Study and minimize the DFA based on the Exercises
Theory:
The minimization algorithm works by identifying indistinguishable states and grouping them
into single states. Informally, two states are indistinguishable if their behavior with
transitions and acceptance is essentially the same. Formally, two states p and q are indistin
guishable if for every word w, the executions of w from p and q are both accepting states or
both non-accepting states. Two states are distinguishable if they are not indistinguishable.
For example, an accept state is distinguishable from a non-accept state since takes one to
accept and another to non-accept. Rather than con gurations of strings, we can discover
distinguishability with one symbol at a time. Thus if there are states p and q and a symbol a
such that a takes p and q to distinguishable states, then p and q are themselves distin
guishable. It turns out that the relation of indistinguishability is an equivalence relation. Thus
the minimization of a DFA is achieved by grouping the equivalence classes of states into
single states. We discuss two examples below.
Examples:
1. Minimize the following given DFA
20
2. Minimize the following given DFA
3. Minimize the following given DFA
21
EXPERIMENT 7:
Aim: Study CFG and Design CFG for the Languages given in the exercise.
Theory:
A Context Free Grammar(CFG) is a set of rewriting rules that produce patterns of strings.
A Context Free Grammar is described by a 4 tuple (V,T,P,S) where
 V is the set of variables.
 T is the set of terminals.
 P is the set of what are called productions and
 S is the start symbol of the grammar.
 A production is basically a substitution rule. It consists of a symbol and a string separated by an arrow.
 The symbol is called a variable.
 The string on the right side of the arrow consists of some variables and some other symbols that are called
terminals. A terminal is not allowed to be on the left side of an arrow for any of the rules. The terminals in
Context Free Grammar are analogous to the input alphabet in automata.
 One variable is called the start variable. Generally, that variable is denoted by S and generally while listing the
production rules, a rule with that variable on the left side is listed first.
Examples:
1.
Enter a context-free grammar that generates the following language L over the alphabet Σ = {a, b}:
L = { w | w contains at least two a symbols }
22
2. L = {strings that have the same number of 0s and 1s}
3.CFG for the language a mb n where m != n.
23
EXPERIMENT 8:
Aim: Study PDA and Design PDA for the given problems.
Theory:
A Pushdown Automaton(PDA) is similar to a non deterministic nite automaton with the
addition of a stack. A stack is simply a last in first out structure, easily visualized as a Pez
Dispenser or a stack of plates. The stacks in pushdown automata are allowed to grow
indefinitely and as a result of that, these machines can recognize languages that cannot be
recognized by NFAs. It is also provable that the set of languages de ned by PDA are exactly
the context free languages. Formally, a pushdown automata is defined as a 6-tuple (Q, ∑, Γ ,
δ, q0, F):
Q is a finite set of states
∑ is the alphabet of the language. Also a finite set.
Γ is the set of pushdown symbols (which can be pushed and popped from stack)
q0 is the initial state.
Z is the initial pushdown symbol (which is initially present in stack)
F is the set of final states (F ⊆ Q)
δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*. In a given state, PDA will
read input symbol and stack symbol (top of the stack) and move to a new state and change
the symbol of stack.
Exercise:
1. Build a PDA that recognizes the following language L1 ={ 0n12n |n>0} .
24
2. Build a PDA that recognizes the following language L1 ={ 0n1n |n>0}
3.
L = {w ∈ Σ ∗ |w is a palindrome of odd length}.
25
26
Download