SlideShare a Scribd company logo
1 of 60
Chomsky and Greibach Normal
Forms
Chomsky and Greibach Normal Forms – p.1/2
Simplifying a CFG
Chomsky and Greibach Normal Forms – p.2/2
It is often convenient to simplify CFG
Simplifying a CFG
Chomsky and Greibach Normal Forms – p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
Simplifying a CFG
Chomsky and Greibach Normal Forms – p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
Another normal form usually used in algebraic
specifications is Greibach normal form
Simplifying a CFG
Chomsky and Greibach Normal Forms – p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
Another normal form usually used in algebraic
specifications is Greibach normal form
Note the difference between grammar cleaning and simplifi cation
Note
Chomsky and Greibach Normal Forms – p.3/2
Normal forms are useful when more advanced topics in
computation theory are approached, as we shall see further
Definition
Chomsky and Greibach Normal Forms – p.4/2
is in Chomsky normal form ifA context-free grammar
every rule is of the form:
where is a terminal, are nonterminals, and
may not be the start variable (the axiom)
Note
Chomsky and Greibach Normal Forms – p.5/2
The rule , where is the start variable, is not ex-
cluded from a CFG in Chomsky normal form.
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
Order of transformations: (1) add a new start variable, (2)
eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules
Theorem 2.9
Chomsky and Greibach Normal Forms – p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
Order of transformations: (1) add a new start variable, (2)
eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules
Check that the obtained CFG defi nes the same language
Proof
Chomsky and Greibach Normal Forms – p.7/2
Let be the original CFG.
Proof
Chomsky and Greibach Normal Forms – p.7/2
Let be the original CFG.
Step 1: add a new start symbol to , and the rule to
Proof
Chomsky and Greibach Normal Forms – p.7/2
Let be the original CFG.
to
does not occur
Step 1: add a new start symbol to , and the rule
Note: this change guarantees that the startsymbol of
on the of any rule
Step 2: eliminate
Chomsky and Greibach Normal Forms – p.8/2
-rules
Repeat
1. Eliminate the rule from where is not the start symbol
2. For each occurrence of on the of a rule, add a new rule to
with that occurrence of deleted
Example: replace by ;
unless the
replace by
3. Replace the rule , (if it is present) by
rule has been previously eliminated
until all rules are eliminated
Step 3: remove unit rules
Chomsky and Greibach Normal Forms – p.9/2
Repeat
1. Remove a unit rule
2. For each rule , add the rule to , unless
was a unit rule previously removed
until all unit rules are eliminated
Note: is a string of variables and terminals
Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms – p.10/2
Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms – p.10/2
Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms – p.10/2
Example CFG conversion
Chomsky and Greibach Normal Forms – p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
Example CFG conversion
Chomsky and Greibach Normal Forms – p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
Example CFG conversion
Chomsky and Greibach Normal Forms – p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
Removing
Chomsky and Greibach Normal Forms – p.12/2
rules
Removing :
Removing :
Removing
Chomsky and Greibach Normal Forms – p.12/2
rules
Removing :
Removing :
Removing
Chomsky and Greibach Normal Forms – p.12/2
rules
Removing :
Removing :
Removing unit rule
Chomsky and Greibach Normal Forms – p.13/2
Removing :
Removing :
Removing unit rule
Chomsky and Greibach Normal Forms – p.13/2
Removing :
Removing :
Removing unit rule
Chomsky and Greibach Normal Forms – p.13/2
Removing :
Removing :
More unit rules
Chomsky and Greibach Normal Forms – p.14/2
Removing :
Removing :
More unit rules
Chomsky and Greibach Normal Forms – p.14/2
Removing :
Removing :
More unit rules
Chomsky and Greibach Normal Forms – p.14/2
Removing :
Removing :
Converting remaining rules
Chomsky and Greibach Normal Forms – p.15/2
Converting remaining rules
Chomsky and Greibach Normal Forms – p.15/2
Converting remaining rules
Chomsky and Greibach Normal Forms – p.15/2
Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms – p.16/2
Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms – p.16/2
Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms – p.16/2
Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms – p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms – p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms – p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms – p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms – p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms – p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
Construction
Chomsky and Greibach Normal Forms – p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
Construction
Chomsky and Greibach Normal Forms – p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
Construction
Chomsky and Greibach Normal Forms – p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
Removing left-recursion
Chomsky and Greibach Normal Forms – p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
Removing left-recursion
Chomsky and Greibach Normal Forms – p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
Removing left-recursion
Chomsky and Greibach Normal Forms – p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
21-1
More on Greibach NF
Chomsky and Greibach Normal Forms – p.22/2
See Introduction to Automata Theory, Languages,
and Computation, J.E, Hopcroft and J.D Ullman,
Addison-Wesley 1979, p. 94–96
Example
Chomsky and Greibach Normal Forms – p.23/2
Convert the CFG
where
into Greibach normal form.
Example
Chomsky and Greibach Normal Forms – p.23/2
Convert the CFG
where
into Greibach normal form.
Example
Chomsky and Greibach Normal Forms – p.23/2
Convert the CFG
where
into Greibach normal form.
Solution
Chomsky and Greibach Normal Forms – p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal
Solution
Chomsky and Greibach Normal Forms – p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal
Solution
Chomsky and Greibach Normal Forms – p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal

