Consider the following grammar: S → F R R → * S | ε F → id In the predictive…

2006

Consider the following grammar:

S → F R

R → * S | ε

F → id

In the predictive parser table M of this grammar, the entries M[S, id] and M[R, $] respectively are:

  1. A.

    {S → FR} and {R → ε }

  2. B.

    {S → FR} and { }

  3. C.

    {S → FR} and {R → *S}

  4. D.

    {F → id} and {R → ε}

Attempted by 77 students.

Show answer & explanation

Correct answer: A

Correct answer: {S → F R} and {R → ε}.

FIRST sets

  • FIRST(F) = { id } because F → id.

  • FIRST(S) = FIRST(F R) = { id }.

  • FIRST(R) = { *, ε } because R → * S | ε.

FOLLOW sets

  • Since S is the start symbol, $ is in FOLLOW(S).

  • From S → F R, FOLLOW(R) includes FOLLOW(S), so $ is in FOLLOW(R).

Parser-table entries

  • M[S, id]: Since id is in FIRST(S), place S → F R.

  • M[R, $]: Since R can derive ε and $ is in FOLLOW(R), place R → ε.

Therefore, M[S, id] = {S → F R} and M[R, $] = {R → ε}.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir