# GATE | GATE-CS-2006 | Question 58

• Last Updated : 15 Sep, 2021

Consider the following grammar:

```S → FR
R → S | ε
F → id```

In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, \$] respectively.
(A) {S → FR} and {R → ε }
(B) {S → FR} and { }
(C) {S → FR} and {R → *S}
(D) {F → id} and {R → ε}

Explanation: Here representing the parsing table as M[ X , Y ], where X represents rows( Non terminals) and Y represents columns(terminals).

Here are the rules to fill the parsing table.

For each distinct production rule A->α, of the grammar, we need to apply the given rules:

Rule 1: if A –> α is a production, for each terminal ‘a’ in FIRST(α), add A–>α to M[ A , a ]

Rule 2 : if ‘ ε ‘ is in FIRST(α), add A –> α to M [ A , b ] for each ‘b’ in FOLLOW(A).

As Entries have been asked corresponding to Non-Terminal S and R, hence we only need to consider their productions to get the answer.

For S → FR, according to rule 1, this production rule should be placed at the entry M[ S, FIRST(FR) ], and from the given grammar, FIRST(FR) ={id}, hence S->FR is placed in the parsing table at entry M[S , id].

Similarly,

For R → S, this production rule should be placed at entry M[ R, FIRST(S) ], and as FIRST(S) = FIRST(F) = {id} hence, R->S is placed at entry M[R,id]

and

For R->ε, as FIRST(ε) = {ε}, hence rule 2 should be applied, therefore, this production rule should be placed in the parsing table at entry M[R,FOLLOW(R)], and FOLLOW(R) = FOLLOW(S) = {\$}, hence R->ε is placed at entry M[ R, \$ ].