Professional Documents
Culture Documents
Chomsky - Greibach Hector Chavez
Chomsky - Greibach Hector Chavez
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Grammar: G = (V, T, P, S)
Terminals TT == {{ a,
a, bb }}
Variables VV == A,
A, B,
B, CC
Start Symbol SS
Production PP == SS →
→ AA
Grammar example
S → aBSc
S → abc
LL == {{ aannbbnnccnn || nn ≥≥ 11 }}
Ba → aB
Bb → bb
S→P
P → aPb LL == {{ aannbbnn || nn ≥≥ 00 }}
P→ε
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final simplification
• Greibach Normal Form
• Algorithm (Example)
• Summary
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
1 Eliminate
Eliminate Useless
Useless Symbols
Symbols
2 Eliminate
Eliminate εε productions
productions
3 Eliminate
Eliminate unit
unit productions
productions
• X is generating if X
* ω for some terminal string ω.
• X is reachable if there is a derivation X
* αXβ
for some α and β
SS →
→ AB
AB || aa
AA → Initial CFL grammar
→ bb
SS →
→ AB
AB || aa Identify generating symbols
AA →
→ bb
SS →
→ aa Remove non-generating
AA →
→ bb
SS →
→ aa Identify reachable symbols
AA →
→ bb
SS →
→ aa Eliminate non-reachable
SS →
→ AB
AB || aa SS →
→ aa
AA →
→ bb AA →
→ bb
We cannot use S → AB
SS →
→ AB
AB || aa because B has not been
AA →
→ bb established to be generating
SS →
→ AB
AB || aa In this example the symbols
AA →
→ bb {S, A, B, a, b} are reachable.
1 Eliminate
Eliminate Useless
Useless Symbols
Symbols
2 Eliminate
Eliminate εε productions
productions
3 Eliminate
Eliminate unit
unit productions
productions
Eliminate ε Productions
AA
* εε
Nullable variable
If A is a nullable variable
S → ASA | aB
A→B|S Nullable: {A, B}
B→b|ε
Eliminate ε Productions
S → ASA | aB S → ASA | aB | AS | SA | S | a
A→B|S A→B|S
B→b|ε B→b
Eliminate ε Productions
S → ASA | aB S → ASA | aB | AS | SA | S | a
A→B|S A→B|S
B→b|ε B→b
Eliminate ε Productions
S → ASA | aB S → ASA | aB | AS | SA | S | a
A→B|S A→B|S
B→b|ε B→b
1 Eliminate
Eliminate Useless
Useless Symbols
Symbols
2 Eliminate
Eliminate εε productions
productions
3 Eliminate
Eliminate unit
unit productions
productions
AA
* BB
A → B, B → ω, then A → ω
Example:
T = {*, +, (, ), a, b, 0, 1} Pairs Productions
( E, E ) E→E+T
I → a | b | Ia | Ib | I0 | I1 ( E, T ) E→T*F
F → I | (E) ( E, F ) E → (E)
T→F|T*F ( E, I ) E → a | b | Ia | Ib | I0 | I1
E→T|E+T ( T, T ) T→T*F
( T, F ) T → (E)
( T, I ) T → a | b | Ia |Ib | I0 | I1
Basis: (A, A) is a unit pair ( F, F ) F → (E)
of any variable A, if ( F, I ) F → a | b | Ia | Ib | I0 | I1
A * A by 0 steps. ( I, I ) I → a | b | Ia | Ib | I0 | I1
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
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
A → αX
• Introduction
• Chomsky normal form
• Preliminary simplifications
• Final steps
• Greibach Normal Form
• Algorithm (Example)
• Summary
Example:
S → XA | BB S = A1 A1 → A2A3 | A4A4
B → b | SB X = A2 A4 → b | A1A4
X→b A = A3 A2 → b
A→a
B = A4 A3 → a
CNF
CNF New
New Labels
Labels Updated
Updated CNF
CNF
Example:
A4 → A1A4
Example:
Example:
A4 → A4A4A4
Example:
Second Step
Eliminate
Eliminate Left
Left
Recursions
Recursions
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ AA →
→ αX
αX
Z → A4A4 | A4A4 Z
A2 → b GNF
A3 → a
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
Example:
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)