SlideShare une entreprise Scribd logo
1  sur  31
Simplifies form and Normal form
Simplifies form
Context Free Grammar (CFG)
• A context free grammar is a 4-tuple G=(V, ,S,P)Ʃ
where
V & are disjoint finite setƩ
S is an element of V and
P is a finite set formulas of the form A → α
V → Non terminal or variable
Ʃ → terminal symbols
S → start symbol
P → production rule or grammar rules
Context Free Grammar (CFG)
Application
• CFG are extensively used to specify the syntax of programming
language.
• CFG is used to develop parser
Definition: Context Free Language
• Language generated by CFG is called context free language
• Let G= (V, , S, P) be a CFG. The Language generated by G isƩ
L(G):{x */S G* x}∈ Ʃ ⟹
• A language L is a context free Language(CFL) if there is a CFG G
so that L=L(G)
Simplified form & Normal forms
• In this section we discuss some slight more straight
forward ways of improving a grammer without
changing the resulting language.
1)eliminating certain types of productions that may
be awkward to work to work.
2)standardizing the productions so that they all have
a certaion normal form.
Simplifies form
• In this simplifies form there is three type
1) Eliminating Null able Variable(Empty Production Removal)
2) Eliminating Unit Production(Unit production removal)
3) Eliminating Useless Productions(Removing Useless)
Eliminating Null able Variable
(Empty Production Removal)
• The productions of context-free grammars can be coerced
into a variety of forms without affecting the expressive power
of the grammars.
• If the empty string does not belong to a language, then there
is a way to eliminate the productions of the form A → ^ from
the grammar.
• If the empty string belongs to a language, then we can
eliminate ^ from all productions save for the single
production S → ^ . In this case we can also eliminate any
occurrences of S from the right-hand side of productions
Eliminating Null able Variable
(Empty Production Removal)
• a nullable variable in a CFG G=(V, ,S,P) is defined as followsƩ
1) Any variable A for which P contains A → is nullable˄
2) if P contain production A → B1B2…..Bn
where B1B2…Bn are nullable variable, then A is nullable.
3) No other variable in V are nullable.
• Example:
S → aX/Yb
X → S/˄
Y → bY/b
Ans:
S → aX/Yb/a
X → S
Y → bY/b
Eliminating Unit Production
(Unit production removal)
Eliminating Unit Production
(Unit production removal)
Eliminating Unit Production
(Unit production removal)
• Example:
S → Aa/B
A → a/bc/B
B → A/bB
Ans:
Unit production are S → B, A → B and B → A
S → Aa/A/bb S → Aa/a/bc/bb
A → a/bc/B A → a/bc/A/bb
A → a/bc/bb B → A/bb
B → A/bb B → a/bc/bb
So CFG after removing unit production is
S → Aa/a/bc/bb
A → a/bc/bb
B → a/bc/bb
Normal forms
definition
Theorem
Example of CFG Conversion
Removing Rules
Removing unit rule
More unit rules
Converting remaining rules
Presentation Outline
20May 27, 2009
• Greibach Normal Form
Greibach Normal Form
21May 27, 2009
A → αX
A context free grammar is said to be in
Greibach Normal Form if all productions
are in the following form:
• A is a non terminal symbols
• α is a terminal symbol
• X is a sequence of non terminal symbols.
It may be empty.
Step1:
If the start symbol S occurs on some right side, create a
new start symbol S’ and a new production S’ → S.
Step 2:
Remove Null productions. (Using the Null production
removal algorithm discussed earlier)
Step 3:
Remove unit productions. (Using the Unit production
removal algorithm discussed earlier)
Step 4:
Remove all direct and indirect left-recursion.
Step 5:
Do proper substitutions of productions to convert it into
the proper form of GNF.
Algorithm to Convert a CFG into Greibach Normal Form
Greibach Normal Form
Greibach Normal Form
23May 27, 2009
Example:
S → XA | BB
B → b | SB
X → b
A → a
S = A1
X = A2
A = A3
B = A4
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
CNF New Labels Updated CNF
Greibach Normal Form
24May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
First Step
Xk is a string of zero
or more variables
Ai → AjXk j > iAi → AjXk j > i
A4 → A1A4
Greibach Normal Form
25May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
A4 → A1A4
A4 → A2A3A4 | A4A4A4 | b
A4 → bA3A4 | A4A4A4 | b
First Step
Ai → AjXk j > iAi → AjXk j > i
Greibach Normal Form
26May 27, 2009
Example:
Second Step
Eliminate
Left Recursions
Eliminate
Left Recursions
A1 → A2A3 | A4A4
A4 → bA3A4 | A4A4A4 | b
A2 → b
A3 → a
A4 → A4A4A4
Greibach Normal Form
27May 27, 209
Example:
Second Step
Eliminate
Left
Recursions
Eliminate
Left
Recursions
A1 → A2A3 | A4A4
A4 → bA3A4 | A4A4A4 | b
A2 → b
A3 → a
A4 → bA3A4 | b | bA3A4Z| bZ
Z → A4A4 | A4A4Z
Greibach Normal Form
28May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
A → αXA → αX
GNF
Greibach Normal Form
29May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
Greibach Normal Form
30May 27, 2009
Example:
A1 → bA3 |bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A2 → b
A3 → a
Grammar in Greibach Normal Form
Thank You
14/11/16

