Question
Consider the following context-free grammar where the set of terminals is .
The following is a partially-filled LL(1) parsing table.
| a | b | c | d | f | $ | |
|---|---|---|---|---|---|---|
| S | (1) | S -> daT | (2) | |||
| T | T -> aS | T -> baT | (3) | T -> eps | (4) | |
| R | R -> caTR | R -> eps |
Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?
Official answer and solution
- Official answer
- A
- From
- Official GATE 2021 answer key
Solution
Compute the FIRST and FOLLOW sets for the non-terminals S, T, and R, and identify the entries for the numbered cells in the LL(1) parsing table.
The grammar productions are:
Compute FIRST sets:
For non-terminal , production has . Thus, is entered in cell (cell 1) and in cell (cell 2).
Compute :
- From , . Since is start symbol, , so .
- From , , and .
- From , , which implies .
Thus . Production is placed under all terminals in , so it appears in cell (cell 3), in cell (already filled in the given table) and in cell (cell 4).
Therefore, the entries are:
(1) , (2) , (3) , (4) , matching option A.
A
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology (CS, Set-1)
- Question
- 41 of 65, printed as CS Q.31
- 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.