5 views

Uploaded by OsamaKhalid

q

- lottolg
- MD_1.pdf
- k Means Java Ex1
- Dynamic Actions
- Context Free Grammars Normal
- Lecture-Countif Sumif
- Brochure
- 117
- Chatbot conversation design
- Lexical Analysis
- cvim hotkeys
- Appendix E CASF Algorithm
- E-Commerce Lecture 13
- The Ring programming language version 1.5.1 book - Part 90 of 180
- Duplicate
- A Company Makes Three Products and Has Available 4 Workstations
- The Ring programming language version 1.5.3 book - Part 101 of 184
- Gamification Critical Approaches
- Python Project File
- Nested Loop

You are on page 1of 4

Dave Bacon

Department of Computer Science & Engineering, University of Washington

A useful form for dealing with context free grammars is the Chomksy 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. And as a CS major, I know you really love binary trees!

So what is Chomsky normal form? A CFG is in Chomsky normal form when every rule is of the form A BC

and A a, where a is a terminal, and A, B, and C are variables. Further B and C are not the start variable.

Additionally we permit the rule S where S is the start variable, for technical reasons. Note that this means that

we allow S as one of many possible rules.

Okay, so if this is the Chomsky normal form what is it good for? Well as a first fact, note that parse trees for a

derivation using such a grammar will be a binary tree. Thats nice. It will help us down the road. Okay, so if it might

be good for something, we can ask the natural question: is it possible to convert an arbitrary CFG into an equivalent

grammar which is of the Chomsky normal form? The answer, it turns out, is yes. Lets see how such a conversion

would proceed.

The first step is simple! We just add a new start variable S0 and the rule S0 S where S is the original start

variable. By doing this we guarantee that the start variable doesnt occur on the right hand side of a rule.

Next we remove the rule. We do this as follows. Suppose we are removing the rule A . We remove this rule.

But now we have to fix the rules which have an A on their right-hand side. We do this by, for each occurrence of A

on the right hand side, adding a rule (from the same starting variable) which has the A removed. Further if A is the

only thing occurring on the right hand side, we replace this A with . Of course this latter fact will have created a

new rule. So we do this unless we have previously removed A . But onward we press: simply repeat the above

process over and over again until all rules have been removed.

For example, suppose our rules contain the rule A and the rule B uAv where u and v are not both the

