GFG App
Open App
Browser
Continue

# GATE | GATE-CS-2006 | Question 58

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, \$ ].