Skip to content
GATEiit

GATE CSE 2017 Session 2 Q42: Removing left recursion from an expression grammar

Syllabus topic: Lexical analysis, parsing and syntax-directed translation

Question

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?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: C (official GATE 2017 final answer key)

Concept used: Left recursion A→Aα∣β is removed by rewriting it as A→βA′, A′→αA′∣ϵ, applied to every left-recursive non-terminal.

Concept notes

Loading notes…

First step: Check which options still contain a production whose right side starts with its own left-hand non-terminal, then apply the standard rewrite to both E and T.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Lexical analysis, parsing and syntax-directed translation

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key