GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 1.18

Unambiguity versus derivation order

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2001 paper

GATE 2001, Q1.18 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 1.18, GATE 2001: Which claim is false? An unambiguous grammar has identical leftmost and rightmost derivations; LL(1) parsing is top-down; LALR is more powerful than SLR; an ambiguous grammar cannot be LR(k) for any k.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: Unambiguity means each generated string has one parse tree, hence one leftmost derivation and one rightmost derivation. It does not mean those two sequences of intermediate sentential forms are identical.

Step 2: For S→AB,A→a,B→b, the leftmost derivation is S⇒AB⇒aB⇒ab, while the rightmost one is S⇒AB⇒Ab⇒ab. The grammar is unambiguous, yet the derivations differ.

Thus A is false. LL(1) is top-down, LALR recognizes a strictly larger grammar class than SLR, and every LR(k) grammar is unambiguous.

Original paper, page 3