The document discusses normal forms of Context Free Grammar (CFG), specifically Chomsky Normal Form (CNF) and Greibach Normal Form. It outlines the requirements for CNF, including restrictions on production rules and provides algorithms for converting grammars into CNF. Additionally, it includes examples demonstrating the conversion process and concludes with a learning outcome related to the simplification of CFG.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views
4-CNF
The document discusses normal forms of Context Free Grammar (CFG), specifically Chomsky Normal Form (CNF) and Greibach Normal Form. It outlines the requirements for CNF, including restrictions on production rules and provides algorithms for converting grammars into CNF. Additionally, it includes examples demonstrating the conversion process and concludes with a learning outcome related to the simplification of CFG.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17
NORMAL FORMS OF CONTEXT FREE GRAMMAR
Unit III 2/24/2025 1
LEARNING OBJECTIVE • To Understand the need of formal languages, and grammars (K3) – To Understand normal forms of CFG
Unit III 2/24/2025
NORMAL FORMS OF CONTEXT FREE GRAMMAR • Chomsky normal form • Greibach normal form
Unit III 2/24/2025
CHOMSKY NORMAL FORM • The Chomsky normal form places restrictions on the length and the composition of the right-hand side of a rule
• A context free grammar G is in CNF if every production is of
the form A→a or A→BC and S→ is in G if ∈L(G). When is in L(G) we assume that S does not appear on the R.H.S. of any other production. – where B, C NT
Unit III 2/24/2025
EXAMPLE Ex: S → AB S→ A→a B→b
Unit III 2/24/2025
CHOMSKY NORMAL FORM • Algorithm Step 1
• Make sure that the following are satisfied:
– No -productions (other than S → ) – No unit productions – No useless symbols
Unit III 2/24/2025
CHOMSKY NORMAL FORM • Algorithm Step 2 • Eliminate terminals from RHS of productions – For each production A → X1X2…Xm • where Xi NT
– If m 1, replace each terminal a RHS of A
• Add (if needed) Ca → a for each a , where each Ca is new non-terminal. • In production A, replace terminal a with corresponding Ca Unit III 2/24/2025 CHOMSKY NORMAL FORM • Algorithm Step 3
• Eliminate productions with long RHS:
– For each production: • A → B1B2…Bm, m 2, where Bi NT – replace with productions • A → B1D1 • D1 → B2D2 •… • Dm-2 → Bm-1Bm – where D1…Dm-2 are new non-terminals.
Unit III 2/24/2025
EXAMPLE • S→aAbB A→ Ca A | a S→ Ca A Cb B • A→aA | a B→ Cb B | b S→ Ca D1 • B→bB | b D1→AD2 S→aAbB D2→ Cb B (i) No є-productions S→ Ca A Cb B A→ Ca A | a No Null productions B→ Cb B | b S→ Ca D1 Ca → a No useless symbols D1→AD2 Cb → b
Ca → a D2→ Cb B Cb → b
Unit III 2/24/2025
EXAMPLE 1. Original grammar (no chain rules, useless symbols, or -productions): S→XaY|Yb X→YXaY|a Y→SS|aX|b
Unit III 2/24/2025
EXAMPLE 1. Original grammar (no chain rules, useless symbols, or -productions): S→XaY|Yb X→YXaY|a Y→SS|aX|b
2. Grammar after eliminating terminals from RHSs:
S → X Ca Y | Y Cb Ca → a X → Y X Ca Y | a Cb → b Y → S S | Ca X | b
Unit III 2/24/2025
EXAMPLE 1. Original grammar (no chain rules, useless symbols, or -productions): S→XaY|Yb X→YXaY|a Y→SS|aX|b
2. Grammar after eliminating terminals from RHSs:
S → X Ca Y | Y Cb Ca → a X → Y X Ca Y | a Cb → b Y → S S | Ca X | b
3. Grammar after eliminating long RHSs:
S → X D1 | Y Cb D1 → Ca Y Ca → a X → YD2| a D2 → X D3 Cb → b Y → S S | Ca X | b D3 → Ca Y
Unit III 2/24/2025
EXAMPLE Original grammar (no chain rules, useless symbols, or -productions): S → aXYZ | a X → aX | a Y → bcY | bc Z → cZ | c
1. Grammar after eliminating terminals from RHSs:
S → AXYZ | a A→a X → AX | a B →b Y → BCY | BC C →c Z → CZ | c
2. Grammar after eliminating long RHSs:
S → AF | a A→a F→ XG X → AX | a B →b G → YZ Y → BH | BC C →c H → CY Z → CZ | c
Unit III 2/24/2025
SUMMARY • Different normal forms of Context free grammar – Chomsky normal form – Greibach normal form
Unit III 2/24/2025
TEST YOUR KNOWLEDGE
Convert the following grammar into CNF
1.
2.
Unit III 2/24/2025
LEARNING OUTCOME On successful completion of this topic, the student will be able to: • Understand simplification of CFG (K3)
Unit III 2/24/2025
REFERENCE • Hopcroft J.E., Motwani R. and Ullman J.D, “Introduction to Automata Theory, Languages and Computations”, Second Edition, Pearson Education, 2008