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 → aBScS → abcBa → aBBb → 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 → PP → aPbP → ε
L = { anbn | 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 → BCA → α
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
S → AB | aA → b Initial CFL grammar
S → AB | aA → 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 | aA → 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 | aA → 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 | aBA → B | SB → 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 | aBA → B | SB → b | ε
S → ASA | aB | AS | SA | S | aA → B | SB → 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 | aBA → B | SB → b | ε
S → ASA | aB | AS | SA | S | aA → B | SB → 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 | aBA → B | SB → b | ε
S → ASA | aB | AS | SA | S | aA → B | SB → 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-> CB-> A unit productions
S->0A|1B|01A->0S|00B->1|0S|00
May 27, 2009 23
Brain Activity
Can you see both the frog and the horse on this visual illusion?
Brain ActivityIs that a polar bear or a seal on the cool optical illusion picture below?
Brain Activity
Victory or defeat? Both
Brain Activity
Brain Activity