GateAI
Parsing

GATE CSE 2017 Set 2 · Q32

MCQ2 marksEasy

Time

Consider the following expression grammar GG: E→E−T∣TT→T+F∣FF→(E)∣id \begin{aligned} \text{E} &\rightarrow \text{E} - \text{T} \mid \text{T} \\ \text{T} &\rightarrow \text{T} + \text{F} \mid \text{F} \\ \text{F} &\rightarrow (\text{E}) \mid \text{id} \end{aligned} Which of the following grammars is not left recursive, but is equivalent to GG?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) E &→ TX X &→ -TX T &→ FY Y &→ +FY F &→ (E) id

Parsing

To eliminate immediate left recursion of the standard form:

A→Aα∣βA \rightarrow A\alpha \mid \beta

where β\beta does not begin with AA, we replace the production rules with: A→βA′A′→αA′∣ϵ\begin{aligned} A &\rightarrow \beta A^{\prime} A^{\prime} &\rightarrow \alpha A^{\prime} \mid \epsilon \end{aligned}

Applying this transformation to the non-terminals in grammar GG:

  1. For E→E−T∣T\text{E} \rightarrow \text{E} - \text{T} \mid \text{T}: Here, α=−T\alpha = - \text{T} and β=T\beta = \text{T}. E→TXX→−TX∣ϵ\begin{aligned} \text{E} &\rightarrow \text{T}\text{X} \\ \text{X} &\rightarrow -\text{T}\text{X} \mid \epsilon \end{aligned}

  2. For T→T+F∣F\text{T} \rightarrow \text{T} + \text{F} \mid \text{F}: Here, α=+F\alpha = + \text{F} and β=F\beta = \text{F}. T→FYY→+FY∣ϵ\begin{aligned} \text{T} &\rightarrow \text{F}\text{Y} \\ \text{Y} &\rightarrow +\text{F}\text{Y} \mid \epsilon \end{aligned}

  3. The non-terminal F→(E)∣id\text{F} \rightarrow (\text{E}) \mid \text{id} is not left-recursive and remains unchanged.

Combining these yields the grammar in option (C): E→TXX→−TX∣ϵT→FYY→+FY∣ϵF→(E)∣id\begin{aligned} \text{E} &\rightarrow \text{TX} \\ \text{X} &\rightarrow -\text{TX} \mid \epsilon \\ \text{T} &\rightarrow \text{FY} \\ \text{Y} &\rightarrow +\text{FY} \mid \epsilon \\ \text{F} &\rightarrow (\text{E}) \mid \text{id} \end{aligned}

Distractor analysis:

  • (A) retains the original left-recursive rules for E\text{E} and T\text{T}.

  • (B) eliminates left recursion only from E\text{E}, but T→T+F\text{T} \rightarrow \text{T} + \text{F} remains left-recursive.

  • (D) changes the language of the grammar entirely.

Thus, the correct option is (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Parsing previous year question is Q32 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Parsing in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Parsing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Parsing in GATE CSE

Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 11 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2017 Set 2.

How GATE tests Parsing

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q32 · MCQ

Consider the following expression grammar G: E &→ E - T T T &→ T + F F F &→ (E) id Which of the following grammars is not left recursive, but is equivalent to G?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.