More Related Content

What's hot

Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2shah zeb
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automatahafizhamza0322
 
Lecture: Context-Free Grammars
Lecture: Context-Free GrammarsLecture: Context-Free Grammars
Lecture: Context-Free GrammarsMarina Santini
 
Context free grammars
Context free grammarsContext free grammars
Context free grammarsRonak Thakkar
 
Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4Abhimanyu Mishra
 
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
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg pptShiela Rani
 
TOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationTOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationMohammad Imam Hossain
 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammarAfshanKhan51
 
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
 
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 3Abhimanyu Mishra
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)Sagar Kumar
 

What's hot (20)

Pumping lemma for cfl
Pumping lemma for cflPumping lemma for cfl
Pumping lemma for cfl
 
TOC 5 | Regular Expressions
TOC 5 | Regular ExpressionsTOC 5 | Regular Expressions
TOC 5 | Regular Expressions
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automata
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Lecture: Context-Free Grammars
Lecture: Context-Free GrammarsLecture: Context-Free Grammars
Lecture: Context-Free Grammars
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
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
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg ppt
 
TOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationTOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of Computation
 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammar
 
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
 
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
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
Strongly Connected Components
Strongly Connected Components Strongly Connected Components
Strongly Connected Components
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 

Viewers also liked

CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationDrishti Bhalla
 
Chomsky by zeeshan khan and Raheel Khan
Chomsky by zeeshan khan and Raheel KhanChomsky by zeeshan khan and Raheel Khan
Chomsky by zeeshan khan and Raheel KhanM Khan
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsAshutosh Pandey
 
Context free languages
Context free languagesContext free languages
Context free languagesJahurul Islam
 
Bakus naur form
Bakus naur formBakus naur form
Bakus naur formgrahamwell
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammarlavishka_anuj
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Abhimanyu Mishra
 
Context free langauges
Context free langaugesContext free langauges
Context free langaugessudhir sharma
 
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 2016appasami
 
Programming Haskell Chapter8
Programming Haskell Chapter8Programming Haskell Chapter8
Programming Haskell Chapter8Kousuke Ruichi
 
Meta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student VersionMeta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student VersionKelly Bauer
 
Algorithms Vs Meta Language
Algorithms Vs Meta LanguageAlgorithms Vs Meta Language
Algorithms Vs Meta LanguageKelly Bauer
 
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 papersappasami
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
Lecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsCS, NcState
 

Viewers also liked (20)

CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of Computation
 
Chomsky by zeeshan khan and Raheel Khan
Chomsky by zeeshan khan and Raheel KhanChomsky by zeeshan khan and Raheel Khan
Chomsky by zeeshan khan and Raheel Khan
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal Forms
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Bakus naur form
Bakus naur formBakus naur form
Bakus naur form
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
 
Properties of cfg
Properties of cfgProperties of cfg
Properties of cfg
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Turing machines
Turing machinesTuring machines
Turing machines
 
Turing machine by_deep
Turing machine by_deepTuring machine by_deep
Turing machine by_deep
 
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
 
Programming Haskell Chapter8
Programming Haskell Chapter8Programming Haskell Chapter8
Programming Haskell Chapter8
 
Meta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student VersionMeta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student Version
 
Algorithms Vs Meta Language
Algorithms Vs Meta LanguageAlgorithms Vs Meta Language
Algorithms Vs Meta Language
 
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
 
Control structure
Control structureControl structure
Control structure
 
Os2 2
Os2 2Os2 2
Os2 2
 
Lecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause Grammars
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower boundsRajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsRajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower boundsRajendran
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theoremRajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theoremRajendran
 
