GATE / CS ARCHIVE

GATE CSE 2015 SET 3 / QUESTION 65

GATE CSE 2015 Set 3 Q65

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2015 Set 3 paper

GATE 2015 Set 3, Q65 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 65, GATE 2015: Grammar G has productions S→F|H, F→p|c, H→d|c. S,F,H are nonterminals; p,d,c are terminals. Assess S1: LL(1) can parse all strings generated using grammar G; S2: LR(1) can parse all strings generated using grammar G. Options: (A) S1 only; (B) S2 only; (C) both; (D) neither. The question concerns this grammar, not whether its language has a different LL(1) or LR(1) grammar.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Step through it (3 parts)

1. The string c has two parse trees: S→F→c and S→H→c.

2. Thus the displayed grammar is ambiguous and is neither LL(1) nor LR(1). Concretely FIRST(F) and FIRST(H) both contain c, causing an LL conflict; after shifting c, completed F→c and H→c items both reduce on end-of-input, causing an LR reduce/reduce conflict. Therefore D for parsing with this grammar. Its finite language can of course be represented by a different unambiguous grammar S→p|d|c.

Original paper, page 79 · Answer key