Chomsky & Greibach �Normal Forms

rajendranjrf 7,077 views 28 slides Feb 02, 2016
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Chomsky & Greibach �Normal Forms in toc


Slide Content

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, CVariables#
SStart Symbol•&#-
P = S → AProduction

Introduction
4
Grammar example
S → aBSc
S → abc
Ba → aB
Bb → bb/&* •





0 12+
L = { a
n
b
n
c
n
| 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 → ε/&* •



0 16+
L = { a
n
b
n
| n ≥ 0 }

Presentation Outline
6May 27, 2009
•Introduction
•Chomsky normal form
•Preliminary simplifications
•Final simplification
•Greibach Normal Form
•Algorithm (Example)
• Summary

Chomsky Normal Form
7
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
•Introduction
•Chomsky normal form
•Preliminary simplifications
•Final steps
•Greibach Normal Form
•Algorithm (Example)
• Summary

Preliminary Simplifications
9 %#
Eliminate Useless Symbols1 '
Eliminate ε productions 2
Eliminate unit productions3
There are three preliminary simplifications

Preliminary Simplifications
10
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
11May 27, 2009
Example: Removing non-generating symbols#89:
8
S → AB | a
A → b
Initial CFL grammar# 8 9 :
8
S → AB | a
A → b
Identify generating symbols # 8
8
S → a
A → b
Remove non-generating

Preliminary Simplifications
12
Example: Removing non-reachable symbols # 8
S → a Eliminate non-reachable # 8
8
S → a
A → b
Identify reachable symbols

Preliminary Simplifications
13
The order is important. #89:
8
S → AB | a
A → b
Looking first for non-reachable symbols and then
for non-generating symbols can still leave some
useless symbols. #8
8
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 #89:
8
S → AB | a
A → b
We cannot use S → AB
because B has not been
established to be generating

Preliminary Simplifications
15
Eliminate Useless Symbols1
Eliminate ε productions 2
Eliminate unit productions3
There are three preliminary simplifications

Preliminary Simplifications
16
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
17
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
18
•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
19
•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
Eliminate Useless Symbols1
Eliminate ε productions 2
Eliminate unit productions3
There are three preliminary simplifications

Preliminary Simplifications
22
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

Eliminate unit productions
•Consider the CFG
S->0A | 1B|C
A-> 0S|00
B->1|A
C->01
remove unit productions.
S-> C
B-> A unit productions
S->0A|1B|01
A->0S|00
B->1|0S|00
May 27, 2009 23

Brain Activity
Can you see both the frog and the horse on this visual illusion?

Brain Activity
Is that a polar bear or a seal on the cool optical illusion picture below?

Brain Activity
Victory or defeat? Both

Brain Activity

Brain Activity
Tags