q

© All Rights Reserved

5 views

q

© All Rights Reserved

- btcspinner baru
- SAP BW - Virtual Characteristic (Multiprovider & Infoset) - RSR_OLAP_BADI
- Programmatically Closing Your ABAP WebDynpro Application _ SAP Blogs
- syserr
- computer science Course A
- Frequency Counter
- sysmenu
- Sols 5
- engineering-information-sciences-game-and-simulation-programming-guide
- AUTOMATA
- Dynamic Dropdown List in abap sap
- fischer
- Calculator
- Kodingan Rama
- LRandLALRconflict
- bsc prac
- Sem 6 Project
- Chapter 02_Application Server Files
- p2
- Post Movement Journal

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.)

- btcspinner baruUploaded byDidin Syaifuddin Guret
- SAP BW - Virtual Characteristic (Multiprovider & Infoset) - RSR_OLAP_BADIUploaded byAbdul Malik
- Programmatically Closing Your ABAP WebDynpro Application _ SAP BlogsUploaded byabhi
- syserrUploaded byMihai Si Andreea
- computer science Course AUploaded byAli Jdeed
- Frequency CounterUploaded byGaurav Arora
- sysmenuUploaded byAnjani Kunwar
- Sols 5Uploaded byMainak Bhowmik
- engineering-information-sciences-game-and-simulation-programming-guideUploaded byapi-325297075
- AUTOMATAUploaded byKshitijKumarSingh
- Dynamic Dropdown List in abap sapUploaded byAnil Kumar Naidu Neegineni
- fischerUploaded byDemang Sintok
- CalculatorUploaded byMboowa Yahaya
- Kodingan RamaUploaded byhermainaputri
- LRandLALRconflictUploaded bysweettani
- bsc pracUploaded bySadhi Kumar
- Chapter 02_Application Server FilesUploaded bySaket Shahi
- Sem 6 ProjectUploaded bySwetang Khatri
- p2Uploaded byandityasm
- Post Movement JournalUploaded byAdebola Ogunleye
- lUploaded byVarun
- Rpgs h RavanUploaded bySaiprasad
- Creating Lock Object and Using Lock in ProgramUploaded byAshish Mohapatra
- Report Abap Alv List SampleUploaded byDavid Roque
- HR ABAP Program ExampleUploaded byFarooq Ahmed
- HW4 Solutions 2016 SpringUploaded byVijay Trivedi
- bdc oldUploaded byDora Babu
- threadDump-20180831-160739Uploaded byCarlos Alberto
- ATC Module 3Uploaded byNavya CR
- Box2DwithOpenglUploaded byarunkumar_a8131

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

- SIN - U.1 Introduction to RBSUploaded byManolo Camionero
- class0.pptUploaded bySiddhartha Sen
- FUZZY1.pdfUploaded byEka Laras
- Ian Hacking-What is LogicUploaded byjf_90
- rakudoUploaded byscrubbydoo
- UndecidabilityUploaded byapi-19970469
- u5l9worksheet-compoundconditionalsUploaded byapi-332412793
- Java Tutorial for Beginners PDFUploaded bySatish Babu
- SCA FL-02Uploaded byImranAhmad
- Grammar.pdfUploaded bySiraj Ud-Doulla
- AbabouUploaded byMax Zhu
- SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGEUploaded byJames Moreno
- Formal Languages and Chomsky HierarchyUploaded bySaurabh Singh
- Theory of Automata by CohenUploaded byMuhammad Irshad Nazeer
- ANSI-CL-23.psUploaded byBenjamin Culkin
- INTERVAL NEUTROSOPHIC SETS AND LOGICUploaded byAnonymous 0U9j6BLllB
- ThesisUploaded bySzilard Zsolt Fazekas
- Teoría de Modelos para la lógica ModalUploaded byelias
- proplogic.pdfUploaded byGOPI CHAND
- 02_CNF_Horn.pdfUploaded byharry_3k
- Fuzzy LogicUploaded bykuppuswamy
- 11 Maths NcertSolutions Chapter 13 2 SupplementaryUploaded byAshish Kumar
- Pasch, Moritz.pdfUploaded bycreesha
- SMTLIBTutorial.pdfUploaded byjoseocsilva
- CD Previous QA 2010Uploaded bySagar
- 12-13MultipleAlignmentUploaded byRicardo Ortega Magaña
- Class9 Parsing Simplifications of Context-Free GrammarsUploaded byNavneet Kumar
- 20160907110938MTK3013-Chapter1.5 Rules of Inference_Rev1Uploaded byNoor Ziela
- Bottomupparser-Shift Reduce ParsingUploaded byvivek patel
- 03-med.pdfUploaded byVan Bao Nguyen