Chomsky by zeeshan khan and Raheel Khan
-
Upload
m-khan -
Category
Technology
-
view
62 -
download
1
description
Transcript of Chomsky by zeeshan khan and Raheel Khan
![Page 1: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/1.jpg)
Chomsky Normal Form
Muhammad Zeeshan khan Raheel Khan
![Page 2: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/2.jpg)
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.
![Page 3: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/3.jpg)
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.)
![Page 4: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/4.jpg)
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
![Page 5: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/5.jpg)
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
![Page 6: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/6.jpg)
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.
![Page 7: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/7.jpg)
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.
![Page 8: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/8.jpg)
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.
![Page 9: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/9.jpg)
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
![Page 10: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/10.jpg)
Steps for CNF
1. Remove λ- Productions 2. Remove Unit Productions 3. Remove Useless Symbols
![Page 11: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/11.jpg)
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
![Page 12: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/12.jpg)
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..
![Page 13: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/13.jpg)
. 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
![Page 14: Chomsky by zeeshan khan and Raheel Khan](https://reader036.fdocuments.us/reader036/viewer/2022082804/5492438eac795959288b4733/html5/thumbnails/14.jpg)
Thank You
Kingsoft OfficeMake Presentation much more fun