0% found this document useful (0 votes)
61 views3 pages

CNF N GNF

The document discusses the conversion of context-free grammars into Chomsky Normal Form (CNF) and Greibach Normal Form (GNF). It outlines the necessary steps and conditions for transforming grammars, including the removal of certain production forms and the introduction of new variables. Theorems and examples illustrate the equivalence of grammars before and after conversion to these normal forms.

Uploaded by

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

CNF N GNF

The document discusses the conversion of context-free grammars into Chomsky Normal Form (CNF) and Greibach Normal Form (GNF). It outlines the necessary steps and conditions for transforming grammars, including the removal of certain production forms and the introduction of new variables. Theorems and examples illustrate the equivalence of grammars before and after conversion to these normal forms.

Uploaded by

betab18752
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

24.

Use the result of the preceding exercise to rewrite the grammar ----:­
E)(O mple6.7
A -> Aa laBel >', The grarumar
B -> Bblbe S -> ASia ,
A --> SA lb
so that it no longer has productions of the form A ......, Ax or B -> Bx
is in Chomsky normal form. The grammar
*25. Prove the following counterpart of Exercise 23 . Let the set of productions
involving the variable A on the left be divided into two disjoint subsets S -- ASIAAS,
A......, xlA IX2AI·· 'l x nA A --> SAlaa
and is not; both prod uctions S -- AAS and A --> aa violate the conditions of
A......, Yl IY21·· ·IYm,
where A is not a suffix of any Yi . Show that the grammar obtained by
Definition 6.4.

replacing these productions with
Theorem 6.6
A......, Yi IZYi, i = 1, 2, ... ,m,
Any context-free grammar 0 = (V, T, S, P) with A ¢ L (0) has an equiva­
Z -+ xilZXi, i = 1,2, .. . ,n,
lent grammar G= (ii,T,s, p) in Chomsky normal form.
is equiva1ent to the original grammar .
proof: Because of T heorem 6.5 , we can assume without loss of generality
that G has no A-product ions and no unit-productions. The construction of
6.2 Two Important Normal Forms Gwill be done in two steps.
There are many kinds of normal forms we can establish for context-free Step 1: Construct a gramm ar 0 = (VI, T , S, PI) from 0 by considering all
1
grammars. Some of these , because of their wide usefulness, have been stud· productions in P in the form
ied extensively. We consider two of them briefly.
A --+ '/' 1.1' 2'" Tn (G .;; )

Chomsky Normal Form where each X i is a symbol either in V or in T . If n = 1, then Xl must be a


terminal since we have no unit-productions. In this case, put the production
One kind of normal form we can look for is one in which the number of
into Pl . If n ~ 2, introduce new variables Ba for each a E T. For each
symbols on the right of a production is strictly limited. In particular, we
production of P in t he form (6 .5) we put into PI the production
can as.k that the string on the right of a production consist of no more than
two symbols. O ne instance of this is the Chomsky normal form.
. \ -> (\ C~ · · · C" .
where
Definition 6.4
C, = .r ; il ,!', is in ~ '.
A context-free grammar is in Chomsky normal form if all productions are
of the form and

A -- BC ('j = B" if' .1'1 = 1/ .


or For every B a we also put into P 1 the production
/1......, a,
B" -> a.
where A, B , C are in V, and a is in T . ~his part of the algorithm removes all terminals from productions whose
nght side has length greater t.han one, replacing them with newly int rouuced
o.~ ~ Y,'V J,.~"J.J. ...., ... ........ . ' - ­
•_ _ •. __ ~ __ .. __ .. ~ .. ....... ~ • ........ ................. ~" .I. i:.th t.-.1.' a .c.J':' '-TI\..f\1VUVIJ<\'K~ /\NU ...

variables. At the end of this step we have a grammar As required by the construction of Theorem 6.6, the grammar does not
productions have the form • nT'ly A_productions or any unit-productions.
haveInOJ.',Step 1. we .mtroduce new vanables
. Ba. Bb, Be and use the algorithm
A -> a. (6.6)
to get
or S -> ABBa,
A --+ BaBaBb,
B -4 ABc,
A -... CIC~·· · Gil' (6.7)
Ba --+ a,
where Ci E Vj . Bb -4 b,
It is an easy consequence of Theorem 6.1 that Bc -4 C.

L caJl = L (G) In the second step, we introduce additional variables to get the first two
productions into normal form and we get the final result
Step 2: In the second step, we introduce additional variables to reduce the S --+ AD j ,

length of the right sides of the productions where necessary. First we put Dl --+ BBa.
all productions of the form (6.6) as well as all the productions of the form
A --+ BaD2'
(6.7) with n = 2 into P. For n > 2, we introduce new variables D 1 ,D2 , . ..
D2 -4 BoBb,
and put into P the productions
B -4 ABc,
A ....... C1D 1 , Ba - 4 a,
D\ -': C'2D2, Bb - 4 b,
Be - 4 C.
D" '2 - Cn-Ien ' •
ObViously, the resulting grammar C is in Chomsky normal form. Repeated Greibach Normal Form
applications of Theorem 6.1 will show that L (G 1) = L so that (C) , Another useful grammatical form is the Greibach normal form. Here
we put restrict ions not on the length of the right sides of a. production,
L (C) = L (G). but on the positions in which terminals and variables can appear. Argu­
ment.s justifyi ng Greibach normal form are a little complicated and not very
This somewhat informal argument can easily be made more precise. We transparent . Similarly, constructing a grammar in Greibach normal form
equivalent to a given cont.ext-free grammar is tedious. We therefore deal
will leave this to the reader. •
with this matter very briefly. Nevertheless, Greibach normal form has many
theoretical and practical consequences.

Example 6.8 Def.niti on 6.5


Convert the grammar with productions A context-free grammar is said to be in Greibach normal form if all pro­
dUctions have t.he form
S -4 ABa,
A --+ ax,
A --+ aab ,
B --+ Ac Where a E T and x E 1l"'.

to Chomsky normal form.


168 Chapter 6 S IMPLIFICATlON OF CON T E XT-FREE GRAMMARS AND ... 6.2 T wo lMPORTA NT N ORMAL l:'ORMS lo~

If we compare this with Definition 5.4, we see that the form A ....... a:t We int.rod uce Greibach normal form here because it will simplify the t ech­
is common to both Greibach normal form and s-grammars, but Greibach 'cal discllssion of an important result in the next chapter. However, from
normal form does not carry the restriction that the pair (A. , a) occur at mOst :lcOllceptual viewpoint , Greibach norrr:al form plays no fu:ther role in our
once. This additional freedom gives Greibach normal form a generality not discUssion. so we only quote the followmg general result Without proof.
possessed by s-grammars.
If a grammar is not in Greibach normal form, we may be able to rewrite Theorem 6.7
it in this form with some of the techniques encountered above. Here are two
For eV€'ry cont ext-free grammar G with'\ ¢:. L (G) , there exists an equivalent
simple examples.
G in Greibach normal form .
Example 6.9
The grammar
grammar
----
S --.. AB , EI ERCISES
A --.. aA IbB I b,
1. Provide t he det a ils of the proof of Theorem 6.6.
B --.. b
;/ Convert t he grammar 5 --Co a5blab into Chomsky normal form.
is not in Greibach normal form. However, using the substitution given by
3. 1Iansform the grammar 5 ---> a5aAIA, A ---> abAlb into Chomsky normal
Theorem 6.1, we immediately get the equivalent grammar
form . '.
S --.. aAB IbBBI bB, 4. Transform t he grammar with productions
A --.. aA IbBI b, 5 ---> abAB,
B --.. b, A --; bABIA,
which is in Greibach normal form . B ---> BAa IAI A
I~omsky normal form.
oovert t he grammar
Example 6. 10 5 -; ABlaB ,
Convert the grammar A ---> a.a.bl A,
B -; bbA
S --.. abSblaa
inlo Chomsky normal form. 5
into Greibach normal form.
6. Let G = (V, T , 5, P) be any context-free grammar without any A-productions
Here we can use a device similar to the one introduced in the con­
or un it-productions. Let k be the maximum number of symbols on the right of
struction of Chomsky normal form. We introduce new variables A and B auy production in P. Show that there is an equivalent grammar in Chomsky
that are essentially synonyms for a and b, respectively. Substituting for the normal form wit h no more than (k - 1) !PI + ITI production rules.
terminals with their associated variables leads to the equivalent grammar
7 Draw the dependency graph for t he grammar in Exercise 4.
S --.. aBSBlaA , 8. A linear language is one for which there exists a linear grammar (for a def­
A --.. a, inition. see Example 3.14). Let L be any linear language not containing A.
Show that there exists a grammar G = (V, T , 5 , P ) all of whose productions
B --.. b, have one of the forms

which is in Greibach normal form. _ A -. aB,


A. ---> Ba,
A ~ a,
In general, though , neither the conversion of a given grammar to Greibacb
normal form nor the proof that this can always be done is a simple matter. w~ere a E T, A , BE 11, such that L = L (G). 5

You might also like