Skip to content
Related Articles

Related Articles

GATE | Quiz for Sudo GATE 2021 | Question 49

View Discussion
Improve Article
Save Article
  • Last Updated : 18 Dec, 2020
View Discussion
Improve Article
Save Article

Consider the following grammars G1 and G2 respectively.

Grammar – G1:

A1 → A2A3
A2 → A3A1 | b
A3 → A1A1 | a

Grammar – G2:

S → AA | 0
A → SS | 1

Consider the following statements regarding above grammars:

(I): This grammar is not left recursive and equivalent to grammar – G1:

A1 → A2A3
A2 →  A3A1 | b
A3 → a | bA3A1 | aK | bA3A1K 
k → A1A3A1 | A1A3A1K

(II): This grammar is not left recursive and equivalent to grammar – G2:

S → A A | 0
A → 0S | 1 | 0SK | 1K
K → AS | ASK

Note – This question is multiple select questions (MSQ).
(A) Statement (I) is correct
(B) Statement (II) is correct
(C) Statement (I) is not correct
(D) Statement (II) is not correct


Answer: (A) (B)

Explanation: Grammar – G1:

A1 → A2A3
A2 → A3A1 | b
A3 → A1A1 | a

Replace A3 → A1 A1 by A3 → A2A3A1 and then replace this by A3 → A3A1A3A1 and A3 → bA3A1.

Eliminating direct left recursion in the above, gives:

A3 → a | bA3A1 | aK | b A3A1K 
k → A1 A3 A1 | A1 A3 A1K

The resulting grammar is then:

A1 → A2A3
A2 →  A3A1 | b
A3 → a | bA3A1 | aK | bA3A1K 
k → A1A3A1 | A1A3A1K

Grammar – G2:

S → AA | 0
A → SS | 1

Considering the ordering S, A, we get:

S → AA | 0
A → AAS | 0S | 1

and removing immediate left recursion, we get

S → A A | 0
A → 0S | 1 | 0SK | 1K
K → AS | ASK

So, both statements (I) and (II) are correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!