SlideShare una empresa de Scribd logo
1 de 44
Hector Miguel Chavez
Western Michigan University
Presentation Outline
2
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Introduction
3
May 27, 2009
Grammar: G = (V, T, P, S)
T = { a, b }
Terminals
V = A, B, C
Variables
S
Start Symbol
P = S → A
Production
Introduction
4
May 27, 2009
Grammar example
S → aBSc
S → abc
Ba → aB
Bb → bb
L = { anbncn | n ≥ 1 }
S aBSc aBabcc aaBbcc aabbcc
   
Introduction
5
May 27, 2009
Context free grammar
The head of any production contains only one
non-terminal symbol
S → P
P → aPb
P → ε
L = { anbn | n ≥ 0 }
Presentation Outline
6
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final simplification
• Greibach Normal Form
• Algorithm (Example)
• Summary
Chomsky Normal Form
7
May 27, 2009
A → BC
A → α
A context free grammar is said to be in Chomsky
Normal Form if all productions are in the following
form:
• A, B and C are non terminal symbols
• α is a terminal symbol
Presentation Outline
8
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Preliminary Simplifications
9
May 27, 2009
Eliminate Useless Symbols
1
Eliminate ε productions
2
Eliminate unit productions
3
There are three preliminary simplifications
Preliminary Simplifications
10
May 27, 2009
Eliminate Useless Symbols
We need to determine if the symbol is useful by
identifying if a symbol is generating and is reachable
• X is generating if X ω for some terminal string ω.
• X is reachable if there is a derivation X αXβ
for some α and β


*
*
Preliminary Simplifications
11
May 27, 2009
Example: Removing non-generating symbols
S → AB | a
A → b Initial CFL grammar
S → AB | a
A → b
Identify generating symbols
S → a
A → b
Remove non-generating
Preliminary Simplifications
12
May 27, 2009
Example: Removing non-reachable symbols
S → a Eliminate non-reachable
S → a
A → b
Identify reachable symbols
Preliminary Simplifications
13
May 27, 2009
The order is important.
S → AB | a
A → b
Looking first for non-reachable symbols and then
for non-generating symbols can still leave some
useless symbols.
S → a
A → b
Preliminary Simplifications
14
May 27, 2009
Finding generating symbols
If there is a production A → α, and every symbol
of α is already known to be generating. Then A is
generating
S → AB | a
A → b
We cannot use S → AB because
B has not been established to
be generating
Preliminary Simplifications
15
May 27, 2009
Finding reachable symbols
S is surely reachable. All symbols in the body of a
production with S in the head are reachable.
S → AB | a
A → b
In this example the symbols
{S, A, B, a, b} are reachable.
Preliminary Simplifications
16
May 27, 2009
Eliminate Useless Symbols
1
Eliminate ε productions
2
Eliminate unit productions
3
There are three preliminary simplifications
Preliminary Simplifications
17
May 27, 2009
Eliminate ε Productions
• In a grammar ε productions are convenient but
not essential
• If L has a CFG, then L – {ε} has a CFG
Nullable variable
A ε

*
Preliminary Simplifications
18
May 27, 2009
If A is a nullable variable
• Whenever A appears on the body of a production
A might or might not derive ε
S → ASA | aB
A → B | S
B → b | ε
Nullable: {A, B}
Preliminary Simplifications
19
May 27, 2009
• Create two version of the production, one with
the nullable variable and one without it
• Eliminate productions with ε bodies
S → ASA | aB
A → B | S
B → b | ε
S → ASA | aB | AS | SA | S | a
A → B | S
B → b
Eliminate ε Productions
Preliminary Simplifications
20
May 27, 2009
• Create two version of the production, one with
the nullable variable and one without it
• Eliminate productions with ε bodies
S → ASA | aB
A → B | S
B → b | ε
S → ASA | aB | AS | SA | S | a
A → B | S
B → b
Eliminate ε Productions
Preliminary Simplifications
21
May 27, 2009
• Create two version of the production, one with
the nullable variable and one without it
• Eliminate productions with ε bodies
S → ASA | aB
A → B | S
B → b | ε
S → ASA | aB | AS | SA | S | a
A → B | S
B → b
Eliminate ε Productions
Preliminary Simplifications
22
May 27, 2009
Eliminate Useless Symbols
1
Eliminate ε productions
2
Eliminate unit productions
3
There are three preliminary simplifications
Preliminary Simplifications
23
May 27, 2009
Eliminate unit productions
A unit production is one of the form A → B where both
A and B are variables
A B

*
A → B, B → ω, then A → ω
Identify unit pairs
Preliminary Simplifications
24
May 27, 2009
Example:
I → a | b | Ia | Ib | I0 | I1
F → I | (E)
T → F | T * F
E → T | E + T
Pairs Productions
( E, E ) E → E + T
( E, T ) E → T * F
( E, F ) E → (E)
( E, I ) E → a | b | Ia | Ib | I0 | I1
( T, T ) T → T * F
( T, F ) T → (E)
( T, I ) T → a | b | Ia |Ib | I0 | I1
( F, F ) F → (E)
( F, I ) F → a | b | Ia | Ib | I0 | I1
( I, I ) I → a | b | Ia | Ib | I0 | I1
Basis: (A, A) is a unit pair
of any variable A, if
A A by 0 steps.

*
T = {*, +, (, ), a, b, 0, 1}
Preliminary Simplifications
25
May 27, 2009
Example:
Pairs Productions
… …
( T, T ) T → T * F
( T, F ) T → (E)
( T, I ) T → a | b | Ia |Ib | I0 | I1
… …
I → a | b | Ia | Ib | I0 | I1
E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1
T → T * F | (E) | a | b | Ia | Ib | I0 | I1
F → (E) | a | b | Ia | Ib | I0 | I1
Presentation Outline
26
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Final Simplification
27
May 27, 2009
Chomsky Normal Form (CNF)
1. Arrange that all bodies of length 2 or more to
consists only of variables.
2. Break bodies of length 3 or more into a cascade of
productions, each with a body consisting of two
variables.
Starting with a CFL grammar with the preliminary
simplifications performed
Final Simplification
28
May 27, 2009
Step 1: For every terminal α that appears in a body
of length 2 or more create a new variable that has
only one production.
E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1
T → T * F | (E) | a | b | Ia | Ib | I0 | I1
F → (E) | a | b | Ia | Ib | I0 | I1
I → a | b | Ia | Ib | I0 | I1
E → EPT | TMF | LER | a | b | lA | lB | lZ | lO
T → TMF | LER | a | b | IA | IB | IZ | IO
F → LER | a | b | IA | IB | IZ | IO
I → a | b | IA | IB | IZ | IO
A → a B → b Z → 0 O → 1
P → + M → * L → ( R → )
Final Simplification
29
May 27, 2009
Step 2: Break bodies of length 3 or more adding
more variables
E → EPT | TMF | LER | a | b | lA | lB | lZ | lO
T → TMF | LER | a | b | IA | IB | IZ | IO
F → LER | a | b | IA | IB | IZ | IO
I → a | b | IA | IB | IZ | IO
A → a B → b Z → 0 O → 1
P → + M → * L → ( R → )
C1 → PT
C2 → MF
C3 → ER
Presentation Outline
30
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Greibach Normal Form
31
May 27, 2009
A → αX
A context free grammar is said to be in Greibach
Normal Form if all productions are in the following
form:
• A is a non terminal symbols
• α is a terminal symbol
• X is a sequence of non terminal symbols.
It may be empty.
Presentation Outline
32
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Greibach Normal Form
33
May 27, 2009
Example:
S → XA | BB
B → b | SB
X → b
A → a
CNF
S = A1
X = A2
A = A3
B = A4
New Labels
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
Updated CNF
Greibach Normal Form
34
May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
First Step
Xk is a string of zero
or more variables
Ai → AjXk j > i
A4 → A1A4
Greibach Normal Form
35
May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → b | A1A4
A2 → b
A3 → a
A4 → A1A4
A4 → A2A3A4 | A4A4A4 | b
A4 → bA3A4 | A4A4A4 | b
First Step Ai → AjXk j > i
Greibach Normal Form
36
May 27, 2009
Example:
Second Step
Eliminate Left
Recursions
A1 → A2A3 | A4A4
A4 → bA3A4 | A4A4A4 | b
A2 → b
A3 → a
A4 → A4A4A4
Greibach Normal Form
37
May 27, 2009
Example:
Second Step
Eliminate Left
Recursions
A1 → A2A3 | A4A4
A4 → bA3A4 | A4A4A4 | b
A2 → b
A3 → a
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4Z
Greibach Normal Form
38
May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
A → αX
GNF
Greibach Normal Form
39
May 27, 2009
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
Greibach Normal Form
40
May 27, 2009
Example:
A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
A2 → b
A3 → a
Grammar in Greibach Normal Form
Presentation Outline
41
May 27, 2009
Summary (Some properties)
• Every CFG that doesn’t generate the empty string
can be simplified to the Chomsky Normal Form and
Greibach Normal Form
• The derivation tree in a grammar in CNF is a binary
tree
• In the GNF, a string of length n has a derivation of
exactly n steps
• Grammars in normal form can facilitate proofs
• CNF is used as starting point in the algorithm CYK
Presentation Outline
42
May 27, 2009
References
[1] Introduction to Automata Theory, Languages and Computation, John E.
Hopcroft, Rajeev Motwani and Jeffrey D. Ullman, 2nd edition, Addison
Wesley 2001 (ISBN: 0-201-44124-1)
[2] CS-311 HANDOUT, Greibach Normal Form (GNF), Humaira Kamal,
http://suraj.lums.edu.pk/~cs311w02/GNF-handout.pdf
[3] Conversion of a Chomsky Normal Form Grammar to Greibach Normal
Form, Arup Guha,
http://www.cs.ucf.edu/courses/cot4210/spring05/lectures/Lec14Greibac
h.ppt
Test Questions
43
May 27, 2009
1. Convert the following grammar to the Chomsky Normal Form.
2. Is the following grammar context-free?
3. Prove that the language L = { anbncn | n ≥ 1 } is not context-free.
4. Convert the following grammar to the Greibach Normal Form.
S → P
P → aPb | ε
S → aBSc | abc
Ba → aB
Bb → bb
S -> a | CD | CS
A -> a | b | SS
C -> a
D -> AS
Presentation Outline
44
May 27, 2009

