0% found this document useful (0 votes)
232 views22 pages

Lesson 26 - Chomsky Normal Form - Leftmost Derivation

1. Chomsky Normal Form (CNF) is a type of context-free grammar where all productions are of the form A->BC or A->a. Any context-free grammar can be converted to CNF. 2. A theorem states that a CFG in CNF will generate all non-null words of the original context-free language. 3. An example shows converting a sample CFG to CNF by removing null/unit productions and adding new productions.

Uploaded by

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

Lesson 26 - Chomsky Normal Form - Leftmost Derivation

1. Chomsky Normal Form (CNF) is a type of context-free grammar where all productions are of the form A->BC or A->a. Any context-free grammar can be converted to CNF. 2. A theorem states that a CFG in CNF will generate all non-null words of the original context-free language. 3. An example shows converting a sample CFG to CNF by removing null/unit productions and adding new productions.

Uploaded by

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

CS-317 Theory of Automata

Chomsky Normal Form and


Leftmost Derivation
By Aliza Qasim
Lecturer Computer Science
Recap lecture 35
Regular grammar, null productions and
examples, nullable productions and
examples, unit productions and example,
Chomsky Normal Form (Definition)
Chomsky Normal Form
Chomsky Normal Form (CNF): If a CFG has
only productions of the form
nonterminal → string of two nonterminals
or
nonterminal → one terminal
then the CFG is said to be in Chomsky Normal
Form (CNF).
Note
It is to be noted that any CFG can be
converted to be in CNF, if the null
productions and unit productions are
removed. Also if a CFG contains nullable
productions as well, then the corresponding
new production are also to be added. Which
leads the following theorem
Theorem
All NONNULL words of the CFL can be
generated by the corresponding CFG
which is in CNF i.e. the grammar in CNF
will generate the same language except
the null string.
Following is an example showing that a
CFG in CNF generates all nonnull words
of corresponding CFL.
Example
Consider the following CFG
S → aSa|bSb|a|b|aa|bb
To convert the above CFG to be in CNF,
introduce the new productions as
A → a, B → b, then the new CFG will be
S → ASA|BSB|AA|BB|a|b
A→a
B→b
Example continued …
Introduce nonterminals R1 and R2 so that
S → AR1|BR2|AA|BB|a|b
R1 → SA
R2 → SB
A→a
B→b
which is in CNF.
It may be observed that the above CFG which is in CNF
generates the NONNULLPALINDROME, which does not
contain the null string.
Example
Consider the following CFG
S → ABAB
A → a|⌃
B → b|⌃
Here S → ABAB is nullable production and A → ⌃, B
→ ⌃ are null productions. Removing the null
productions
A → ⌃ and B → ⌃, and introducing the new
productions as
S → BAB|AAB|ABB|ABA|AA|AB|BA|BB|A|B
Example continued …
Now S → A|B are unit productions to be eliminated
as shown below
S → A gives S → a (using A → a)
S → B gives S → b (using B → b)
Thus the new resultant CFG takes the form
S → BAB|AAB|ABB|ABA|AA|AB|BA|BB|a|b A
→a
B→b
Introduce the nonterminal C where C → AB, so that
Example continued …
S → BAB|AAB|ABB|ABA|AA|AB|BA|BB|a|b

A→a
B→b
C → AB
S → CC|BC|AC|CB|CA|AA|AB|BA|BB|a|b
is the CFG in CNF.
Task
Convert the following CFG to be in CNF
S → ABAB
A → a|⌃
B → b|⌃
Example
To construct an FA that accepts the grammar
S → abA
A → baB
B → aA|bb
The language can be identified by the three words
generated as follows
(i) S → abA
→ abbaB (using A → baB)
→ abba bb (using B → bb)
(ii) S → abA
→ abbaB (using A → baB)
→ abbaaA (using B → aA)
→ abbaabaB (using A → baB)
→ abbaababb (using B → bb)
(iii) S → abA
→ abbaB (using A → baB)
→ abbaaA (using B → aA)
→ abbaabaB (using A → baB)
→ abbaabaaA (using B → aA)
→ abbaabaabaB (using A → baB)
→ abbaabaababb (using B → bb)
Example continued …
which shows that corresponding language
has RE abba(aba)*bb. Thus the FA
accepting the given CFG may be

a
S- a b A b a B b b +
a
b b a
a a,b

a,b
Left most derivation
Definition: The derivation of a word w,
generated by a CFG, such that at each step, a
production is applied to the left most
nonterminal in the working string, is said to be
left most derivation.
It is to be noted that the nonterminal that
occurs first from the left in the working string,
is said to be left most nonterminal. Following
is an example
Example
Consider the following CFG
S → XY
X → XX|a
Y → YY|b
then following are the two left most
derivations of aaabb
Example continued …
S → XY S → XY
→ XXY → XXY
→ aXY → XXXY
→ aXXY → aXXY
→ aaXY → aaXY
→ aaaY → aaaY
→ aaaYY → aaaYY
→ aaabY → aaabY
= aaabb = aaabb
Theorem
Any word that can be generated by a certain CFG has also
a left most derivation.
It is to be noted that the above theorem can be stated for
right most derivation as well.
Example: Consider the following CFG
S → YX
X → XX|b
Y → YY|a
Following are the left most and right most derivations
of abbbb
Example continued …
S → YX S → YX
→ aX → YXX
→ aXX → YXb
→ abX → YXXb
→ abXX → YXbb
→ abbX → YXXbb
→ abbXX → YXbbb
→ abbbX → Ybbbb
= abbbb = abbbb
A new format for FAs
A class of machines (FAs) has been discussed
accepting the regular language i.e.
corresponding to a regular language there is a
machine in this class, accepting that language
and corresponding to a machine of this class
there is a regular language accepted by this
machine. It has also been discussed that there
is a CFG corresponding to regular language
and CFGs also define some nonregular
languages, as well
A new format for FAs contd. …
There is a question whether there is a class of
machines accepting the CFLs? The answer is
yes. The new machines which are to be defined
are more powerful and can be constructed with
the help of FAs with new format.
To define the new format of an FA, the
following are to be defined
Summing Up
• Chomsky Normal Form, Theorem regarding
CNF, examples of converting CFG to be in
CNF, Example of an FA corresponding to
Regular CFG, Left most and Right most

You might also like