GATE | GATE-CS-2003 | Question 56

Consider the grammar shown below

S → i E t S S' | a
S' → e S | ε
E → b 

In the predictive parse table. M, of this grammar, the entries M[S’, e] and M[S’, $] respectively are
(A) {S’ → e S} and {S’ → e}
(B) {S’ → e S} and {}
(C) {S’ → ε} and {S’ → ε}
(D) {S’ → e S, S’→ ε} and {S’ → ε}


Answer: (D)

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’, hence we only need to consider its productions to get the answer.

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

Similarly,

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

Therefore Answer is option D.

Visit the Following links to Learn how to find First and Follow sets.

http://geeksquiz.com/compiler-design-first-in-syntax-analysis/
http://geeksquiz.com/compiler-design-follow-set-in-syntax-analysis/

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.