Más contenido relacionado

Similar a Chomsky_Greibach-Hector-Chavez.ppt

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
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammarlavishka_anuj
 
Theory of Computation FSM Grammar Minimisation and Normal Forms
Theory of Computation FSM Grammar Minimisation and Normal FormsTheory of Computation FSM Grammar Minimisation and Normal Forms
Theory of Computation FSM Grammar Minimisation and Normal FormsRushabh2428
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarniveditJain
 
Theory of computation Lecture Slide(Chomsky Normal Form).pptx
Theory of computation Lecture Slide(Chomsky Normal Form).pptxTheory of computation Lecture Slide(Chomsky Normal Form).pptx
Theory of computation Lecture Slide(Chomsky Normal Form).pptxcustomersupport14
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarJasmine Peniel
 

Similar a Chomsky_Greibach-Hector-Chavez.ppt (9)

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
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
Toc CFG cfl properties
Toc CFG  cfl propertiesToc CFG  cfl properties
Toc CFG cfl properties
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
Theory of Computation FSM Grammar Minimisation and Normal Forms
Theory of Computation FSM Grammar Minimisation and Normal FormsTheory of Computation FSM Grammar Minimisation and Normal Forms
Theory of Computation FSM Grammar Minimisation and Normal Forms
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Theory of computation Lecture Slide(Chomsky Normal Form).pptx
Theory of computation Lecture Slide(Chomsky Normal Form).pptxTheory of computation Lecture Slide(Chomsky Normal Form).pptx
Theory of computation Lecture Slide(Chomsky Normal Form).pptx
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 

Último

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 

