30 views

Uploaded by chunnilal_munnilal

Greibach Normal form

Greibach Normal form

© All Rights Reserved

- GP142
- Sample Web Design Project Plan
- Basic Vision With LabVIEW
- Gnu Plot
- Salv
- Matrix Mul
- Rust 1.0
- poetry and figurative language lesson plan
- Reach - Then Teach (FREE Preview)
- Making Things See
- week0w
- 1662 Upgrade Procedure
- Homework 3 Word Document
- Review Quiz
- DTNRG-0.pdf
- DS 2 marks
- Word Search
- Cor Sale HIS Sale 30 BG COL RED Document
- Program No2
- Link10mv Tb Pg093

You are on page 1of 25

Definition

A CFG is in Greibach normal form if each rule has one these forms:

i. A aA1A2An ii. A a iii. S where a and Ai V {S} for i = 1, 2,, n

Definition

A CFG is in Chomsky normal form if each rule has one these forms:

i. A BC ii. A a iii. S where B, C V {S}

Conversion

Convert from Chomsky to Greibach in two steps: 1. From Chomsky to intermediate grammar

a. Eliminate direct left recursion b. Use A uBv rules transformations to improve references (explained later)

Before

A Aa | b

After

A bZ | b Z aZ | a

Remove the rule with direct left recursion, and create a new one with recursion on the right

Before

A Aa | Ab | b | c

After

A bZ | cZ | b | c Z aZ | bZ | a | b

Remove the rules with direct left recursion, and create new ones with recursion on the right

Before

A AB | BA | a Bb|c

After

A BAZ | aZ | BA | a Z BZ | B Bb|c

Before

A uBb B w1 | w1 || wn

After

Add A uw1b | uw1b || uwnb Delete A uBb

Conversion: Step 1

Goal: construct intermediate grammar in this format

i. A aw ii. A Bw iii. S where w V* and B comes after A

Conversion: Step 1

Assign a number to all variables starting with S, which gets 1 Transform each rule following the order according to given number from lowest to highest

Eliminate direct left recursion If RHS of rule starts with variable with lower order, apply A uBb transformation to fix it

Conversion: Step 2

Goal: construct Greibach grammar out of intermediate grammar from step 1 Fix A Bw rules into A aw format

After step 1, last original variable should have all its rules starting with a terminal Working from bottom to top, fix all original variables using A uBb transformation technique, so all rules become A aw

Conversion Example

Convert the following grammar from Chomsky normal form, into Greibach normal form

1. 2. 3. 4. S AB | A AB | CB | a B AB | b C AC | c

Conversion Strategy

Goal: transform all rules which RHS does not start with a terminal Apply two steps conversion Work rules in sequence, eliminating direct left recursion, and enforcing variable reference to higher given number Fix all original rules, then new ones

Step 1: S rules

Starting with S since it has a value to of 1 S AB | S rules comply with two required conditions

There is no direct left recursion Referenced rules A and B have a given number higher than 1. A corresponds to 2 and B to 3.

Step 1: A rules

A AB | CB | a Direct left recursive rule A AB needs to be fixed. Other A rules are fine Apply direct left recursion transformation

A CBR1 | aR1 | CB | a R1 BR1 | B

Step 1: B rules

B AB | b B AB rule needs to be fixed since B corresponds to 3 and A to 2. B rules can only have on their RHS variables with number equal or higher. Use A uBb transformation technique B CBR1B | aR1B | CBB | aB | b

Step 1: C rules

C AC | c C AC rule needs to be fixed since C corresponds to 4 and A to 2. Use same A uBb transformation technique C CBR1C | aR1C | CBC | aC | c Now variable references are fine according to given number, but we introduced direct left recursion in two rules

Step 1: C rules

C CBR1C | aR1C | CBC | aC | c Eliminate direct left recursion

C aR1CR2 | aCR2 | cR2 | aR1C | aC | c R2 BR1CR2 | BCR2 | BR1C | BC

S AB | A CBR1 | aR1 | CB | a B CBR1B | aR1B | CBB | aB | b C aR1CR2 | aCR2 | cR2 | aR1C | aC | c R1 BR1 | B R2 BR1CR2 | BCR2 | BR1C | BC

Rules S, A, B and C dont have direct left recursion, and RHS variables are of higher number All C rules start with terminal symbol Proceed to fix rules B, A and S in bottomup order, so they start with terminal symbol. Use A uBb transformation technique

Before

B CBR1B | aR1B | CBB | aB | b

After

B aR1B | aB | b B aR1CR2BR1B | aCR2BR1B | cR2BR1B | aR1CBR1B | aCBR1B | cBR1B B aR1CR2BB | aCR2BB | cR2BB | aR1CBB | aCBB | cBB

Before

A CBR1 | aR1 | CB | a

After

A aR1 | a A aR1CR2BR1 | aCR2BR1 | cR2BR1 | aR1CBR1 | aCBR1 | cBR1 A aR1CR2B | aCR2B | cR2B | aR1CB | aCB | cB

Before

S AB |

After

S S aR1B | aB S aR1CR2BR1B | aCR2BR1B | cR2BR1B | aR1CBR1B | aCBR1B | cBR1B S aR1CR2BB | aCR2BB | cR2BB | aR1CBB | aCBB | cBB

