SlideShare a Scribd company logo
1 of 15
Greibach
Normal Form
(GNF)
-Sampath Kumar S,
AP/CSE, SECE
Greibach Normal Form (GNF):
 A CFG is in Greibach Normal Form (GNF), if the
right-hand side of each rule has one terminal
followed by zero or more non-terminals:
A → a B, where a ∈ T and B ∈ V*.
 For converting the given grammar to GNF, we use
2 lemmas.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
2
Zero or more non-terminal symbols
One terminal symbol
Example of a grammar in GNF
11/21/2017
Sampath Kumar S, AP/CSE, SECE
3
S → aB | bA
A → a | aS | bAA
B → b | bS | aBB
Every right-hand side consists of exactly
one terminal followed by zero or more non-
terminals.
Example of a grammar not in GNF
11/21/2017
Sampath Kumar S, AP/CSE, SECE
4
S → aBc
B → b
Not in Greibach Normal Form
Terminal at end is not allowed
Lemma 1: Substitution Rule
Let G = {V, T, P, S} be a CFG. Let A → αBγ be a
production in P and B is
B → β1|β2|β3|β4
The equivalent grammar can be obtained by
substituting B in A. Then the resulting grammar
is
A → αβ1γ|αβ2γ|αβ3γ|αβ4γ
11/21/2017
Sampath Kumar S, AP/CSE, SECE
5
Lemma 2: Elimination of Left recursion
Grammar of the form A → Aα|β is called left
recursive grammar. To eliminate left recursion, rewrite
the grammar as
A → βZ
Z → αZ|ε
If we eliminate ε production, then we get
A → βZ|β
Z → αZ|α
We can generalize this grammar. If there is a CFG as
A → Aα1|Aα2|Aα3|….Aαn|β1|β2|β3……βn
The equivalent grammar without left recursion is
A → β1Z|β2Z|β3Z|…|β1|β2|β3 ……
Z → α1Z|α2Z|α3Z|……|α1|α2|α3
11/21/2017
Sampath Kumar S, AP/CSE, SECE
6
Procedure for converting to GNF:
1. Simplify the CFG (i.e., eliminate null production, unit
production and useless symbols) and convert to Chomsky
Normal Form (CNF).
2. Convert the rules to ascending order. Rename the Non
Terminals as A1, A2 …. with S = A1.
3. For each production of the form Ai → Ajα, apply the
following:
(a) if j>i – Leave the production as it is.
(b) if j=i – Apply elimination of left recursion rule.
(c) if j<i – Apply substitution rule.
4. For each production of the form Ai → Ajα, where j>i,
apply the substitution lemma if Aj is in GNF, to bring Ai to
GNF.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
7
Problems to discuss:
104. Convert the following CFG to GNF
S → AA|a
A→ SS|b
Solution:
Step 1: Simplify the CFG and convert to CNF
– Given grammar is in CNF form.
Step 2: Rename the variables as S=A1, A=A2
A1 → A2A2|a ….(1)
A2 → A1A1|b ….(2)
11/21/2017
Sampath Kumar S, AP/CSE, SECE
8
Problems to discuss:
Step 3.1: In (1) j>i so leave the production as it is.
Step 3.2: In (2) j<i so apply substitution rule.
A2 → A2A2A1|aA1|b ….(new 2)
Step 3.3: In (new 2) j=i so apply elimination of left
recursion rule.
A2 → aA1A3|bA3|aA1|b ….(new 2)
A3 → A2A1A3|A2A1 ….(3)
Step 3.4: In (3) j<i so apply substitution rule.
A3 → aA1A3A1A3|bA3A1A3|aA1A1A3|bA1A3|
aA1A3A1|bA3A1|aA1A1|bA1 ….(new 3)
11/21/2017
Sampath Kumar S, AP/CSE, SECE
9
Problems to discuss:
Step 4: Now (1) is in Ai → Ajα where j<i so we
apply substitution rule to convert it to GNF.
A1 → aA1A2|bA2|aA1A3A2|bA3A2|a …(new 1)
Final production rule:
A1 → aA1A2|bA2|aA1A3A2|bA3A2|a
A2 → aA1A3|bA3|aA1|b
A3 → aA1A3A1A3|bA3A1A3|aA1A1A3|bA1A3|
aA1A3A1|bA3A1|aA1A1|bA1
Now the given CFG is converted to GNF.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
10
Problems to discuss:
105. Convert the following CFG to GNF
S → XA|BB
B → b|SB
X → b
A → a
106. Convert the following CFG to GNF
S → CA
A→ a
C → aB|b
107. Convert the following CFG to GNF
S → AB
A→ BS|b
B → SA|a
11/21/2017
Sampath Kumar S, AP/CSE, SECE
11
Problems to discuss:
108. Convert the following CFG to GNF
S → ABA
A→ aA|ε
B → bB|ε
109. Convert the following CFG to CNF
S → AB
C→ AB|b
B → CA
A → a
110. Convert the following CFG to CNF
S → BC|a
B → AC|b
C → a
A → b
11/21/2017
Sampath Kumar S, AP/CSE, SECE
12
Problems to discuss:
108. Convert the following CFG to GNF
S → ABA
A→ aA|ε
B → bB|ε
109. Convert the following CFG to CNF
S → AB
C→ AB|b
B → CA
A → a
110. Convert the following CFG to CNF
S → BC|a
B → AC|b
C → a
A → b
11/21/2017
Sampath Kumar S, AP/CSE, SECE
13
11/21/2017
Sampath Kumar S, AP/CSE, SECE
15
நன்றி
11/21/2017
Sampath Kumar S, AP/CSE, SECE
16

