GATE / CS ARCHIVE

GATE CSE 2021 SET 1 / QUESTION 31

GATE CSE 2021 Set 1 Q31

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2021 Set 1 paper

GATE 2021 Set 1, Q31 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 31, GATE 2021: For terminals {a,b,c,d,f}, grammar S→daT|Rf, T→aS|baT|ε, R→caTR|ε has a partially filled LL(1) table. Numbered cells are 1=(S,c), 2=(S,f), 3=(T,c), 4=(T,$). Known cells are (S,d)=S→daT; (T,a)=T→aS; (T,b)=T→baT; (T,f)=T→ε; (R,c)=R→caTR; (R,f)=R→ε; other unnumbered cells blank. Choose entries (1,2,3,4): A (S→Rf,S→Rf,T→ε,T→ε); B (blank,S→Rf,T→ε,T→ε); C (S→Rf,blank,blank,T→ε); D (blank,S→Rf,blank,blank).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (2 parts)

FIRST(R)={c,ε}, so FIRST(Rf)={c, f}; both numbered S-row cells contain S→Rf. From R→caTR, c belongs to FOLLOW(T), and nullable R carries FOLLOW(R)={f} into FOLLOW(T). From S→daT and T→aS, the start marker $ also reaches FOLLOW(T). Thus FOLLOW(T)={c, f,$}, and the numbered T-row cells at c and $ contain T→ε. Therefore A.

The FIRST rule puts A→α in every terminal column of FIRST(α) except ε. When α is nullable, put it in all FOLLOW(A) columns. For S→Rf, R can start with c or disappear, exposing f. For T→ε, the c column comes from T followed by R in R→caTR; the f column comes from the following nullable R and S→Rf; the end marker flows from start S through S→daT. No guessed table entry is needed once these sets are computed.

Original paper, page 27 · Answer key