SlideShare uma empresa Scribd logo
1 de 44
Presentation Outline
2
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Introduction
3
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
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
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 S αXβ
for some α and β


*
*
Preliminary Simplifications
11
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
Example: Removing non-reachable symbols
S → a Eliminate non-reachable
S → a
A → b
Identify reachable symbols
Preliminary Simplifications
13
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
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
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
Eliminate Useless Symbols
1
Eliminate ε productions
2
Eliminate unit productions
3
There are three preliminary simplifications
Preliminary Simplifications
17
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
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
• 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
• 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
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
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
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
CNF
Presentation Outline
27
May 27, 2009
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Chomsky Normal Form
28
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
Final Simplification
29
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
30
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
31
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
32
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Greibach Normal Form
33
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
34
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Greibach Normal Form
35
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
36
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
37
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
38
Example:
Second Step
Eliminate Left
Recursions
A1 → A2A3 | A4A4
A4 → bA3A4 | A4A4A4 | b
A2 → b
A3 → a
A4 → A4A4A4
A  A α | β
Can be written as
A  β A ‘
A ‘  α A’ | ɛ
Greibach Normal Form
39
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
40
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
A → αX
GNF
Greibach Normal Form
41
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
42
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
43
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
44
May 27, 2009

Mais conteúdo relacionado

Semelhante a NORMAL-FORMS.ppt

Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammarlavishka_anuj
 
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
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarJasmine Peniel
 
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
 
Normal Forms for CFG's.pdf
Normal Forms for CFG's.pdfNormal Forms for CFG's.pdf
Normal Forms for CFG's.pdfAmanda Reznor
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Iffat Anjum
 
Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019Bushra Al-Anesi
 

Semelhante a NORMAL-FORMS.ppt (12)

Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
Context free grammar
Context free grammarContext free grammar
Context free 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
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 
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
 
Normal Forms for CFG's.pdf
Normal Forms for CFG's.pdfNormal Forms for CFG's.pdf
Normal Forms for CFG's.pdf
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019
 
affTA09 - LampiranA
affTA09 - LampiranAaffTA09 - LampiranA
affTA09 - LampiranA
 

Mais de SadagopanS

partial-order.ppt
partial-order.pptpartial-order.ppt
partial-order.pptSadagopanS
 
Goal stack planning.ppt
Goal stack planning.pptGoal stack planning.ppt
Goal stack planning.pptSadagopanS
 
Normal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptxNormal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptxSadagopanS
 
Bermuda Triangle.pptx
Bermuda Triangle.pptxBermuda Triangle.pptx
Bermuda Triangle.pptxSadagopanS
 
Minimization of DFA.pptx
Minimization of DFA.pptxMinimization of DFA.pptx
Minimization of DFA.pptxSadagopanS
 
AWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdfAWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdfSadagopanS
 

Mais de SadagopanS (6)

partial-order.ppt
partial-order.pptpartial-order.ppt
partial-order.ppt
 
Goal stack planning.ppt
Goal stack planning.pptGoal stack planning.ppt
Goal stack planning.ppt
 
Normal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptxNormal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptx
 
Bermuda Triangle.pptx
Bermuda Triangle.pptxBermuda Triangle.pptx
Bermuda Triangle.pptx
 
Minimization of DFA.pptx
Minimization of DFA.pptxMinimization of DFA.pptx
Minimization of DFA.pptx
 
AWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdfAWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdf
 

Último

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Último (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

NORMAL-FORMS.ppt

  • 1.
  • 2. Presentation Outline 2 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 3. Introduction 3 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 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 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 S αXβ for some α and β   * *
  • 11. Preliminary Simplifications 11 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 Example: Removing non-reachable symbols S → a Eliminate non-reachable S → a A → b Identify reachable symbols
  • 13. Preliminary Simplifications 13 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 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 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 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications
  • 17. Preliminary Simplifications 17 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 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 • 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 • 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 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 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 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
  • 27. Presentation Outline 27 May 27, 2009 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 28. Chomsky Normal Form 28 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
  • 29. Final Simplification 29 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
  • 30. Final Simplification 30 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 → )
  • 31. Final Simplification 31 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
  • 32. Presentation Outline 32 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 33. Greibach Normal Form 33 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.
  • 34. Presentation Outline 34 • Introduction • Chomsky normal form • Preliminary simplifications • Final steps • Greibach Normal Form • Algorithm (Example) • Summary
  • 35. Greibach Normal Form 35 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
  • 36. Greibach Normal Form 36 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
  • 37. Greibach Normal Form 37 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
  • 38. Greibach Normal Form 38 Example: Second Step Eliminate Left Recursions A1 → A2A3 | A4A4 A4 → bA3A4 | A4A4A4 | b A2 → b A3 → a A4 → A4A4A4 A  A α | β Can be written as A  β A ‘ A ‘  α A’ | ɛ
  • 39. Greibach Normal Form 39 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
  • 40. Greibach Normal Form 40 Example: A1 → A2A3 | A4A4 A4 → bA3A4 | b | bA3A4Z | bZ Z → A4A4 | A4A4 Z A2 → b A3 → a A → αX GNF
  • 41. Greibach Normal Form 41 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
  • 42. Greibach Normal Form 42 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
  • 43. Presentation Outline 43 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