Question
Identify the language generated by the following grammar, where is the start variable.
Official answer and solution
- Official answer
- C
- From
- Official GATE 2017 answer key
Solution
Find the language generated by each non-terminal and concatenate their languages.
Analyze the production rules of the grammar:
- Non-terminal has productions . This generates the regular language (i.e., with ).
- Non-terminal has productions . This generates equal numbers of 's and 's: .
- The start production is . Therefore, any string generated by is of the form:
Let . Since and , we have , which is equivalent to , with .
Thus, the generated language is , which matches option C.
Final answer
C
Common trap
Overlooking that allows , which yields strings like where .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 2
- Question
- 16 of 65, printed as CS Q.16
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.