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?

This question was previously asked in
GATE CS 2017 Official Paper: Shift 2
View all GATE CS Papers >
  1. E → E – T | T

    T → T + F | F

    F → (E) | id

  2. E → TE’

    E’ → -TE’ | ϵ

    T → T + F | F

    F → (E) | id

  3. E → TX

    X → -TX | ϵ

    T → FY

    Y → +FY | ϵ

    F → (E) | id

  4. E → TX | (TX)

    X → -TX | +TX | ϵ

    T → id

Answer (Detailed Solution Below)

Option 3 :

E → TX

X → -TX | ϵ

T → FY

Y → +FY | ϵ

F → (E) | id

Free
GATE CS Full Mock Test
5.4 K Users
65 Questions 100 Marks 180 Mins

Detailed Solution

Download Solution PDF

Concept:

A production of grammar is said to have left recursion if its leftmost variable of its RHS is same as variable of LHS.

Consider grammar of type A → Aa | b

After removing left recursion, it becomes A → bA’, A’ → aA’| ϵ

Explanation:

Given grammar is:

E → E – T | T

T → T + F | F

F → (E) | id

After removing left recursion, it becomes:

E → TE’

E’ → -T E’ | ϵ

T → FT’

T’ → + FT’ | ϵ

F → (E) | id

Therefore option 3 is correct.

Latest GATE CS Updates

Last updated on Jan 8, 2025

-> GATE CS 2025 Admit Card has been released on 7th January 2025.

-> The exam will be conducted on 1st February 2025 in 2 shifts.

-> Candidates applying for the GATE CE must satisfy the GATE Eligibility Criteria.

-> The candidates should have BTech (Computer Science). Candidates preparing for the exam can refer to the GATE CS Important Questions to improve their preparation.

-> Candidates must check their performance with the help of the GATE CS mock tests and GATE CS previous year papers for the GATE 2025 Exam.

Get Free Access Now
Hot Links: teen patti master official teen patti circle teen patti gold apk