in Compiler Design
45 votes

Which of the following statements are true?

  1. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa
  2. All $\epsilon$-productions can be removed from any context-free grammar by suitable transformations
  3. The language generated by a context-free grammar all of whose productions are of the form $X \rightarrow w$ or $X \rightarrow wY$ (where, $w$ is a string of terminals and $Y$ is a non-terminal), is always regular
  4. The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees
  1. I, II, III and IV
  2. II, III and IV only
  3. I, III and IV only
  4. I, II and IV only
in Compiler Design


take for example we havp production of form

A-=>AaA/a then how can S1 will be true
we can not convert left linear grammar to right or right to left linear grammar directly by reversing each terminal and non terminal of the grammar. But it is possible with the help of other methods.

Subscribe to GO Classes for GATE CSE 2022

4 Answers

60 votes
Best answer

Answer is C: 

Statement $1$ is true: Using GNF we can convert Left recursive grammar to right recursive and by using reversal of CFG and GNF we can convert right recursive to left recursive.

Statement $2$ is false: because if $\epsilon$ is in the language then we can't remove  $\epsilon$ production from Start symbol. (For example $L = a^*$)

Statement $3$ is true because right linear grammar generates regular set

Statement $4$ is true, only two non-terminals are there in each production in CNF. So it always form a binary tree.

edited by


How can we convert using GNF(left recursive grammar to right recursive grammar and vice versa.?

2nd statement says ϵ  can be removed from Grammar.

Suppose we have a grammar like

S -> AbaC

A -> BC

B -> b/ ϵ

C -> D/ ϵ

D -> d

In this case ϵ  productions can be removed. Correct me if i am wrong..


@Shamim Ahmed option b says all epsilon can be removed. If language can generate epsilon, how can we remove it? start symbol will always have it to generate epsilon. 

How is option 3 correct?

Ex:  X -> a/aY, Y -> aYb/epsilon.. This will give a^n+1 b^n which is not regular. Where am I going wrong?

You cannot have such  production Y -> aYb/epsilon.    since all the production are of the form

X->wY or x->w

You can have Y->aY or Y->aX (x is non terminal) or Y->b   but not  Y -> aYb/epsilon


16 votes

1.Every left recursive grammar can be converted to a right recursive grammar and vice versa

    yes their is algo.

2. All ∈ production can be removed from any CFG by suitable transformation

   NO when language itself contain null then u can't remove null.

3. The language generated by a CFG all whose production are to the form X→ w or X→ wY 

    yup their is formula for it X-> aT* then regular since right linear form

4.The derivation trees of strings generated by a CFG in CNF are alays binary trees.

    yes b/c cfn in form of S->AB or S->a so max two child at a time.

Answer is (C)

6 votes
2nd is false

S->∈ if we have this production in our cfg we can remove it if we do so it changes language

All other options are true so ans is c


but,we have a procedure to remove null production in cfg isnt it???and the qs asked that all epsilon production can be removed or not...

Yes, we can remove any Null production except in one case if we can derive $\epsilon$ from grammar, we cannot remove that. 

eg. $S\rightarrow aS|\epsilon$ generating language $L = a^*$, and if we remove $\epsilon$ from it,
we will get $S\rightarrow aS|a$ generating a different language ,$L = a^+$ 

1 vote

Explanation for I.


  • Reverse "LLG for L" to get "RLG for LR" by changing A → Ba to A → aB
  • Convert "RLG for LR" directly to "FA for LR"
  • Reverse "FA for LR" to get "FA for L" by
    • Change starting state to final state
    • Reverse direction of each transition
    • Create a new start state with ϵ transitions to all accepting states
    • Convert "FA for L" directly to "RLG for L"

Similar approach can be derived for converting "RLG for L" to "LLG of L".


Related questions