More Related Content

What's hot

Context free grammars
Context free grammarsContext free grammars
Context free grammarsRonak Thakkar
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsKM Bappi
 
Synchronous and-asynchronous-data-transfer
Synchronous and-asynchronous-data-transferSynchronous and-asynchronous-data-transfer
Synchronous and-asynchronous-data-transferAnuj Modi
 
Automata theory
Automata theoryAutomata theory
Automata theorycolleges
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machineMian Munib
 
Introduction to Parallel and Distributed Computing
Introduction to Parallel and Distributed ComputingIntroduction to Parallel and Distributed Computing
Introduction to Parallel and Distributed ComputingSayed Chhattan Shah
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 
Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarMdImamHasan1
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Distance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmDistance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmMOHIT AGARWAL
 
2.7 normal forms cnf & problems
2.7 normal forms  cnf & problems2.7 normal forms  cnf & problems
2.7 normal forms cnf & problemsSampath Kumar S
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternativesPooja Dixit
 

What's hot (20)

Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
 
Synchronous and-asynchronous-data-transfer
Synchronous and-asynchronous-data-transferSynchronous and-asynchronous-data-transfer
Synchronous and-asynchronous-data-transfer
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Automata Theory - Turing machine
Automata Theory - Turing machineAutomata Theory - Turing machine
Automata Theory - Turing machine
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machine
 
Introduction to Parallel and Distributed Computing
Introduction to Parallel and Distributed ComputingIntroduction to Parallel and Distributed Computing
Introduction to Parallel and Distributed Computing
 
Csma
CsmaCsma
Csma
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous Grammar
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Distance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmDistance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing Algorithm
 
2.7 normal forms cnf & problems
2.7 normal forms  cnf & problems2.7 normal forms  cnf & problems
2.7 normal forms cnf & problems
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 

Similar to Greibach Normal Form Conversion Guide

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.pptxJisock
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationNikhil Pandit
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptxShubhamKumar483645
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarJasmine Peniel
 

Similar to Greibach Normal Form Conversion Guide (6)

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
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 
TOA_WEEK 14.pptx
TOA_WEEK 14.pptxTOA_WEEK 14.pptx
TOA_WEEK 14.pptx
 

More from Sampath Kumar S

5.2 primitive recursive functions
5.2 primitive recursive functions5.2 primitive recursive functions
5.2 primitive recursive functionsSampath Kumar S
 
4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languagesSampath Kumar S
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines constructionSampath Kumar S
 
4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)Sampath Kumar S
 
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on plSampath Kumar S
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cflSampath Kumar S
 
3.1,2,3 pushdown automata definition, moves &amp; id
3.1,2,3 pushdown automata   definition, moves &amp; id3.1,2,3 pushdown automata   definition, moves &amp; id
3.1,2,3 pushdown automata definition, moves &amp; idSampath Kumar S
 
2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammarsSampath Kumar S
 
2.4 derivations and languages
2.4 derivations and languages2.4 derivations and languages
2.4 derivations and languagesSampath Kumar S
 
2.3 context free grammars and languages
2.3 context free grammars and languages2.3 context free grammars and languages
2.3 context free grammars and languagesSampath Kumar S
 
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 grammarSampath Kumar S
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular setsSampath Kumar S
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfaSampath Kumar S
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressionsSampath Kumar S
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfaSampath Kumar S
 
1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expressionSampath Kumar S
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε movesSampath Kumar S
 

More from Sampath Kumar S (20)

5.2 primitive recursive functions
5.2 primitive recursive functions5.2 primitive recursive functions
5.2 primitive recursive functions
 
4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages
 
4.6 halting problem
4.6 halting problem4.6 halting problem
4.6 halting problem
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines construction
 
4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)
 
4.1 turing machines
4.1 turing machines4.1 turing machines
4.1 turing machines
 
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
 
3.1,2,3 pushdown automata definition, moves &amp; id
3.1,2,3 pushdown automata   definition, moves &amp; id3.1,2,3 pushdown automata   definition, moves &amp; id
3.1,2,3 pushdown automata definition, moves &amp; id
 
2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars
 
2.4 derivations and languages
2.4 derivations and languages2.4 derivations and languages
2.4 derivations and languages
 
