GATE / CS ARCHIVE

GATE CSE 2024 SET 1 / QUESTION 26

Classify parsers by construction direction

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

GATE 2024 Set 1, Q26 1 mark · MSQ
Report issue

Parsing & Syntax Analysis

Question 26, GATE 2024: Which are bottom-up parsers? A Shift-reduce; B Predictive; C LL(1); D LR.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, D

Approach: Ask whether parsing starts with the input's terminal symbols and reduces upward, or starts with the grammar's start symbol and expands downward.
1. A shift-reduce parser shifts input symbols onto a stack, then reduces recognized handles to nonterminals. Repeated reductions construct the parse from leaves toward the root. Hence A is bottom-up.
2. An LR parser is a systematic shift-reduce parser. It reads input from left to right and reconstructs a rightmost derivation in reverse, so D is bottom-up as well.
3. Predictive parsing chooses productions while expanding from the start symbol toward the input. It is top-down, making B false.
4. LL(1) is a predictive, top-down method using one lookahead symbol. Its second L refers to a leftmost derivation, not to upward reduction. C is false.
Answer: A and D. LR and LL both scan left to right, so scan direction alone does not distinguish bottom-up from top-down.

Original paper, page 17 · Answer key