Contenu connexe

Tendances

Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
myrajendra
 
Generalized transition graphs
Generalized transition graphsGeneralized transition graphs
Generalized transition graphs
Arham Khan G
 

Tendances (20)

Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
 
Built in function
Built in functionBuilt in function
Built in function
 
context free language
context free languagecontext free language
context free language
 
Removing ambiguity-from-cfg
Removing ambiguity-from-cfgRemoving ambiguity-from-cfg
Removing ambiguity-from-cfg
 
2.8 normal forms gnf & problems
2.8 normal forms   gnf & problems2.8 normal forms   gnf & problems
2.8 normal forms gnf & problems
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
 
Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
 
2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg ppt
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
System calls
System callsSystem calls
System calls
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 
Generalized transition graphs
Generalized transition graphsGeneralized transition graphs
Generalized transition graphs
 
CHOMSKY AND GREIBACH NORMAL FORM.ppt
CHOMSKY AND GREIBACH NORMAL FORM.pptCHOMSKY AND GREIBACH NORMAL FORM.ppt
CHOMSKY AND GREIBACH NORMAL FORM.ppt
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Operating System- Services,types.Batch files and DOS history
Operating System- Services,types.Batch files and DOS historyOperating System- Services,types.Batch files and DOS history
Operating System- Services,types.Batch files and DOS history
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 

En vedette

Class8
 Class8 Class8
Class8
issbp
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
Deepak Singh
 
Class7
 Class7 Class7
Class7
issbp
 

En vedette (20)

Lecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause Grammars
 
Normal forms
Normal formsNormal forms
Normal forms
 
Cs2303 theory of computation may june 2016
Cs2303 theory of computation may june 2016Cs2303 theory of computation may june 2016
Cs2303 theory of computation may june 2016
 
Class8
 Class8 Class8
Class8
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Diodes
DiodesDiodes
Diodes
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthing
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
 
GNF
GNFGNF
GNF
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Class7
 Class7 Class7
Class7
 
Spyware and rootkit
Spyware and rootkitSpyware and rootkit
Spyware and rootkit
 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfg
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 

Similaire à Simplifies and normal forms - Theory of Computation

Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
Jisock
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
lavishka_anuj
 

Similaire à Simplifies and normal forms - Theory of Computation (18)

Context Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.pptContext Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.ppt
 
Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
 
Chomsky_GreibachNF.ppt
Chomsky_GreibachNF.pptChomsky_GreibachNF.ppt
Chomsky_GreibachNF.ppt
 
Chomsky_Greibach-Hector-Chavez.ppt
Chomsky_Greibach-Hector-Chavez.pptChomsky_Greibach-Hector-Chavez.ppt
Chomsky_Greibach-Hector-Chavez.ppt
 
NORMAL-FORMS.ppt
NORMAL-FORMS.pptNORMAL-FORMS.ppt
NORMAL-FORMS.ppt
 
NORMAL-FORMS.ppt
NORMAL-FORMS.pptNORMAL-FORMS.ppt
NORMAL-FORMS.ppt
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
TOA_WEEK 14.pptx
TOA_WEEK 14.pptxTOA_WEEK 14.pptx
TOA_WEEK 14.pptx
 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of Computation
 
Class5
Class5Class5
Class5
 
Cfg part ii
Cfg   part iiCfg   part ii
Cfg part ii
 
Conversion of CFG to CNF.pptx
Conversion of CFG to CNF.pptxConversion of CFG to CNF.pptx
Conversion of CFG to CNF.pptx
 
3 handouts section2-5
3 handouts section2-53 handouts section2-5
3 handouts section2-5
 

Dernier

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 

Dernier (20)

Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 

