SlideShare a Scribd company logo
6
Most read
9
Most read
10
Most read
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

PPTX
Chomsky Normal Form
PPTX
Two-way Deterministic Finite Automata
PPTX
Graph coloring using backtracking
PPTX
Automata theory - Push Down Automata (PDA)
PPTX
Introduction TO Finite Automata
PPTX
2.7 normal forms cnf & problems
PPTX
Types of grammer - TOC
PDF
Automata theory
Chomsky Normal Form
Two-way Deterministic Finite Automata
Graph coloring using backtracking
Automata theory - Push Down Automata (PDA)
Introduction TO Finite Automata
2.7 normal forms cnf & problems
Types of grammer - TOC
Automata theory

What's hot (20)

PPTX
Memory management ppt
PPTX
Algorithm and pseudocode conventions
PPTX
Instruction pipeline: Computer Architecture
PPTX
Simplification of cfg ppt
PPTX
Computer registers
PPTX
Moore and mealy machine
PDF
Deterministic Finite Automata (DFA)
PPTX
8 queens problem using back tracking
PPT
Memory management
PPTX
Computer architecture virtual memory
PPT
Shared memory
PPT
pushdown automata
PPTX
Push down automata
PPT
Greedy Algorihm
PDF
Code optimization in compiler design
PPT
NFA or Non deterministic finite automata
PPTX
Predicate logic
PPT
Np cooks theorem
PPTX
Generating code from dags
PPTX
Minmax Algorithm In Artificial Intelligence slides
Memory management ppt
Algorithm and pseudocode conventions
Instruction pipeline: Computer Architecture
Simplification of cfg ppt
Computer registers
Moore and mealy machine
Deterministic Finite Automata (DFA)
8 queens problem using back tracking
Memory management
Computer architecture virtual memory
Shared memory
pushdown automata
Push down automata
Greedy Algorihm
Code optimization in compiler design
NFA or Non deterministic finite automata
Predicate logic
Np cooks theorem
Generating code from dags
Minmax Algorithm In Artificial Intelligence slides
Ad

Similar to 2.8 normal forms gnf &amp; problems (20)

PPTX
Theory of competition topic simplification of cfg, normal form of FG.pptx
PPT
Simplifies and normal forms - Theory of Computation
DOCX
Normal Forms for Context Free Grammers.docx
PPTX
AUTOMATA AUTOMATA Automata8Chapter7.pptx
PPT
Toc CFG cfl properties
PDF
TOC 7 | CFG in Chomsky Normal Form
PPTX
Theory of Automata and formal languages Unit 3
PDF
The Greibach normal form is referred to as GNF gnf1.pdf
PPT
Video lecture for bca
PPTX
CNF & Leftmost Derivation - Theory of Computation
PPTX
CFG to CNF
PPT
Chomsky by zeeshan khan and Raheel Khan
PPT
NORMAL-FORMS.ppt
PPT
NORMAL-FORMS.ppt
PDF
Normal Forms for CFG's.pdf
PPTX
Normal forms cfg
PDF
Theory of Computation FSM Grammar Minimisation and Normal Forms
PPT
Lec-hdbehebensjshshsus28 Grammatical Format.ppt
PPT
Chomsky_Greibach-Hector-Chavez.ppt
Theory of competition topic simplification of cfg, normal form of FG.pptx
Simplifies and normal forms - Theory of Computation
Normal Forms for Context Free Grammers.docx
AUTOMATA AUTOMATA Automata8Chapter7.pptx
Toc CFG cfl properties
TOC 7 | CFG in Chomsky Normal Form
Theory of Automata and formal languages Unit 3
The Greibach normal form is referred to as GNF gnf1.pdf
Video lecture for bca
CNF & Leftmost Derivation - Theory of Computation
CFG to CNF
Chomsky by zeeshan khan and Raheel Khan
NORMAL-FORMS.ppt
NORMAL-FORMS.ppt
Normal Forms for CFG's.pdf
Normal forms cfg
Theory of Computation FSM Grammar Minimisation and Normal Forms
Lec-hdbehebensjshshsus28 Grammatical Format.ppt
Chomsky_Greibach-Hector-Chavez.ppt
Ad

More from Sampath Kumar S (20)

PPTX
5.2 primitive recursive functions
PPTX
4.7. chomskian hierarchy of languages
PPTX
4.6 halting problem
PPTX
4.3 techniques for turing machines construction
PPTX
4.2 variantsof turing machines (types of tm)
PPTX
4.1 turing machines
PPTX
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
PPTX
3.5 equivalence of pushdown automata and cfl
PPTX
3.4 deterministic pda
PPTX
3.1,2,3 pushdown automata definition, moves &amp; id
PPTX
2.5 ambiguity in context free grammars
PPTX
2.4 derivations and languages
PPTX
2.3 context free grammars and languages
PPTX
2.1 & 2.2 grammar introduction – types of grammar
PPTX
1.10. pumping lemma for regular sets
PPTX
1.9. minimization of dfa
PPTX
1.8. equivalence of finite automaton and regular expressions
PPTX
1.7. eqivalence of nfa and dfa
PPTX
1.5 & 1.6 regular languages &amp; regular expression
PPTX
1.4. finite automaton with ε moves
5.2 primitive recursive functions
4.7. chomskian hierarchy of languages
4.6 halting problem
4.3 techniques for turing machines construction
4.2 variantsof turing machines (types of tm)
4.1 turing machines
3.6 &amp; 7. pumping lemma for cfl &amp; problems based on pl
3.5 equivalence of pushdown automata and cfl
3.4 deterministic pda
3.1,2,3 pushdown automata definition, moves &amp; id
2.5 ambiguity in context free grammars
2.4 derivations and languages
2.3 context free grammars and languages
2.1 & 2.2 grammar introduction – types of grammar
1.10. pumping lemma for regular sets
1.9. minimization of dfa
1.8. equivalence of finite automaton and regular expressions
1.7. eqivalence of nfa and dfa
1.5 & 1.6 regular languages &amp; regular expression
1.4. finite automaton with ε moves

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PDF
Pre independence Education in Inndia.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Pharma ospi slides which help in ospi learning
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Classroom Observation Tools for Teachers
PPTX
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
Pre independence Education in Inndia.pdf
PPH.pptx obstetrics and gynecology in nursing
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Module 4: Burden of Disease Tutorial Slides S2 2025
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Anesthesia in Laparoscopic Surgery in India
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Classroom Observation Tools for Teachers
Institutional Correction lecture only . . .

2.8 normal forms gnf &amp; problems

  • 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

  • #2: School of EECS, WSU