ATCD Mod 2
ATCD Mod 2
1
CONSTRUCTION OF A REGULAR GRAMMAR
GENERATING T(M) FOR A GIVEN DFA M
2
3
4
5
BASIC DEFINITIONS AND EXAMPLE of GRAMMAR
6
7
8
Find the Derivation of below Grammar
9
10
11
12
13
14
15
16
17
AMBIGUITY IN CONTEXT-FREE GRAMMARS
18
19
20
21
22
Construction of Reduced Grammar
23
24
25
26
27
28
29
Example-02
30
31
32
ELIMINATION OF NULL PRODUCTIONS
33
ELIMINATION OF UNIT PRODUCTIONS
34
Chomsky's Normal Form (CNF)
G1 = {S → AB, S → c, A → a, B → b} is in CNF
G2 = {S → aA, A → a, B → c} is not in CNF
35
Convert the given CFG to CNF. Consider the given
grammar G1:
S → a | aA | B
A → aBB | ε
B → Aa | b
36
Solution
S → a | aA | B
A → aBB
B → Aa | b | a
37
Step-2: Now, as grammar G1 contains Unit production S → B,
its removal yield:
S → a | aA | Aa | b
A → aBB
B → Aa | b | a
38
Step-03: In the production rule S → aA | Aa, A → aBB and B →
Aa, terminal a exists on RHS with non-terminals. So we will
replace terminal a with X:
S → a | XA | AX | b
A → XBB
B → AX | b | a
X→a
39
Step-04: In the production rule A → XBB, RHS has more than
two symbols, removing it from grammar yield:
S → a | XA | AX | b
A → RB
B → AX | b | a
X→a
R → XB
40
Example-02
41
42
Push Down Automata
43
tape
tape head
stack head
finite
stack
control
a l p h a b e t
50
Actions of the PDA
If δ(q, a, Z) contains (p, ) among its
actions, then one thing the PDA can
do in state q, with a at the front of
the input, and Z on top of the stack is:
1. Change the state to p.
2. Remove a from the front of the input
(but a may be ε).
3. Replace Z on the top of the stack by .
51
Example: PDA
Design a PDA to accept {anbn | n > 1}.
The states:
q0 = start state. We are in state q if we
0
52
Actions of the Example PDA
aaabbbε
q0
Z0
53
Actions of the Example PDA
aabbbε
q0
a
Z0
54
Actions of the Example PDA
abbbε
q0
a
a
Z0
55
Actions of the Example PDA
bbbε
q0
a
a
a
Z0
56
Actions of the Example PDA
bbε
q1
a
a
Z0
57
Actions of the Example PDA
bε
q1
a
Z0
58
Actions of the Example PDA
ε
q1
Z0
59
Actions of the Example PDA
qf
Z0
60
Example: PDA Cont…
The transitions:
δ(q0, a, Z0) = (q0, aZ0).
δ(q0, a, a) = (q0, aa).
δ(q , b, a) = (q , ε).
0 1
δ(q , b, a) = (q , ε).
1 1
61
State Machine of PDA
62
PDA for Odd Palindrome
63
PDA for Even Palindrome
64
CFG to PDA (If not in GNF)
65
CFG to PDA (If in GNF)
66
67
68
69
70
71
72
Closure Properties of CFL
• Union
• Concatenation
• Kleene Star operation
73
Union
74
Concatenation
75
Kleene Star
76