You are on page 1of 5

Removal of unit production:

A->B where A and B are non-terminals


1. To remove A-> B add production A-> x to grammar whenever B->x
occurs in the grammar(x belongs to terminal).
2. Delete A->B from grammar.
Removal of null productions:
A->ep
1. To remove A->ep look for productions whose right side contains A
2. Replace each occurrence of A in each of these productions with ep.
3. Add the resultant productions to the grammar.
Chomsky Normal form:
In CNF we have restriction on length of RHS which is elements in RHS should be
two non-terminals or one terminal or an epsilon.
A->a
A->BC
A->ep(epsilon)
Where a is terminal and A,B,C are non-terminals.

Step 1: If the start symbol S occurs on some right side, create a new start
symbol S’ and a new production S’ → S.
Step 2: Remove Null productions.
Step 3: Remove unit productions.
Step 4: Replace each production A → B1...Bn where n > 2 with A → B1 C where
C → B2 ...Bn. Repeat this step for all productions having two or more symbols
in the right side.
Step 5: If the right side of any production is in the form A→ aB where a is a
terminal and A, B are non-terminal, then the production is replaced by A→XB
and X→
S->ASA| aB
A->B | S
B-> b | ep

S’-> XA| YB | a | AS | SA
X->AS
Y->a
S->XA| YB | a | AS | SA
A->b | XA| YB | a | AS | SA
B-> b

S’-> XB | SB | AS
X->AS
Y->a
Z->b
P->SZ
S->XB | SB | AS
A->YX | a | YS
B->PS | YX | a | YS | ZZ
Greibach Normal Form
Step 1 If the start symbol S occurs on some right side, create a new start
symbol S’ and a new production S’ → S.
Step 2 Remove Null productions. (Using the Null production removal algorithm
discussed earlier)
Step 3: Remove unit productions. (Using the Unit production removal
algorithm discussed earlier)
Step 4:Remove all direct and indirect left-recursion.
Step 5 Do proper substitutions of productions to convert it into the proper
form of GNF.
S-> CA | BB
B->b | SB
C->b
A->a

S->A1
C->A2
A->A3
B->A4

A1->bA3 | b A4| bA3A4A4 | bZA4 | bA3A4Z


A4->b | bA3A4 | bZ | bA3A4Z
Z-> bA4Z | bA3A4A4Z | bZA4Z | bA3A4ZA4Z | bA4 | bA3A4A4 | bZA4 | bA3A4ZA4

A2-> b
A3->a
Pumping lemma for regular languages
Is used to prove that a language is not regular.
It can not be used to prove a regular language.
If A is a regular language it has a pumping length p such that any string S where
|S| >=p maybe divided into 3 parts S=x y z such that the following conditions
must be true.
1. Xy^iz belongs to A for i>=0.
2. |y| >0.
3. |xy|<=p.
L={ anbn | n>=1} is regular ani anko
P=5 S=aa aaa bbbbb
aa aaa aaa bbbbb not belongs to L. so case 1 failed.
P=4 S= aaaabbbb
I=3 after pumping
Aaaa bbbbbb bb not belongs to L.
P=4 S=aaa aabb bb
I=2 aaa aabb aabb bb not possible.
So from the above 3 cases it is evident that L is pakka not regular.
Pumping lemma for CFL
Is used to prove that a language is not cfl.
It can not be used to prove a CFL.
If A is a CFL it has a pumping length p such that any string S where |S| >=p
maybe divided into 5 parts S=uvx y z such that the following conditions must
be true.
1. Uv^ixy^iz belongs to A for i>=0.
2. |vy| >0.
3. |vxy|<=p.
L={an bn cn \n>=1} i=2
P=4 aa aaaa bb bbcbbc ccc not belongs to L
Turing machine
L={an bn | n>=1} xxxyyy
Q0-> q1(a,x\r)
Q1->q1(a,a/r
Y,y\r)
Q2(b,y,L)
Q2->q2(a,a\l)
Q2(y,y\l)
Q0(x,x\r)
Q0-> q3(y,y\r)
Q3->q3(y,y\r)
Qf(B,B/r)
A1->aA3A4A3 | aA4A3 | aA3A4 | aA4| bA3 | bA4A3| aA3A3 | aA3 | bA4 | b
A2->aA3A4 | aA4
A6->a
A5->b
A3->aA3 | a
A4-> bA4 |b
S->A1
X->A2
A->A3
B->A4
Z->A5
Y->A6
8) S-> AA
A-> abB | b |bb | BB
B-> abB | b | bb

You might also like