Вы находитесь на странице: 1из 15

NORMAL FORMS

Beulah A.
AP/CSE
Chomsky Normal Form (CNF)
2

 A context free grammar G is in CNF if every production


is of the form A→a or A→BC and S→λ is in G if
λ∈L(G). When λ is in L(G) we assume that S does not
appear on the R.H.S. of any other production.
Ex:
S → AB
S→λ
A→a
B→b
Beulah A. August 9, 2018
Theorem
3

 For every context free grammar, there is an


equivalent grammar in Chomsky Normal Form
(CNF)
 Proof:

Step 1 : Elimination of null productions. Let the


grammar thus obtained be G = (N, T, S, P).

Beulah A. August 9, 2018


Theorem
4

 Step 2 : Elimination of terminals on R.H.S. Define


G1 = (N1, T, S, P1) where P1 and N1 are constructed as
follows:
(i) All the productions in P of the form A → a or →BC are included
in P1. All the variables in N are included in N1.
(ii) Consider A → X1 X2 ..... Xn with some terminal on R.H.S. If Xi is a
terminal, say ai, add a new variable Cai to N1 and Cai → ai to P1. In
production A → X1 X2 ...... Xn, every terminal on R.H.S. is repaced
by the corresponding new variable and the variables on the R.H.S.
are retained. The resulting production is added to P1.
Thus we get G1 = (N1, T, P1, S).
Beulah A. August 9, 2018
Theorem
5

 Step 3 : Restricting the number of variables on R.H.S. For any


production in P1, the R.H.S. consists of either a single terminal (or
λ in S → λ) or two or more variables. We define G2 =(N2, T, P2, S)
as follows:
(i) All productions in P1 are added to P2 if they are in the required
form. All the variables in N1 are added to N".
(ii) Consider A → A1 A2..... Am, where m ≥ 3. We introduce new productions
A → A1D1, D1 → A2 D2, ...... Dm–2 → Am–1 Am,
and new variables D1, D2, ..... Dm–2. These are added to P2 and N2
respectively.
Thus we get G2 in Chomsky Normal Form.
Beulah A. August 9, 2018
Theorem
6

Step 4 : To complete the proof we have to


show that L(G) = L(G1) = L(G2).
To show that L(G) ⊆ L(G1), we start with w ∈
L(G). If A → X1X2..... Xn is used in the
derivation of w, the same effect can be achieved by
using the corresponding production in P1 and the
productions involving the new variables.
Hence A ⇒ ∗ X1 X2.....Xn. Thus L(G) ⊆ L(G1).

Beulah A. August 9, 2018


Greibach Normal Form (GNF)
7

 A context free grammar G is in GNF if every


production is of the form A→aα where α∈N* and
a∈Τ (α may be λ) and S→λ is in G if λ ∈ L(G),
where S does not appear on the RHS of any
production.
 Ex:

S → aAB | λ
A → bC
B→b
C → Beulah
c A. August 9, 2018
Theorem
8

 Every context free language L can be generated by a


context free grammar G in GNF.
 Step 1 :

Eliminate null productions and then construct a


grammar in G in CNF generating L.
Rename the variables as A1, A2,...... An with S = A1.
Write G as ({A1, A2,......An}, T, P, A1).

Beulah A. August 9, 2018


Theorem
9

 Step 2: Derive the productions of the form


Ai → aγ or
Ai → Ajγ, where j > i.
To obtain this convert the Ai productions (i=1,2, ... n-1)
to the form Ai → Ajγ such that j > i.

Beulah A. August 9, 2018


Theorem
10

 Step 3: Derive the productions of the form


Ai → aγ from Ai → Aiγ
To obtain this eliminate the left recursion

A  A 1 | ... | A m | 1 | ... | n where 1 ... n do not start with A


 eliminate immediate left recursion
A  1 | ... | n
A  1 B | ... | n B
B 1 | ... | m
B 1 B| ... | m B an equivalent grammar
Beulah A. August 9, 2018
Theorem
11

 Step 4: Modify Ai -productions to the form


Ai → aγ for i=1,2, ... n-1
 Step 5: Modify Bi - productions to the form

Bi → aγ

Beulah A. August 9, 2018


Summary
 Definition CNF , GNF

Beulah A. August 9, 2018


Test Your Knowledge
 The entity which generate Language is termed as:
a) Automata
b) Tokens
c) Grammar
d) Data
 The minimum number of productions required to
produce a language consisting of palindrome
strings over ∑={a,b} is
a) 3
b) 7 c) 5 d) 6
Beulah A. August 9, 2018
Test Your Knowledge
14

 The Grammar can be defined as: G=(V, ∑, p, S)


In the given definition, what does S represents?
a) Accepting State
b) Starting Variable
c) Sensitive Grammar
d) None of these

Beulah A. August 9, 2018


Reference
 Hopcroft J.E., Motwani R. and Ullman J.D,
“Introduction to Automata Theory, Languages and
Computations”, Second Edition, Pearson
Education, 2008

Beulah A. August 9, 2018

Вам также может понравиться