Question
Consider the grammar given below:
Let and be indexed as follows:
| Symbol | ||||
|---|---|---|---|---|
| Index | 3 | 2 | 1 | 0 |
Compute the set of the non-terminal and write the index values for the symbols in the set in descending order. (For example, if the set is , then the answer should be 3210)
Answer: ________.
Official answer and solution
- Official answer
- 31
- From
- Official GATE 2019 answer key
Solution
Calculate FIRST and FOLLOW sets for the grammar symbols according to standard compiler parsing rules.
The given grammar is:
Step 1: Compute FIRST sets:
- : Since , includes . Because , also includes . Thus .
Step 2: Compute FOLLOW sets:
- For start symbol : .
- For non-terminal : In , is followed by terminal . Hence .
- For non-terminal : In , is followed by .
- contains .
- Since , also contains everything in .
Therefore:
The given symbol indices are:
For the symbols in , the indices are and .
Arranging them in descending order gives 31.
31
Forgetting that D can derive epsilon, which causes symbol 'a' to be missed from FOLLOW(B).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2019 Computer Science and Information Technology (CS)
- Question
- 29 of 65, printed as CS Q.19
- 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.