2.3 context free grammars and languages
2.3 context free grammars and languages2.3 context free grammars and languages
2.3 context free grammars and languages
 
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
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfa
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε moves
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Greibach Normal Form Conversion Guide

  • 2. Greibach Normal Form (GNF):  A CFG is in Greibach Normal Form (GNF), if the right-hand side of each rule has one terminal followed by zero or more non-terminals: A → a B, where a ∈ T and B ∈ V*.  For converting the given grammar to GNF, we use 2 lemmas. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 2 Zero or more non-terminal symbols One terminal symbol
  • 3. Example of a grammar in GNF 11/21/2017 Sampath Kumar S, AP/CSE, SECE 3 S → aB | bA A → a | aS | bAA B → b | bS | aBB Every right-hand side consists of exactly one terminal followed by zero or more non- terminals.
  • 4. Example of a grammar not in GNF 11/21/2017 Sampath Kumar S, AP/CSE, SECE 4 S → aBc B → b Not in Greibach Normal Form Terminal at end is not allowed
  • 5. Lemma 1: Substitution Rule Let G = {V, T, P, S} be a CFG. Let A → αBγ be a production in P and B is B → β1|β2|β3|β4 The equivalent grammar can be obtained by substituting B in A. Then the resulting grammar is A → αβ1γ|αβ2γ|αβ3γ|αβ4γ 11/21/2017 Sampath Kumar S, AP/CSE, SECE 5
  • 6. Lemma 2: Elimination of Left recursion Grammar of the form A → Aα|β is called left recursive grammar. To eliminate left recursion, rewrite the grammar as A → βZ Z → αZ|ε If we eliminate ε production, then we get A → βZ|β Z → αZ|α We can generalize this grammar. If there is a CFG as A → Aα1|Aα2|Aα3|….Aαn|β1|β2|β3……βn The equivalent grammar without left recursion is A → β1Z|β2Z|β3Z|…|β1|β2|β3 …… Z → α1Z|α2Z|α3Z|……|α1|α2|α3 11/21/2017 Sampath Kumar S, AP/CSE, SECE 6
  • 7. Procedure for converting to GNF: 1. Simplify the CFG (i.e., eliminate null production, unit production and useless symbols) and convert to Chomsky Normal Form (CNF). 2. Convert the rules to ascending order. Rename the Non Terminals as A1, A2 …. with S = A1. 3. For each production of the form Ai → Ajα, apply the following: (a) if j>i – Leave the production as it is. (b) if j=i – Apply elimination of left recursion rule. (c) if j<i – Apply substitution rule. 4. For each production of the form Ai → Ajα, where j>i, apply the substitution lemma if Aj is in GNF, to bring Ai to GNF. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 7
  • 8. Problems to discuss: 104. Convert the following CFG to GNF S → AA|a A→ SS|b Solution: Step 1: Simplify the CFG and convert to CNF – Given grammar is in CNF form. Step 2: Rename the variables as S=A1, A=A2 A1 → A2A2|a ….(1) A2 → A1A1|b ….(2) 11/21/2017 Sampath Kumar S, AP/CSE, SECE 8
  • 9. Problems to discuss: Step 3.1: In (1) j>i so leave the production as it is. Step 3.2: In (2) j<i so apply substitution rule. A2 → A2A2A1|aA1|b ….(new 2) Step 3.3: In (new 2) j=i so apply elimination of left recursion rule. A2 → aA1A3|bA3|aA1|b ….(new 2) A3 → A2A1A3|A2A1 ….(3) Step 3.4: In (3) j<i so apply substitution rule. A3 → aA1A3A1A3|bA3A1A3|aA1A1A3|bA1A3| aA1A3A1|bA3A1|aA1A1|bA1 ….(new 3) 11/21/2017 Sampath Kumar S, AP/CSE, SECE 9
  • 10. Problems to discuss: Step 4: Now (1) is in Ai → Ajα where j<i so we apply substitution rule to convert it to GNF. A1 → aA1A2|bA2|aA1A3A2|bA3A2|a …(new 1) Final production rule: A1 → aA1A2|bA2|aA1A3A2|bA3A2|a A2 → aA1A3|bA3|aA1|b A3 → aA1A3A1A3|bA3A1A3|aA1A1A3|bA1A3| aA1A3A1|bA3A1|aA1A1|bA1 Now the given CFG is converted to GNF. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 10
  • 11. Problems to discuss: 105. Convert the following CFG to GNF S → XA|BB B → b|SB X → b A → a 106. Convert the following CFG to GNF S → CA A→ a C → aB|b 107. Convert the following CFG to GNF S → AB A→ BS|b B → SA|a 11/21/2017 Sampath Kumar S, AP/CSE, SECE 11
  • 12. Problems to discuss: 108. Convert the following CFG to GNF S → ABA A→ aA|ε B → bB|ε 109. Convert the following CFG to CNF S → AB C→ AB|b B → CA A → a 110. Convert the following CFG to CNF S → BC|a B → AC|b C → a A → b 11/21/2017 Sampath Kumar S, AP/CSE, SECE 12
  • 13. Problems to discuss: 108. Convert the following CFG to GNF S → ABA A→ aA|ε B → bB|ε 109. Convert the following CFG to CNF S → AB C→ AB|b B → CA A → a 110. Convert the following CFG to CNF S → BC|a B → AC|b C → a A → b 11/21/2017 Sampath Kumar S, AP/CSE, SECE 13
  • 14. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 15

Editor's Notes

  1. School of EECS, WSU