Consider the following two context-free grammars over the terminal alphabet . In each grammar is the only non-terminal and the start symbol, and denotes the empty string.
Which one of the following statements is CORRECT?
Show solution
Solution MCQ · 2 marks · −⅔ if wrong
Answer: (A) and is regular
Method. Find what every sentential form looks like, then read off the language.
. Every rule puts its 's to the left of and its 's to the right, so a sentential form is . The rule adds one and two 's; adds one only. If is used times and is used times, the final string is . So , and every pair is reachable (apply times, then times, then ). Hence . Quick check: but .
. Again all 's stay left of and all 's right of it, so every string is . Conversely any is derived by applying times, times, then . So , which is regular. The rule is redundant.
The trap. A rule of the form suggests , but a grammar's language is not decided by one rule: here and let the two counts vary independently, so the "matching" is lost. In the opposite care is needed: the extra rule adds only 's, so the -count can exceed the number of blocks but never fall below it.
What was tested. Deriving a grammar's language from the contribution of each production (a symbol-count argument in both directions), and not judging regularity from the shape of a single production.
Copied. Paste it into the new chat.Too long to send. Copy the question and solution by hand.