GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 40

GATE CSE 2025 Set 2 Q40

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q40 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 40, GATE 2025: For grammar S→Aa | bAc | dc | bda and A→d, choose the parsing classification.
Options: A. neither LALR(1) nor SLR(1); B. CLR(1) but not LALR(1); C. LALR(1) but not SLR(1); D. both LALR(1) and SLR(1).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step through it (3 parts)

First compute FOLLOW(A). In S→Aa, a follows A; in S→bAc, c follows A. Thus FOLLOW(A)={a,c}.

The LR(0) state reached by reading d directly from the start contains A→d· and S→d·c. SLR puts the reduction A→d on every symbol in FOLLOW(A), including c, but S→d·c requires shifting c. This is a shift/reduce conflict. Likewise, after reading bd the state contains A→d· and S→bd·a, producing a conflict on a. So the grammar is not SLR(1).

Canonical LR(1) retains the particular context. After the initial d, the completed item is [A→d·,a]; it reduces only on a, while S→d·c shifts c. After bd, the completed item is [A→d·,c]; it reduces only on c, while S→bd·a shifts a. These actions do not conflict.

LALR merges states only when their complete LR(0) cores are identical. The two potentially troublesome states have different S items, S→d·c versus S→bd·a, so they are not merged merely because both contain A→d·. All other reductions arise in completed S productions or similarly nonconflicting states. Hence the precise lookahead separation survives LALR construction. Answer: C.

Original paper, page 30 · Answer key