All original rules S, A, B and C are fully converted now New recursive rules need to be converted next Use same A uBb transformation technique replacing starting variable B

R1 BR1 | B R2 BR1CR2 | BCR2 | BR1C | BC

Conclusions

After conversion, since B has 15 rules, and R1 references B twice, R1 ends with 30 rules Similar for R2 which references B four times. Therefore, R2 ends with 60 rules All rules start with a terminal symbol (with the exception of S ) Parsing algorithms top-down or bottom-up would complete on a grammar converted to Greibach normal form

- GP142Uploaded byChristopher Griffin
- Sample Web Design Project PlanUploaded byHeena Desai
- Basic Vision With LabVIEWUploaded bynghiepmechan
- Gnu PlotUploaded bySk Wasim Firdous
- Matrix MulUploaded byniharika sunkara
- SalvUploaded byVenkatRaman
- Rust 1.0Uploaded byhfujsx
- poetry and figurative language lesson planUploaded byapi-285059397
- Making Things SeeUploaded byadrianstravitz
- Reach - Then Teach (FREE Preview)Uploaded byDerrick Brown
- week0wUploaded byjaanu
- 1662 Upgrade ProcedureUploaded byTony Melek
- DTNRG-0.pdfUploaded bynelloholmes
- Homework 3 Word DocumentUploaded byloneuke
- DS 2 marksUploaded bySaravanan Sar
- Word SearchUploaded bygwitynski
- Cor Sale HIS Sale 30 BG COL RED DocumentUploaded byddukem
- Review QuizUploaded byMark Ryan R. Hernandez
- Program No2Uploaded byGarima Mudgal
- Link10mv Tb Pg093Uploaded byisabellario2602
- alv_custom_container+hyperlink(1)Uploaded byEmanuelPredescu
- C_M3_Nov14_231014Uploaded byΚαρσάνικο Κέντημα
- february newsletter 2016Uploaded byapi-262391750
- R-codeUploaded byMarthinus
- Sample Script Used to Create a Sales Order With Credit Card PaymentUploaded bysekharmcp
- code practiceUploaded byaurelio
- USB_CODE_CHART.pdfUploaded byAdrian Hands
- Molly Paper 4Uploaded byAlex Kneier
- 257 ESD-Application 2011 WebUploaded byM Nurul Ikhsan Saleh
- Ch 17Uploaded byManpreet

- Search Engine OptimizationUploaded bypetkoum
- IccUploaded bychunnilal_munnilal
- Gate SyllabusUploaded bychunnilal_munnilal
- lec10Uploaded byMagnus La Croix
- IFCBUploaded bychunnilal_munnilal
- Wolf Sara ArrangedUploaded bychunnilal_munnilal
- Slides RelationalAlgebraUploaded bychunnilal_munnilal
- Jag DeepUploaded bychunnilal_munnilal
- sumitUploaded bychunnilal_munnilal
- Campus ProposalUploaded bychunnilal_munnilal

- ELK 100 InstallUploaded bymrmomo99
- SM-C5010 UM Open HongKong Marshmallow Eng Rev.1.0 170217Uploaded bykjscir
- MVCUploaded bySivakumar M
- TSX17 20 SelectionUploaded byPariapaza Enrique Luis
- Catalogue Jiangsu Sieyuan Hertz[1]Uploaded bydaminhvien
- Ict Skills Enhancement Training in Teacher EducationUploaded byVelijun R. Perez
- Digital Still Camera DSC-RX10M4Uploaded byAlfonso Calderon
- Proact III 04177_A ManualUploaded byHernando Robledo
- Topic1qUploaded byAnderson Alves
- Best 12V Battery Charger Circuit Using LM311Uploaded byAïn' Fidy
- Attribute Data ManagementUploaded byriaz zarin
- ME 1_finalUploaded byAshfaq Qureshi
- OmniScan MX2 en 201210Uploaded byGetapo Ramin
- Www Facstaff Bucknell Edu Mastascu ElessonsHTML OpAmps OpAmp(2)Uploaded byYesrno Toyou
- The Journal of Abnormal PsycUploaded byapi-3708082
- Expresso Bikes EF S2 Install GuideUploaded bypowerliftermilo
- IRS Physical Document and Computer System Security, Form #09.039Uploaded bySovereignty Education and Defense Ministry (SEDM)
- Bi 11gr1certmatrix 1661681Uploaded bySrinivasreddy Madireddy
- 60-03 CPR04 Manual CopyUploaded bysoundrisrinivasan
- SibeliusFirst712QSG_76284Uploaded bySteve Clark
- Developing and Using QuestionairesUploaded byMichaelister Ordoñez Monteron
- List of Samsung Authorised Service Centres in Trichy _ Product WiseUploaded byMuralitharan Jothimani
- SPO-Asesmen-Ulang-Pasien[1]Uploaded byElvi Adilenna
- Service manual.pdfUploaded byJaimeAndrésFerrer
- Excel 10 Automatic GradingUploaded byMd Yusof
- PKI enkripcijaUploaded byb00kmaker
- Design of Cross drainage StructuresUploaded bypandey_baibhav
- Selection_of_bearing_size.pdfUploaded byniraj
- Techniczny AngUploaded bySebastian2007
- Computer TermsUploaded byMoustafa Elbadwihi