- 2073 Chaitra
CNF conversion (grammar with S→A|B)
Short answer
After removing unit productions, the CNF is: S → XaP | XaQ | a | b | XaXb | ε, A → XaP, B → XaQ | a | b | XaXb, with P → BXa, Q → AXb, Xa → a, Xb → b.
Convert the following CFG to CNF. [Heading and grammar are cut off in the scan. The worked solution starts from S → A | B | ε, A → aBa, B → aAb | a | b | ab (after removing null productions), so the original grammar had ε-productions for A and B.]
Grammar. The heading is cut off in the question. From the given null-free form we take the grammar
S → A | B | ε; A → aBa; B → aAb | a | b | ab
(this is the original S → A | B, A → aBa | ε, B → aAb | a | b after removing ε-productions). We convert it to CNF.
Step 1: Start symbol
S does not occur on a right side, so S → ε can stay.
Step 2: ε-productions
Already removed except S → ε (allowed for the start symbol).
Step 3: Remove unit productions S → A and S → B
S → aBa | aAb | a | b | ab | ε
A → aBa
B → aAb | a | b | ab
Step 4: Convert to CNF
Terminals: Xa → a, Xb → b. Long rules: aBa = Xa P with P → B Xa; aAb = Xa Q with Q → A Xb; ab = Xa Xb.
S → XaP | XaQ | a | b | XaXb | ε
A → XaP
B → XaQ | a | b | XaXb
P → BXa
Q → AXb
Xa → a
Xb → b
Every production has the form X → YZ or X → a (and S → ε for the start). This is the CNF.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Define CNF; convert S→MaN|bL|bM grammar · Theory of Computation, chapter 3
- CNF: S→aAb|Ba|A, A→SS|ε, B→ε · Theory of Computation, chapter 3
- CNF: S→AB, A→aAA|ε, B→bBB|ε · Theory of Computation, chapter 3
- CFG versus unrestricted grammar · Theory of Computation, chapter 4
- Unrestricted grammar; superset of CFG · Theory of Computation, chapter 4 · asked 2×
- CNF: S→XYZ|XY|aZ · Theory of Computation, chapter 3
- Language of grammar; grammar for strings not ending in ab · Discrete Structure, chapter 2
- 3-bus load flow with Q limits (cut off) · Power System Analysis II, chapter 2
- Lateral load elements; stepwise [cut off] · Concrete Technology and Masonry Structure, chapter 9
- Define scan conversion · Computer Graphics, chapter 2