- 2073 Shrawan
Define CNF; convert S→MaN|bL|bM grammar
Short answer
A CFG is in CNF if all productions are A → BC or A → a, with S → ε allowed if ε is in the language. The converted grammar is: S → XbL | b | XbM, L → XaXb | a | XcM, M → a | XcM, Xa → a, Xb → b, Xc → c.
What is Chomsky Normal Form (CNF)? Convert the following grammar to CNF. G = (S, L, M, N, a, b, c), Σ = {a, b, c}, R = {S → MaN | bL | bM; L → ab | cN | M | ε; M → a | cM; N → abN}
Chomsky Normal Form
A CFG is in CNF if every production has one of the forms
- A → BC (two variables), or
- A → a (one terminal),
and the start symbol may have S → ε if ε ∈ L (then S must not appear on any right side). Every CFG can be converted to CNF. CNF is used in the CYK parsing algorithm.
Conversion
Grammar: S → MaN | bL | bM; L → ab | cN | M | ε; M → a | cM; N → abN.
Step 1: Useless symbols. N → abN is the only rule for N and always contains N, so N generates no terminal string. Remove N and rules containing it:
S → bL | bM
L → ab | M | ε (cN removed)
M → a | cM
Step 2: Remove ε. Only L is nullable. S is not nullable, so no ε remains.
S → bL | b | bM
L → ab | M
M → a | cM
Step 3: Remove unit L → M.
S → bL | b | bM
L → ab | a | cM
M → a | cM
Step 4: Convert to CNF. Add Xa → a, Xb → b, Xc → c, replace terminals in long rules:
S → XbL | b | XbM
L → XaXb | a | XcM
M → a | XcM
Xa → a
Xb → b
Xc → c
This is in CNF. (Examples of strings generated: b, ba, bab, bca, bcca.)
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- CNF conversion (grammar with S→A|B) · Theory of Computation, chapter 3
- CNF: S→AB, A→aAA|ε, B→bBB|ε · Theory of Computation, chapter 3
- CNF: S→XYZ|XY|aZ · Theory of Computation, chapter 3
- CNF: S→ASB|ε, A→aAS|a, B→... · Theory of Computation, chapter 3
- CNF: S→aAb|Ba|A, A→SS|ε, B→ε · Theory of Computation, chapter 3
- Conversion to conjunctive normal form · Artificial Intelligence, chapter 4 · asked 3×
- Language of grammar; grammar for strings not ending in ab · Discrete Structure, chapter 2
- NFA and DFA from grammar with A, B rules · Discrete Structure, chapter 2 · asked 2×
- Dynamic equation of GVF, wide rectangular form · Hydraulics, chapter 8 · asked 2×