SlideShare a Scribd company logo
Costas Busch - LSU 1
Simplifications
of
Context-Free Grammars
Costas Busch - LSU 2
A Substitution Rule
bB
aAB
abBcA
aaAA
aBS





Substitute
Equivalent
grammar
aAB
abbcabBcA
aaAA
abaBS




|
|
bB 
Costas Busch - LSU 3
Equivalent
grammarabaAcabbcabBcA
aaAA
aaAabaBS
||
||



aAB
abbcabBcA
aaAA
abaBS




|
|
Substitute
aAB 
Costas Busch - LSU 4
In general:
1yB
xBzA


Substitute
zxyxBzA 1|
equivalent
grammar
1yB 
Costas Busch - LSU 5
Nullable Variables
:production X
Nullable Variable: Y
Example:



M
aMbM
aMbS
Nullable variable production
Costas Busch - LSU 6
M



M
aMbM
aMbS
Substitute
abaMbM
abaMbS
|
|


Removing sproduction
After we remove all the
all the nullable variables disappear
(except for the start variable)
sproduction
Costas Busch - LSU 7
Unit-Productions
YX Unit Production:
(a single variable in both sides)
bbB
AB
BA
aA
aAS




Example:
Unit Productions
Costas Busch - LSU 8
bbB
AB
BA
aA
aAS





Substitute
BA 
bbB
BAB
aA
aBaAS




|
|
Removal of unit productions:
Costas Busch - LSU 9
Remove
bbB
BAB
aA
aBaAS




|
|
bbB
AB
aA
aBaAS



 |
BB 
XX 
can be removed immediately
Unit productions of form
Costas Busch - LSU 10
Substitute
AB 
bbB
aA
aAaBaAS


 ||
bbB
AB
aA
aBaAS



 |
Costas Busch - LSU 11
Remove repeated productions
bbB
aA
aBaAS


 |
bbB
aA
aAaBaAS


 ||
Final grammar
Costas Busch - LSU 12
Useless Productions
aAA
AS
S
aSbS





  aAaaaaAaAAS
Some derivations never terminate...
Useless Production
Costas Busch - LSU 13
bAB
A
aAA
AS





