Chomsky Normal Form
Muhammad Zeeshan khan Raheel Khan
Introduction
A useful form for dealing with context free grammars is the Chomsky normal form. This is a particular form of writing a CFG which is useful for understanding CFGs and for proving things about them. It also makes the parse
tree for derivations using this form of the CFG a binary tree.
Introduction
A special form of grammarsA grammar where every production is either of the
formA→BC or A→C(where A, B, C are arbitrary variables And can
arbitrary symbol).
Example:S → AS | aA → SA | b(If language contains ", then we allow S ! "where S is
start symbol, and forbid S on RHS.)
General Grammars
Production Rules Of the form A → B A is a string of terminals and variables B is a string of terminals and variables To apply a rule, replace any occurrence of A with the string
Chomsky Normal Form
Said to be Context free grammar.
..If a CFG has only productions of the form non-terminal A string of two non-terminals Or non-terminal A one terminal then the CFG is said to be in Chomsky Normal Form (CNF).
..Increment of terminal
Why is importamt
The key advantage is that in Chomsky Normal Form, every derivation of a string of n letters has exactly 2n − 1 steps.
Thus: one can determine if a string is in the language
by exhaustive search of all derivations.
Uses
Simplicity of proofs
There are plenty of proofs around context-free grammars, including reducibility and equivalence to automata. Those are the simpler the more restricted the set of grammars you have to deal with is. Therefore, normal forms can be helpful there.
Enables parsing
While PDAs can be used to parse words with any grammar, this is often inconvenient. Normal forms can give us more structure to work with, resulting in easier parsing algorithms.
As a concrete example, the CYK algorithm uses Chomsky normal form. Greibach normal form, on the other hand, enables recursive-descent parsing; even though backtracking may be necessary, space complexity is linear.
Proof ldea
Any context-free language is generated by a context-free grammar in Chomsky
PROOF IDEA We can convert any grammar G into Chomsky
normal form. The conversion has several stages wherein rules
that violate the conditions are replaced with equivalent ones that are satisfactory.
Simple explanation
If we can put a CFG into CNF, then we can calculate the “depth” of the longest branch of a parse tree for the derivation of a string.
A (parse tree)
B C
a
Steps for CNF
1. Remove λ- Productions 2. Remove Unit Productions 3. Remove Useless Symbols
Remove - Productions
Example : take A CFG S → ASB A → aAS | a |e B → SbS | A | bbNext we need to eliminate the " rules. Eliminating A →
e yields
S → ASB |SB A → aAS | a |aS B → SbS | A | bb | e
Remove Unit Productions
Now we have a new " rule., B → . Lets remove it S → ASB |SB |S|AS A → aAS | a |aS B → SbS | A | bb
Next we need to remove all unit rules. Lets begin by removing B→ A
S → ASB |SB |S|AS A → aAS | a |aS B → SbS | aAS | a |aS | bb now Where A is useless for the grammer..
. Remove Useless Symbols
Example: Let G beS → AB | a; A → b S and A are generating, B is not. If we eliminate B we have to eliminate because its non-generating
symbol so the grammar is S → a; A → b
Thank You
Kingsoft OfficeMake Presentation much more fun
Top Related