0% found this document useful (0 votes)
28 views18 pages

Normal Form

The document discusses normal forms in context-free grammars (CFG), specifically Chomsky Normal Form (CNF), which simplifies CFGs by standardizing productions. It outlines the processes of eliminating useless symbols, ε-productions, and unit productions to achieve CNF. Several examples illustrate the transformation of grammars into CNF and the elimination of undesired productions.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views18 pages

Normal Form

The document discusses normal forms in context-free grammars (CFG), specifically Chomsky Normal Form (CNF), which simplifies CFGs by standardizing productions. It outlines the processes of eliminating useless symbols, ε-productions, and unit productions to achieve CNF. Several examples illustrate the transformation of grammars into CNF and the elimination of undesired productions.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

NORMAL FORM

-CNF
-GNF
Normal Forms:
Ambiguity is one undesirable property of a CFG that we
might wish to eliminate.
The ways of improving a grammar without changing the
resultant language.

First by eliminating certain types of productions.

Then by standardizing the productions, so that they all have


a certain “Normal form”.

1) Eliminate the production with awkward to write


2) Standardizing the production
Chomsky Normal Form:
When working with CFG, it is often convenient to have them in
simplified form. One of the simplest and most useful forms is called
the CNF.

Def:
A CFG is in CNF if every rule is of the form
NT string of exactly 2 NT
NTone terminal

Eg:
ABC
Aa
Where a is any terminal and A,B and C are any variable except that B
and C may not be the start variable.
In addition we permit the rule Sε , where S is the start variable.
CNF:
• We eliminate useless symbols. Those variables or terminals that
do not appears in any derivation of a terminal string from the start
symbol.
• We must eliminate ε-productions, those of the form X ε for
some variable X.
• We must eliminate unit production, those of the form XY for
variables x and Y.

Eliminating Useless Symbols:


I. Identified non-generating symbols in given CFG and
eliminate those productions which contains non-
generating symbols.
II. Identify non-reachable symbols in grammar and
eliminate those productions which contain non-
reachable symbols.
Ex:1
G=( { S,A,B}, {a,b}, P, S) where S is the start symbol and P is,
SbA/aB
AbAA/aS/a
BaBB/bS/b

Solu:
First production we have to replace terminal ‘b’ by a NT say
Cb and ‘a’ by Ca hence grammar becomes
S CbA/ CaB
A CbAA/ CaS/a
Ca a
Cbb
B CaBB/ CbS/b
First Production in CNF
S CbA/ CaB
Ca a
Cbb
Production in CNF
Second production is not in CNF S CbA/ CaB
A CbAA/ CaS/a A CbD/ CaS/a
A CbD/ CaS/a B CaE/ CbS/b
DAA Ca a
Cbb
Third production is not in CNF DAA
B CaBB/ CbS/b EBB
B CaE/ CbS/b
EBB
Ex:2
S1A/0B
A1AA/0S/0
B0BB/1
Solu:
SC1A/C0B
AC1Ca/ C0S/0
C11
C00
Ca AA
Cb BB
Ex:3
Sa
Sb
SCSS

Solu:
Sa
Sb
SCD
DSS
Ex:4
SabSb/a/aAb
Step 3
AbS/aAAb SCD/a/XaBb
Solu: AXbS/BaBb
SabSb/a/aBb BaXaA
AbS/BaBb
BbAXb
BaaA
BbAb Cab
DSXb
Step:2 Xaa
SCD/a/aBb Xbb
AbS/ BaBb
BaaA
BbAb
Cab
DSb
Ex:5 Step:2
SbA/aB SCbA/CaB
AbAA/aS/a
ADA/CaS/a
BaBB/bS/b
BEB/CbS/b
Solu: Cbb
SCbA/CaB Caa
ACbAA/CaS/a DCbA
BCaBB/CbS/b ECaB
Cbb
Caa
To Eliminate ε-Production:
To eliminate ε-Productions from a grammar G, we use the following
techniques

If A ε is a production to be eliminated then we look for all


productions, whose right side contains A, and replace each
occurrence of A in each of these productions to obtain the non ε -
productions to be added to the grammar to keep the language
generated the same.
Eg:
Consider the following grammar
SaA
Ab/ ε

Solu:
SaA
Sa
Ab
Ex:2
SABAC
AaA/ ε
BbB/ ε
Cc

List of production whose right side contain A,


SABAC
AaA
Therefore
SABC/BAC/BC
Aa
Add these productions to the grammar and eliminate A ε
to obtain following grammar
SABAC/ABC/BAC/BC
AaA/a
BbB/ ε
Cc
Now Eliminate Bε
SAAC/AC/C
Bb
Add these productions to the grammar and eliminate Bε from the
grammar to obtain

SABAC/BAC/ABC/BC/AAC/AC/C
AaA/a
BbB/b
Cc
Exercise:3
SAB Eliminate Bε
AaAA/ε SAB/B
BbBB/ε BbBB
Solu:
It derives
Eliminate Aε
SAB SA
AaAA BbB/b
The production derives
SB Therefore
AaA/a SAB/B/A
AaAA/aA/a
Therefore
SAB/B BbBB/bB/b
AaAA/aA/a
BbBB/ε
Removal of UNIT Production:
A production of the form
NT one NT
i.e, production of the form AB is called unit production
Algorithm:
Removal of unit productions
While (there exist a unit production, AB)
{
Select a unit production AB, such that there exists a production
Bα , where α is a terminal.

For(every non-unit production B α)

Add production A α to the grammar

Eliminate AB from the grammar


}
Ex:
Consider CFG
SAB
Aa
BC/b
CD
DE
Ea
Remove the unit production
Solu:
Consider 3 Unit productions
BC, CD, DE

Now to remove unit production BC , we see if there exists a


production whose left side has ‘C’ and right side contains a terminal
(i.e, Ca), but there is no such productions in G.
Similar things holds for production CD
Now, we try to remove unit production DE, because there is a
production Ea
Therefore Eliminate DE and introduce Da, grammar becomes
SAB
Aa
BC/b
CD
Da
Ea

Now we can remove CD by using Da, we get


SAB
Aa
BC/b
Ca
Da
Ea
Similarly , we can remove BC by using Ca, we obtain
SAB
Aa
Ba/b
Ca
Da
Ea

Now it can be easily seen that productions Ca, Da, Ea are useless
because if we start deriving from S, these productions will never be
used.
Hence eliminating them gives,
SAB
Aa
Ba/b
Which is completely reduced grammar

You might also like