Another grammar:
Not reachable from S
Useless Production
Costas Busch - LSU 14
In general:
If there is a derivation
)(GLwxAyS  
Then variable is usefulA
Otherwise, variable is uselessA
consists of
terminals
Costas Busch - LSU 15
A production is useless
if any of its variables is useless
xA 
DC
CB
aAA
AS
S
aSbS






 Productions
useless
useless
useless
useless
Variables
useless
useless
useless
Costas Busch - LSU 16
Example Grammar:
aCbC
aaB
aA
CAaSS



 ||
Removing Useless Variables and Productions
Costas Busch - LSU 17
First: find all variables that can produce
strings with only terminals or
aCbC
aaB
aA
CAaSS



 || },{ BA
},,{ SBA
Round 1:
Round 2:
(possible useful variables)

(the right hand side of production
that has only terminals)
(the right hand side of a production
has terminals and
variables of previous round)
This process can be generalized
Costas Busch - LSU 18
Then, remove productions that use variables
other than
aCbC
aaB
aA
CAaSS



 ||
},,{ SBA
aaB
aA
AaSS


 |
Costas Busch - LSU 19
Second: Find all variables
reachable from
aaB
aA
AaSS


 |
S A B
Use a Dependency Graph
where nodes are variables
unreachable
S
Costas Busch - LSU 20
Keep only the variables
reachable from S
aaB
aA
AaSS


 |
aA
AaSS

 |
Final Grammar
Contains only
useful variables
Costas Busch - LSU 21
Removing All
Step 1: Remove Nullable Variables
Step 2: Remove Unit-Productions
Step 3: Remove Useless Variables
This sequence guarantees that
unwanted variables and productions
are removed

More Related Content

PPTX
Context free grammars
PPTX
Properties of Regular Expressions
PPT
Dfa example
PPTX
POTW Solution!
PDF
Regular properties 2
PDF
Asymmetric multipartite GHZ states and Bell inequalities
PPTX
CNF & Leftmost Derivation - Theory of Computation
PDF
Karnaugh
Context free grammars
Properties of Regular Expressions
Dfa example
POTW Solution!
Regular properties 2
Asymmetric multipartite GHZ states and Bell inequalities
CNF & Leftmost Derivation - Theory of Computation
Karnaugh

Viewers also liked (16)

PPTX
Tania
PPT
Telecom lect 4
PPTX
Languages
PPT
Analog Transmission
PPTX
Agile pm lect1
PPTX
Turing variations
PPTX
Universal turing coastus
PPTX
Theory of Computation
PPTX
Finite Automata
PPT
Telecom lect 3
PPT
Telecom lect 8
PPT
Telecom lect 2
PPT
Telecom lect 5
PPT
Wifi & wi max
PPTX
Martin folwer
PPTX
Machine Learning
Tania
Telecom lect 4
Languages
Analog Transmission
Agile pm lect1
Turing variations
Universal turing coastus
Theory of Computation
Finite Automata
Telecom lect 3
Telecom lect 8
Telecom lect 2
Telecom lect 5
Wifi & wi max
Martin folwer
Machine Learning
Ad

Similar to context free grammars_simplification (20)

PPT
Simplifiaction of grammar
PDF
Theory of Computation FSM Grammar Minimisation and Normal Forms
PPTX
BCS503 TOC Module 4 PPT.pptx V SEM CSE PPT
PDF
Normal Forms for CFG's.pdf
PPT
NORMAL-FORMS.ppt
PPT
NORMAL-FORMS.ppt
PDF
Context Free Grammar
PPT
Normal-forms-for-Context-Free-Grammars.ppt
PPT
context-freelanguages and properties lecture note.ppt
PPTX
Theory of Automata and CGFG for learning
PPT
Context Free Languages by S.Mandal-1.ppt
PPT
Context free grammer.ppt
PPT
Unit-2 Context free grammer. ppt CFG CFL
PDF
Syntax Analyzer.pdf
PPTX
Eliminating ^ production and Unit Production from a CFG.pptx
PPT
Simplifies and normal forms - Theory of Computation
PPT
Context-Free Languages under theory of automata.ppt
PPTX
Natural Language Processing - Writing Grammar
PPT
Chomsky & Greibach Normal Forms
PPT
Toc CFG cfl properties
Simplifiaction of grammar
Theory of Computation FSM Grammar Minimisation and Normal Forms
BCS503 TOC Module 4 PPT.pptx V SEM CSE PPT
Normal Forms for CFG's.pdf
NORMAL-FORMS.ppt
NORMAL-FORMS.ppt
Context Free Grammar
Normal-forms-for-Context-Free-Grammars.ppt
context-freelanguages and properties lecture note.ppt
Theory of Automata and CGFG for learning
Context Free Languages by S.Mandal-1.ppt
Context free grammer.ppt
Unit-2 Context free grammer. ppt CFG CFL
Syntax Analyzer.pdf
Eliminating ^ production and Unit Production from a CFG.pptx
Simplifies and normal forms - Theory of Computation
Context-Free Languages under theory of automata.ppt
Natural Language Processing - Writing Grammar
Chomsky & Greibach Normal Forms
Toc CFG cfl properties
Ad

More from Shiraz316 (20)

PPTX
FINGERNAIL DISORDER DETECTION FOR DISEASE ANALYSIS
PPTX
K neareast neighbor algorithm presentation
PPTX
Khi 087 revised dt report
PPTX
Khi 117 revised dt report
PPTX
Khi 164 revised dt report
PPTX
Khi 054 revised dt report
PPTX
Khi 061 revised dt report
PPTX
Khi 022 revised dt report
PPTX
Khi 113 revised dt report
PPTX
Khi 156 revised dt report
PPTX
Khi 142 revised dt report
PPTX
Khi 316 revised dt report
PPTX
Khi 186 revised dt report
PPTX
Khi 052 revised dt report
PPTX
Khi 151 revised dt report
PPTX
Khi 150 revised dt report
PPTX
Khi 078 revised dt report
PPTX
LTE quick introduction session Training
PPTX
LTE Sales Training for CPE Device
PPTX
Witribe Customer Premises Equipment Training for LTE
FINGERNAIL DISORDER DETECTION FOR DISEASE ANALYSIS
K neareast neighbor algorithm presentation
Khi 087 revised dt report
Khi 117 revised dt report
Khi 164 revised dt report
Khi 054 revised dt report
Khi 061 revised dt report
Khi 022 revised dt report
Khi 113 revised dt report
Khi 156 revised dt report
Khi 142 revised dt report
Khi 316 revised dt report
Khi 186 revised dt report
Khi 052 revised dt report
Khi 151 revised dt report
Khi 150 revised dt report
Khi 078 revised dt report
LTE quick introduction session Training
LTE Sales Training for CPE Device
Witribe Customer Premises Equipment Training for LTE

Recently uploaded (20)

PPTX
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
PDF
BIOCHEM CH2 OVERVIEW OF MICROBIOLOGY.pdf
PDF
Session 1 (Week 1)fghjmgfdsfgthyjkhfdsadfghjkhgfdsa
PDF
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
PPTX
Internet Safety for Seniors presentation
PDF
Uptota Investor Deck - Where Africa Meets Blockchain
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PPTX
Introduction to cybersecurity and digital nettiquette
PPTX
Database Information System - Management Information System
PDF
The Evolution of Traditional to New Media .pdf
PDF
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
PPTX
Slides PPTX: World Game (s): Eco Economic Epochs.pptx
PDF
Introduction to the IoT system, how the IoT system works
PPT
Ethics in Information System - Management Information System
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
Understand the Gitlab_presentation_task.pdf
PDF
Alethe Consulting Corporate Profile and Solution Aproach
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPT
250152213-Excitation-SystemWERRT (1).ppt
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
BIOCHEM CH2 OVERVIEW OF MICROBIOLOGY.pdf
Session 1 (Week 1)fghjmgfdsfgthyjkhfdsadfghjkhgfdsa
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
Internet Safety for Seniors presentation
Uptota Investor Deck - Where Africa Meets Blockchain
Exploring VPS Hosting Trends for SMBs in 2025
Mathew Digital SEO Checklist Guidlines 2025
Introduction to cybersecurity and digital nettiquette
Database Information System - Management Information System
The Evolution of Traditional to New Media .pdf
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
Slides PPTX: World Game (s): Eco Economic Epochs.pptx
Introduction to the IoT system, how the IoT system works
Ethics in Information System - Management Information System
Power Point - Lesson 3_2.pptx grad school presentation
Understand the Gitlab_presentation_task.pdf
Alethe Consulting Corporate Profile and Solution Aproach
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
250152213-Excitation-SystemWERRT (1).ppt

context free grammars_simplification

  • 1. Costas Busch - LSU 1 Simplifications of Context-Free Grammars
  • 2. Costas Busch - LSU 2 A Substitution Rule bB aAB abBcA aaAA aBS      Substitute Equivalent grammar aAB abbcabBcA aaAA abaBS     | | bB 
  • 3. Costas Busch - LSU 3 Equivalent grammarabaAcabbcabBcA aaAA aaAabaBS || ||    aAB abbcabBcA aaAA abaBS     | | Substitute aAB 
  • 4. Costas Busch - LSU 4 In general: 1yB xBzA   Substitute zxyxBzA 1| equivalent grammar 1yB 
  • 5. Costas Busch - LSU 5 Nullable Variables :production X Nullable Variable: Y Example:    M aMbM aMbS Nullable variable production
  • 6. Costas Busch - LSU 6 M    M aMbM aMbS Substitute abaMbM abaMbS | |   Removing sproduction After we remove all the all the nullable variables disappear (except for the start variable) sproduction
  • 7. Costas Busch - LSU 7 Unit-Productions YX Unit Production: (a single variable in both sides) bbB AB BA aA aAS     Example: Unit Productions
  • 8. Costas Busch - LSU 8 bbB AB BA aA aAS      Substitute BA  bbB BAB aA aBaAS     | | Removal of unit productions:
  • 9. Costas Busch - LSU 9 Remove bbB BAB aA aBaAS     | | bbB AB aA aBaAS     | BB  XX  can be removed immediately Unit productions of form
  • 10. Costas Busch - LSU 10 Substitute AB  bbB aA aAaBaAS    || bbB AB aA aBaAS     |
  • 11. Costas Busch - LSU 11 Remove repeated productions bbB aA aBaAS    | bbB aA aAaBaAS    || Final grammar
  • 12. Costas Busch - LSU 12 Useless Productions aAA AS S aSbS        aAaaaaAaAAS Some derivations never terminate... Useless Production
  • 13. Costas Busch - LSU 13 bAB A aAA AS      Another grammar: Not reachable from S Useless Production
  • 14. Costas Busch - LSU 14 In general: If there is a derivation )(GLwxAyS   Then variable is usefulA Otherwise, variable is uselessA consists of terminals
  • 15. Costas Busch - LSU 15 A production is useless if any of its variables is useless xA  DC CB aAA AS S aSbS        Productions useless useless useless useless Variables useless useless useless
  • 16. Costas Busch - LSU 16 Example Grammar: aCbC aaB aA CAaSS     || Removing Useless Variables and Productions
  • 17. Costas Busch - LSU 17 First: find all variables that can produce strings with only terminals or aCbC aaB aA CAaSS     || },{ BA },,{ SBA Round 1: Round 2: (possible useful variables)  (the right hand side of production that has only terminals) (the right hand side of a production has terminals and variables of previous round) This process can be generalized
  • 18. Costas Busch - LSU 18 Then, remove productions that use variables other than aCbC aaB aA CAaSS     || },,{ SBA aaB aA AaSS    |
  • 19. Costas Busch - LSU 19 Second: Find all variables reachable from aaB aA AaSS    | S A B Use a Dependency Graph where nodes are variables unreachable S
  • 20. Costas Busch - LSU 20 Keep only the variables reachable from S aaB aA AaSS    | aA AaSS   | Final Grammar Contains only useful variables
  • 21. Costas Busch - LSU 21 Removing All Step 1: Remove Nullable Variables Step 2: Remove Unit-Productions Step 3: Remove Useless Variables This sequence guarantees that unwanted variables and productions are removed