Lesson 26 - Chomsky Normal Form - Leftmost Derivation
Lesson 26 - Chomsky Normal Form - Leftmost Derivation
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