Último (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 

Chomsky_Greibach-Hector-Chavez.ppt

  • 1. Hector Miguel Chavez Western Michigan University
  • 2. Presentation Outline 2 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 3. Introduction 3 May 27, 2009 Grammar: G = (V, T, P, S) T = { a, b } Terminals V = A, B, C Variables S Start Symbol P = S → A Production
  • 4. Introduction 4 May 27, 2009 Grammar example S → aBSc S → abc Ba → aB Bb → bb L = { anbncn | n ≥ 1 } S aBSc aBabcc aaBbcc aabbcc    
  • 5. Introduction 5 May 27, 2009 Context free grammar The head of any production contains only one non-terminal symbol S → P P → aPb P → ε L = { anbn | n ≥ 0 }
  • 6. Presentation Outline 6 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final simplification • Greibach Normal Form • Algorithm (Example) • Summary
  • 7. Chomsky Normal Form 7 May 27, 2009 A → BC A → α A context free grammar is said to be in Chomsky Normal Form if all productions are in the following form: • A, B and C are non terminal symbols • α is a terminal symbol
  • 8. Presentation Outline 8 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 9. Preliminary Simplifications 9 May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications
  • 10. Preliminary Simplifications 10 May 27, 2009 Eliminate Useless Symbols We need to determine if the symbol is useful by identifying if a symbol is generating and is reachable • X is generating if X ω for some terminal string ω. • X is reachable if there is a derivation X αXβ for some α and β   * *
  • 11. Preliminary Simplifications 11 May 27, 2009 Example: Removing non-generating symbols S → AB | a A → b Initial CFL grammar S → AB | a A → b Identify generating symbols S → a A → b Remove non-generating
  • 12. Preliminary Simplifications 12 May 27, 2009 Example: Removing non-reachable symbols S → a Eliminate non-reachable S → a A → b Identify reachable symbols
  • 13. Preliminary Simplifications 13 May 27, 2009 The order is important. S → AB | a A → b Looking first for non-reachable symbols and then for non-generating symbols can still leave some useless symbols. S → a A → b
  • 14. Preliminary Simplifications 14 May 27, 2009 Finding generating symbols If there is a production A → α, and every symbol of α is already known to be generating. Then A is generating S → AB | a A → b We cannot use S → AB because B has not been established to be generating
  • 15. Preliminary Simplifications 15 May 27, 2009 Finding reachable symbols S is surely reachable. All symbols in the body of a production with S in the head are reachable. S → AB | a A → b In this example the symbols {S, A, B, a, b} are reachable.
  • 16. Preliminary Simplifications 16 May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications
  • 17. Preliminary Simplifications 17 May 27, 2009 Eliminate ε Productions • In a grammar ε productions are convenient but not essential • If L has a CFG, then L – {ε} has a CFG Nullable variable A ε  *
  • 18. Preliminary Simplifications 18 May 27, 2009 If A is a nullable variable • Whenever A appears on the body of a production A might or might not derive ε S → ASA | aB A → B | S B → b | ε Nullable: {A, B}
  • 19. Preliminary Simplifications 19 May 27, 2009 • Create two version of the production, one with the nullable variable and one without it • Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions
  • 20. Preliminary Simplifications 20 May 27, 2009 • Create two version of the production, one with the nullable variable and one without it • Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions
  • 21. Preliminary Simplifications 21 May 27, 2009 • Create two version of the production, one with the nullable variable and one without it • Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions
  • 22. Preliminary Simplifications 22 May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications
  • 23. Preliminary Simplifications 23 May 27, 2009 Eliminate unit productions A unit production is one of the form A → B where both A and B are variables A B  * A → B, B → ω, then A → ω Identify unit pairs
  • 24. Preliminary Simplifications 24 May 27, 2009 Example: I → a | b | Ia | Ib | I0 | I1 F → I | (E) T → F | T * F E → T | E + T Pairs Productions ( E, E ) E → E + T ( E, T ) E → T * F ( E, F ) E → (E) ( E, I ) E → a | b | Ia | Ib | I0 | I1 ( T, T ) T → T * F ( T, F ) T → (E) ( T, I ) T → a | b | Ia |Ib | I0 | I1 ( F, F ) F → (E) ( F, I ) F → a | b | Ia | Ib | I0 | I1 ( I, I ) I → a | b | Ia | Ib | I0 | I1 Basis: (A, A) is a unit pair of any variable A, if A A by 0 steps.  * T = {*, +, (, ), a, b, 0, 1}
  • 25. Preliminary Simplifications 25 May 27, 2009 Example: Pairs Productions … … ( T, T ) T → T * F ( T, F ) T → (E) ( T, I ) T → a | b | Ia |Ib | I0 | I1 … … I → a | b | Ia | Ib | I0 | I1 E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1 T → T * F | (E) | a | b | Ia | Ib | I0 | I1 F → (E) | a | b | Ia | Ib | I0 | I1
  • 26. Presentation Outline 26 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 27. Final Simplification 27 May 27, 2009 Chomsky Normal Form (CNF) 1. Arrange that all bodies of length 2 or more to consists only of variables. 2. Break bodies of length 3 or more into a cascade of productions, each with a body consisting of two variables. Starting with a CFL grammar with the preliminary simplifications performed
  • 28. Final Simplification 28 May 27, 2009 Step 1: For every terminal α that appears in a body of length 2 or more create a new variable that has only one production. E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1 T → T * F | (E) | a | b | Ia | Ib | I0 | I1 F → (E) | a | b | Ia | Ib | I0 | I1 I → a | b | Ia | Ib | I0 | I1 E → EPT | TMF | LER | a | b | lA | lB | lZ | lO T → TMF | LER | a | b | IA | IB | IZ | IO F → LER | a | b | IA | IB | IZ | IO I → a | b | IA | IB | IZ | IO A → a B → b Z → 0 O → 1 P → + M → * L → ( R → )
  • 29. Final Simplification 29 May 27, 2009 Step 2: Break bodies of length 3 or more adding more variables E → EPT | TMF | LER | a | b | lA | lB | lZ | lO T → TMF | LER | a | b | IA | IB | IZ | IO F → LER | a | b | IA | IB | IZ | IO I → a | b | IA | IB | IZ | IO A → a B → b Z → 0 O → 1 P → + M → * L → ( R → ) C1 → PT C2 → MF C3 → ER
  • 30. Presentation Outline 30 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 31. Greibach Normal Form 31 May 27, 2009 A → αX A context free grammar is said to be in Greibach Normal Form if all productions are in the following form: • A is a non terminal symbols • α is a terminal symbol • X is a sequence of non terminal symbols. It may be empty.
  • 32. Presentation Outline 32 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 33. Greibach Normal Form 33 May 27, 2009 Example: S → XA | BB B → b | SB X → b A → a CNF S = A1 X = A2 A = A3 B = A4 New Labels A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a Updated CNF
  • 34. Greibach Normal Form 34 May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a First Step Xk is a string of zero or more variables Ai → AjXk j > i A4 → A1A4
  • 35. Greibach Normal Form 35 May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → b | A1A4 A2 → b A3 → a A4 → A1A4 A4 → A2A3A4 | A4A4A4 | b A4 → bA3A4 | A4A4A4 | b First Step Ai → AjXk j > i
  • 36. Greibach Normal Form 36 May 27, 2009 Example: Second Step Eliminate Left Recursions A1 → A2A3 | A4A4 A4 → bA3A4 | A4A4A4 | b A2 → b A3 → a A4 → A4A4A4
  • 37. Greibach Normal Form 37 May 27, 2009 Example: Second Step Eliminate Left Recursions A1 → A2A3 | A4A4 A4 → bA3A4 | A4A4A4 | b A2 → b A3 → a A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4Z
  • 38. Greibach Normal Form 38 May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4 Z A2 → b A3 → a A → αX GNF
  • 39. Greibach Normal Form 39 May 27, 2009 Example: A1 → A2A3 | A4A4 A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4 Z A2 → b A3 → a Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4
  • 40. Greibach Normal Form 40 May 27, 2009 Example: A1 → bA3 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A4 → bA3A4 | b | bA3A4Z | bZ Z → bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 | bA3A4A4 | bA4 | bA3A4ZA4 | bZA4 A2 → b A3 → a Grammar in Greibach Normal Form
  • 41. Presentation Outline 41 May 27, 2009 Summary (Some properties) • Every CFG that doesn’t generate the empty string can be simplified to the Chomsky Normal Form and Greibach Normal Form • The derivation tree in a grammar in CNF is a binary tree • In the GNF, a string of length n has a derivation of exactly n steps • Grammars in normal form can facilitate proofs • CNF is used as starting point in the algorithm CYK
  • 42. Presentation Outline 42 May 27, 2009 References [1] Introduction to Automata Theory, Languages and Computation, John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman, 2nd edition, Addison Wesley 2001 (ISBN: 0-201-44124-1) [2] CS-311 HANDOUT, Greibach Normal Form (GNF), Humaira Kamal, http://suraj.lums.edu.pk/~cs311w02/GNF-handout.pdf [3] Conversion of a Chomsky Normal Form Grammar to Greibach Normal Form, Arup Guha, http://www.cs.ucf.edu/courses/cot4210/spring05/lectures/Lec14Greibac h.ppt
  • 43. Test Questions 43 May 27, 2009 1. Convert the following grammar to the Chomsky Normal Form. 2. Is the following grammar context-free? 3. Prove that the language L = { anbncn | n ≥ 1 } is not context-free. 4. Convert the following grammar to the Greibach Normal Form. S → P P → aPb | ε S → aBSc | abc Ba → aB Bb → bb S -> a | CD | CS A -> a | b | SS C -> a D -> AS