Simplifies and normal forms - Theory of Computation

  • 1. Simplifies form and Normal form
  • 3. Context Free Grammar (CFG) • A context free grammar is a 4-tuple G=(V, ,S,P)Ʃ where V & are disjoint finite setƩ S is an element of V and P is a finite set formulas of the form A → α V → Non terminal or variable Ʃ → terminal symbols S → start symbol P → production rule or grammar rules
  • 4. Context Free Grammar (CFG) Application • CFG are extensively used to specify the syntax of programming language. • CFG is used to develop parser Definition: Context Free Language • Language generated by CFG is called context free language • Let G= (V, , S, P) be a CFG. The Language generated by G isƩ L(G):{x */S G* x}∈ Ʃ ⟹ • A language L is a context free Language(CFL) if there is a CFG G so that L=L(G)
  • 5. Simplified form & Normal forms • In this section we discuss some slight more straight forward ways of improving a grammer without changing the resulting language. 1)eliminating certain types of productions that may be awkward to work to work. 2)standardizing the productions so that they all have a certaion normal form.
  • 6. Simplifies form • In this simplifies form there is three type 1) Eliminating Null able Variable(Empty Production Removal) 2) Eliminating Unit Production(Unit production removal) 3) Eliminating Useless Productions(Removing Useless)
  • 7. Eliminating Null able Variable (Empty Production Removal) • The productions of context-free grammars can be coerced into a variety of forms without affecting the expressive power of the grammars. • If the empty string does not belong to a language, then there is a way to eliminate the productions of the form A → ^ from the grammar. • If the empty string belongs to a language, then we can eliminate ^ from all productions save for the single production S → ^ . In this case we can also eliminate any occurrences of S from the right-hand side of productions
  • 8. Eliminating Null able Variable (Empty Production Removal) • a nullable variable in a CFG G=(V, ,S,P) is defined as followsƩ 1) Any variable A for which P contains A → is nullable˄ 2) if P contain production A → B1B2…..Bn where B1B2…Bn are nullable variable, then A is nullable. 3) No other variable in V are nullable. • Example: S → aX/Yb X → S/˄ Y → bY/b Ans: S → aX/Yb/a X → S Y → bY/b
  • 9. Eliminating Unit Production (Unit production removal)
  • 10. Eliminating Unit Production (Unit production removal)
  • 11. Eliminating Unit Production (Unit production removal) • Example: S → Aa/B A → a/bc/B B → A/bB Ans: Unit production are S → B, A → B and B → A S → Aa/A/bb S → Aa/a/bc/bb A → a/bc/B A → a/bc/A/bb A → a/bc/bb B → A/bb B → A/bb B → a/bc/bb So CFG after removing unit production is S → Aa/a/bc/bb A → a/bc/bb B → a/bc/bb
  • 15. Example of CFG Conversion
  • 20. Presentation Outline 20May 27, 2009 • Greibach Normal Form
  • 21. Greibach Normal Form 21May 27, 2009 A → αX A context free grammar is said to be in Greibach Normal Form if all productions are in the following form: • A is a non terminal symbols • α is a terminal symbol • X is a sequence of non terminal symbols. It may be empty.
  • 22. Step1: If the start symbol S occurs on some right side, create a new start symbol S’ and a new production S’ → S. Step 2: Remove Null productions. (Using the Null production removal algorithm discussed earlier) Step 3: Remove unit productions. (Using the Unit production removal algorithm discussed earlier) Step 4: Remove all direct and indirect left-recursion. Step 5: Do proper substitutions of productions to convert it into the proper form of GNF. Algorithm to Convert a CFG into Greibach Normal Form Greibach Normal Form
  • 23. Greibach Normal Form 23May 27, 2009 Example: S → XA | BB B → b | SB X → b A → a S = A1 X = A2 A = A3 B = A4 A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a CNF New Labels Updated CNF
  • 24. Greibach Normal Form 24May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a First Step Xk is a string of zero or more variables Ai → AjXk j > iAi → AjXk j > i A4 → A1A4
  • 25. Greibach Normal Form 25May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a A4 → A1A4 A4 → A2A3A4 | A4A4A4 | b A4 → bA3A4 | A4A4A4 | b First Step Ai → AjXk j > iAi → AjXk j > i
  • 26. Greibach Normal Form 26May 27, 2009 Example: Second Step Eliminate Left Recursions Eliminate Left Recursions A1 → A2A3 | A4A4 A4 → bA3A4 | A4A4A4 | b A2 → b A3 → a A4 → A4A4A4
  • 27. Greibach Normal Form 27May 27, 209 Example: Second Step Eliminate Left Recursions Eliminate Left Recursions A1 → A2A3 | A4A4 A4 → bA3A4 | A4A4A4 | b A2 → b A3 → a A4 → bA3A4 | b | bA3A4Z| bZ Z → A4A4 | A4A4Z
  • 28. Greibach Normal Form 28May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4 Z A2 → b A3 → a A → αXA → αX GNF
  • 29. Greibach Normal Form 29May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4 Z A2 → b A3 → a Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
  • 30. Greibach Normal Form 30May 27, 2009 Example: A1 → bA3 |bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A4 → bA3A4 | b | bA3A4Z | bZ Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A2 → b A3 → a Grammar in Greibach Normal Form