Master method
Master method Master method
Master method Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisRajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisRajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of QuicksortRajendran
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Recently uploaded

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Normal forms cfg

  • 1. Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms – p.1/2
  • 2. Simplifying a CFG Chomsky and Greibach Normal Forms – p.2/2 It is often convenient to simplify CFG
  • 3. Simplifying a CFG Chomsky and Greibach Normal Forms – p.2/2 It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form
  • 4. Simplifying a CFG Chomsky and Greibach Normal Forms – p.2/2 It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form Another normal form usually used in algebraic specifications is Greibach normal form
  • 5. Simplifying a CFG Chomsky and Greibach Normal Forms – p.2/2 It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form Another normal form usually used in algebraic specifications is Greibach normal form Note the difference between grammar cleaning and simplifi cation
  • 6. Note Chomsky and Greibach Normal Forms – p.3/2 Normal forms are useful when more advanced topics in computation theory are approached, as we shall see further
  • 7. Definition Chomsky and Greibach Normal Forms – p.4/2 is in Chomsky normal form ifA context-free grammar every rule is of the form: where is a terminal, are nonterminals, and may not be the start variable (the axiom)
  • 8. Note Chomsky and Greibach Normal Forms – p.5/2 The rule , where is the start variable, is not ex- cluded from a CFG in Chomsky normal form.
  • 9. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form.
  • 10. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea:
  • 11. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG can be converted into a CFG in Chomsky normal form
  • 12. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG can be converted into a CFG in Chomsky normal form Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions
  • 13. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG can be converted into a CFG in Chomsky normal form Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions Order of transformations: (1) add a new start variable, (2) eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules
  • 14. Theorem 2.9 Chomsky and Greibach Normal Forms – p.6/2 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG can be converted into a CFG in Chomsky normal form Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions Order of transformations: (1) add a new start variable, (2) eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules Check that the obtained CFG defi nes the same language
  • 15. Proof Chomsky and Greibach Normal Forms – p.7/2 Let be the original CFG.
  • 16. Proof Chomsky and Greibach Normal Forms – p.7/2 Let be the original CFG. Step 1: add a new start symbol to , and the rule to
  • 17. Proof Chomsky and Greibach Normal Forms – p.7/2 Let be the original CFG. to does not occur Step 1: add a new start symbol to , and the rule Note: this change guarantees that the startsymbol of on the of any rule
  • 18. Step 2: eliminate Chomsky and Greibach Normal Forms – p.8/2 -rules Repeat 1. Eliminate the rule from where is not the start symbol 2. For each occurrence of on the of a rule, add a new rule to with that occurrence of deleted Example: replace by ; unless the replace by 3. Replace the rule , (if it is present) by rule has been previously eliminated until all rules are eliminated
  • 19. Step 3: remove unit rules Chomsky and Greibach Normal Forms – p.9/2 Repeat 1. Remove a unit rule 2. For each rule , add the rule to , unless was a unit rule previously removed until all unit rules are eliminated Note: is a string of variables and terminals
  • 20. Convert all remaining rules Repeat , , where each , ,1. Replace a rule is a variable or a terminal, by: , , , are new variables replace any terminal with a new variable and add the where , , , 2. If rule withuntil no rules of the form remain Chomsky and Greibach Normal Forms – p.10/2
  • 21. Convert all remaining rules Repeat , , where each , ,1. Replace a rule is a variable or a terminal, by: , , , are new variables replace any terminal with a new variable and add the where , , , 2. If rule withuntil no rules of the form remain Chomsky and Greibach Normal Forms – p.10/2
  • 22. Convert all remaining rules Repeat , , where each , ,1. Replace a rule is a variable or a terminal, by: , , , are new variables replace any terminal with a new variable and add the where , , , 2. If rule withuntil no rules of the form remain Chomsky and Greibach Normal Forms – p.10/2
  • 23. Example CFG conversion Chomsky and Greibach Normal Forms – p.11/2 Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After fi rst step of transformation we get:
  • 24. Example CFG conversion Chomsky and Greibach Normal Forms – p.11/2 Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After fi rst step of transformation we get:
  • 25. Example CFG conversion Chomsky and Greibach Normal Forms – p.11/2 Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After fi rst step of transformation we get:
  • 26. Removing Chomsky and Greibach Normal Forms – p.12/2 rules Removing : Removing :
  • 27. Removing Chomsky and Greibach Normal Forms – p.12/2 rules Removing : Removing :
  • 28. Removing Chomsky and Greibach Normal Forms – p.12/2 rules Removing : Removing :
  • 29. Removing unit rule Chomsky and Greibach Normal Forms – p.13/2 Removing : Removing :
  • 30. Removing unit rule Chomsky and Greibach Normal Forms – p.13/2 Removing : Removing :
  • 31. Removing unit rule Chomsky and Greibach Normal Forms – p.13/2 Removing : Removing :
  • 32. More unit rules Chomsky and Greibach Normal Forms – p.14/2 Removing : Removing :
  • 33. More unit rules Chomsky and Greibach Normal Forms – p.14/2 Removing : Removing :
  • 34. More unit rules Chomsky and Greibach Normal Forms – p.14/2 Removing : Removing :
  • 35. Converting remaining rules Chomsky and Greibach Normal Forms – p.15/2
  • 36. Converting remaining rules Chomsky and Greibach Normal Forms – p.15/2
  • 37. Converting remaining rules Chomsky and Greibach Normal Forms – p.15/2
  • 38. Note The conversion procedure produces several variables along with several rules . Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms – p.16/2
  • 39. Note The conversion procedure produces several variables along with several rules . Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms – p.16/2
  • 40. Note The conversion procedure produces several variables along with several rules . Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms – p.16/2
  • 41. Greibach Normal Form is in has the and A context-free grammar Greibach normal form if each rule property: , , . Chomsky and Greibach Normal Forms – p.17/2 Note: Greibach normal form provides a justifi ca- tion of operator prefi x-notation usually employed in algebra.
  • 42. Greibach Normal Form is in has the and A context-free grammar Greibach normal form if each rule property: , , . Chomsky and Greibach Normal Forms – p.17/2 Note: Greibach normal form provides a justifi ca- tion of operator prefi x-notation usually employed in algebra.
  • 43. Greibach Normal Form is in has the and A context-free grammar Greibach normal form if each rule property: , , . Chomsky and Greibach Normal Forms – p.17/2 Note: Greibach normal form provides a justifi ca- tion of operator prefi x-notation usually employed in algebra.
  • 44. Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Chomsky and Greibach Normal Forms – p.18/2 be a CFG generating . Assume thatProof idea: Let is in Chomsky normal form Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form
  • 45. Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Chomsky and Greibach Normal Forms – p.18/2 be a CFG generating . Assume thatProof idea: Let is in Chomsky normal form Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form
  • 46. Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Chomsky and Greibach Normal Forms – p.18/2 be a CFG generating . Assume thatProof idea: Let is in Chomsky normal form Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form
  • 47. Construction Chomsky and Greibach Normal Forms – p.19/2 so that if1. Modify the rules in 2. Starting with and proceeding to then this is done as follows: (a) Assume that productions have been modifi ed so that for , (b) If only if is a production with , generate a new set of the rhs of eachproductions substituting for the production times we obtain rules of the form(c) Repeating (b) at most , (d) Replace rules by removing left-recursive rules
  • 48. Construction Chomsky and Greibach Normal Forms – p.19/2 so that if1. Modify the rules in 2. Starting with and proceeding to then this is done as follows: (a) Assume that productions have been modifi ed so that for , (b) If only if is a production with , generate a new set of the rhs of eachproductions substituting for the production times we obtain rules of the form(c) Repeating (b) at most , (d) Replace rules by removing left-recursive rules
  • 49. Construction Chomsky and Greibach Normal Forms – p.19/2 so that if1. Modify the rules in 2. Starting with and proceeding to then this is done as follows: (a) Assume that productions have been modifi ed so that for , (b) If only if is a production with , generate a new set of the rhs of eachproductions substituting for the production times we obtain rules of the form(c) Repeating (b) at most , (d) Replace rules by removing left-recursive rules
  • 50. Removing left-recursion Chomsky and Greibach Normal Forms – p.20/2 Left-recursion can be eliminated by the following scheme: If are all left recursive rules, and are all remaining -rules then chose a new nonterminal, sayAdd the new Replace the -rules , -rules by , This construction preserve the language .
  • 51. Removing left-recursion Chomsky and Greibach Normal Forms – p.20/2 Left-recursion can be eliminated by the following scheme: If are all left recursive rules, and are all remaining -rules then chose a new nonterminal, sayAdd the new Replace the -rules , -rules by , This construction preserve the language .
  • 52. Removing left-recursion Chomsky and Greibach Normal Forms – p.20/2 Left-recursion can be eliminated by the following scheme: If are all left recursive rules, and are all remaining -rules then chose a new nonterminal, sayAdd the new Replace the -rules , -rules by , This construction preserve the language .
  • 53. 21-1
  • 54. More on Greibach NF Chomsky and Greibach Normal Forms – p.22/2 See Introduction to Automata Theory, Languages, and Computation, J.E, Hopcroft and J.D Ullman, Addison-Wesley 1979, p. 94–96
  • 55. Example Chomsky and Greibach Normal Forms – p.23/2 Convert the CFG where into Greibach normal form.
  • 56. Example Chomsky and Greibach Normal Forms – p.23/2 Convert the CFG where into Greibach normal form.
  • 57. Example Chomsky and Greibach Normal Forms – p.23/2 Convert the CFG where into Greibach normal form.
  • 58. Solution Chomsky and Greibach Normal Forms – p.24/2 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get: , 3. All rules start with a terminal. We use them to replace . This introduces the rules 4. Use production to make them start with a terminal
  • 59. Solution Chomsky and Greibach Normal Forms – p.24/2 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get: , 3. All rules start with a terminal. We use them to replace . This introduces the rules 4. Use production to make them start with a terminal
  • 60. Solution Chomsky and Greibach Normal Forms – p.24/2 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get: , 3. All rules start with a terminal. We use them to replace . This introduces the rules 4. Use production to make them start with a terminal