empty string. First we remove A . Then we add to this rule the rule B uv. (Make sure that you dont delete

the original rule B uAv. If, on the other hand we had the rule A and B A, then we would remove the

A and replace the rule B A with the rule B . Of course we now have to eliminate this rule via the same

procedure.

Next we need to remove the unit rules. If we have the rule A B, then whenever the rule B u appears, we will

add the rule A u (unless this rule was already replaced.) Again we do this repeatedly until we eliminate all unit

rules.

At this point we have converted our CFG to one which has no transitions, and where all rules are either of the

form variables goes to terminal, or of the form variable goes to string of variables and terminals with two or more

symbols. These later rules are of the appropriate Chomsky normal form. To convert the remaining rules to proper

form, we introduce extra variables. In particular suppose A u1 u2 . . . un where n > 2. Then we convert this to a

set of rules, A u1 A1 , A1 u2 A2 , . . ., Ak2 uk1 uk . Now we need to take care of the rules with two elements

on the right hand side. If both of the elements are variables, then we are fine. But if any of them are terminals, we

2

add a new variable and a new rule to take care of these. For example, if we have A u1 B where u1 is a terminal,

then we replace this by A U1 B and U u1 .

S ASB

A aAS|a|

B SbS|A|bb

S0 S

S ASB

A aAS|a|

B SbS|A|bb

S0 S

S ASB|SB

A aAS|a|aS

B SbS|A|bb|

S0 S

S ASB|SB|S|AS

A aAS|a|aS

B SbS|A|bb

S0 S

S ASB|SB|S|AS

A aAS|a|aS

B SbS|bb|aAS|a|aS

S0 S

S ASB|SB|AS

A aAS|a|aS

B SbS|bb|aAs|a|aS

S0 ASB|SB|AS

S ASB|SB|AS

A aAS|a|aS

B SbS|bb|aAs|a|aS

3

Now we need to take care of the rules with more than three symbols. First replace S0 ASB by S0 AU1 and

U1 SB:

S0 AU1 |SB|AS

S ASB|SB|AS

A aAS|a|aS

B SbS|bb|aAs|a|aS

U1 SB

Next eliminate S ASB in a similar form (technically we could reuse U1 , but lets not):

S0 AU1 |SB|AS

S AU2 |SB|AS

A aAS|a|aS

B SbS|bb|aAs|a|aS

U1 SB

U2 SB

Onward and upward, now fix A aAS by introducing A aU3 and U3 AS.

S0 AU1 |SB|AS

S AU2 |SB|AS

A aU3 |a|aS

B SbS|bb|aAs|a|aS

U1 SB

U2 SB

U3 AS

Finally, fix the two B rules:

S0 AU1 |SB|AS

S AU2 |SB|AS

A aU3 |a|aS

B SU4 |bb|aU5 |a|aS

U1 SB

U2 SB

U3 AS

U4 bS

U5 AS

Finally we need to work with the rules which have terminals and variables or two terminals. We need to introduce

new variables for these. Let these be V1 a and V2 b:

S0 AU1 |SB|AS

S AU2 |SB|AS

A V1 U3 |a|V1 S

B SU4 |V2 V2 |V1 U5 |a|V1 S

U1 SB

U2 SB

U3 AS

U4 V2 S

U5 AS

V1 a

V2 b

4

A quick examination shows us that we have ended up with a grammar in Chomsky normal form. (This can, of course,

be simplified.)

- lottolgUploaded byYufeng Tong
- MD_1.pdfUploaded byMariaRotaru
- k Means Java Ex1Uploaded bySorin Marian Topala
- Dynamic ActionsUploaded bysrinivasabhargava
- Context Free Grammars NormalUploaded byghoshtapan4321
- Lecture-Countif SumifUploaded byArya Bhatt
- BrochureUploaded bySamarth
- 117Uploaded byMiroslav Misa Miskovic
- Chatbot conversation designUploaded byLekha A
- Lexical AnalysisUploaded byChanda Sibala
- cvim hotkeysUploaded byMalka Ravikrishna
- Appendix E CASF AlgorithmUploaded bySebastian Astorquiza Trucco
- E-Commerce Lecture 13Uploaded byfaisal
- The Ring programming language version 1.5.1 book - Part 90 of 180Uploaded byMahmoud Samir Fayed
- DuplicateUploaded byvijaybhaskarsetty
- A Company Makes Three Products and Has Available 4 WorkstationsUploaded byVignesh Ayyathurai
- The Ring programming language version 1.5.3 book - Part 101 of 184Uploaded byMahmoud Samir Fayed
- Gamification Critical ApproachesUploaded bykrem_poetyczny
- Python Project FileUploaded byChandan
- Nested LoopUploaded byJohn Alex Blancaflor
- computer programmingUploaded byapi-306044573
- EJEMPLO RDF.txtUploaded bymigrapser4653
- order of operation.pdfUploaded bybabyu1
- Asignment_1Uploaded byDhinesh Raman
- EqualizerUploaded byajkdjkjk
- AIMP3_MemoryManager_EventLogUploaded byAli Sinan
- FlockUploaded byduranrose
- sun_certifiedUploaded byAnusha Anil Kumar
- Export ArUploaded bysamuel
- url to dorkUploaded bybqbi kau

- Lect 012616Uploaded byOsamaKhalid
- PalestineUploaded byOsamaKhalid
- YamaguchiUploaded byOsamaKhalid
- Graham AE 2011Uploaded byOsamaKhalid
- budka_contemporary.pdfUploaded byOsamaKhalid
- میں نے اس سے یہ کہاUploaded byOsamaKhalid
- Analysis Gender Bias (12)Uploaded byOsamaKhalid
- python quick reference cardUploaded bySérgio Luiz Araújo Silva
- eisenstein-nlp-notes.pdfUploaded byOsamaKhalid
- To Love or Not to LoveUploaded byOsamaKhalid
- Write UpUploaded byOsamaKhalid
- Ling Anth SyllabusUploaded byOsamaKhalid
- Rejection OxfordUploaded byOsamaKhalid
- Community Detection in GraphsUploaded byOsamaKhalid
- Commercial Tomato Production HandbookB 1312_4 (2)Uploaded byOsamaKhalid
- SwearUploaded byOsamaKhalid
- budka_contemporary.pdfUploaded byOsamaKhalid
- Rejection UoAUploaded byOsamaKhalid
- Performance Modeling and Design of Computer systems: Queueing Theory in ActionUploaded byOsamaKhalid
- List-5EF36618-93D1-6088-E0BB-010CB1ADB5ABUploaded byOsamaKhalid
- Anjaria Street Hawkers and Public Space in MumbaiUploaded byquan5287
- BookUploaded byDebashis Ghosh
- Article 9Uploaded byOsamaKhalid

- legmedUploaded byShishi Cruz De Leon
- Hills Like White ElephantsUploaded bySimion Nechifor
- 1-s2.0-S1877705811051113-main.pdfUploaded byHabibie Rahman
- Lenovo b5400 user manualUploaded bysanskbn
- Horizon II Macro AC OutdUploaded byalexflex93
- coherentUploaded byNick Papas
- Linn 104Uploaded byWorse To Worst Satittamajitra
- Copeland Compressors Info & Cross ReferenceUploaded byDaveEger
- Scheduling Job Shop- A CasestudyUploaded byabbas6063
- Renew EnergyUploaded byCheku Dojee
- dairy technology updateUploaded bysubhendujena
- Kingston-Irish-Tunebook.pdfUploaded byJoedi Santos
- Geostatistical Design of Infill Drilling ProgramsUploaded byminerito2211
- LOTO Template_Core From Project Sales CorpUploaded byProject Sales Corp
- Channel SwitchingUploaded byHazem Ahmed Maher
- Taurus Pistol ManualUploaded byematlis
- Digital Forensics Evidence Mining Tool 488Uploaded byUbiquitous Computing and Communication Journal
- 3D Solutions BrochureUploaded byJesús Sánchez
- Crystal BryanUploaded bylubnahl
- Why Use MPC Based Contact for _Bonded_ Connections_ _ CAE AssociatesUploaded byAnush Jk
- C5 TAHAP 2 NORAIDAHUploaded byMohd Zainal Sappari
- Advanced Logistics and Supply Chain ManagementUploaded byDiogo Estevao
- chpter 1 principle of managementUploaded bykhairunnisa
- Cloud Computing Military ContextUploaded byRaj Kumar
- Grandfathers-Gift.epubUploaded byDezső Szabó
- IBM SPSS Statistics Core System Users GuideUploaded bySelam Hulgize
- 3gpp StandardUploaded bykamalntc
- Writing Style GuideUploaded bypompatet
- What is Hair Line.pdfUploaded byAnjum Malik
- The Real Guru - Swami Ramsukdas jiUploaded byGita Press,GitaPrakashan,GitaVatika Books