Open In App

GATE | Gate IT 2007 | Question 49

Consider the following grammars. Names representing terminals have been specified in capital letters.



Which one of the following statements is true?
(A) G1 is context-free but not regular and G2 is regular
(B) G2 is context-free but not regular and G1 is regular
(C) Both G1 and G2 are regular
(D) Both G1 and G2 are context-free but neither of them is regular

Answer: (D)
Explanation: Given grammars can be re-written as:
Say, while = w, expr =E, stmt = S, other = o
Here, we can write a right linear grammar for G1 as
S -> w(E)S
S -> o
E->ID

So, L(G1) is regular.
Now for G2 also we can write a right linear grammar:
S -> w(E)S

E -> E+E
E -> E*E
S -> o
But in this question both these grammar are neither right linear nor left linear.
So, option (D) is correct.
Quiz of this Question

Article Tags :