Similar questions 2 more →
Parsing & Syntax Analysis


Answer & solution
Answer: S→aR | bR; R→aR | bR | ε. (no official key was published)
In the standard transformation S→Sα1 | Sα2 | β1 | β2, choose α1=a, α2=b and β1=a, β2=b. Introduce a new nonterminal R and write S→aR | bR, R→aR | bR | ε. The initial S production contributes one mandatory letter; R generates any remaining sequence of a’s and b’s, including the empty suffix. Thus both grammars generate exactly all nonempty strings over {a,b}. No production now begins with its own left-hand nonterminal, directly or indirectly. The empty string remains excluded from S, as it was in the original grammar.