Context Free Grammar · Theory of Computation
33 questions · asked in 12 of 27 years (2000–2026)
MCQ 26 · MSQ 5 · NAT 21-mark 15 · 2-mark 18
2000Questions per year2026
Questions 16–20 of 33
Identify the language generated by the following grammar, where S is start variable.
S XY
X aX|a
Y aYb|
S XY
X aX|a
Y aYb|
Answer: (C)
X produces where k 1. Y produces where n 0. When we join them, the string is , so the number of a's is strictly greater than the number of b's.
Answer:
Answer:
Consider the following expression grammar G:
EE-T|T
TT+F|F
F(E)|id
Which of the following grammars is not left recursive, but is equivalent to G?
EE-T|T
TT+F|F
F(E)|id
Which of the following grammars is not left recursive, but is equivalent to G?
Answer: (C)
Use the standard rule to remove left recursion:
- Rule is rewritten as
- Rule is rewritten as
Option 1 still has left recursion. Option 2 still keeps the left-recursive rule . Option 4 changes the language.
Answer: Option 3
- Rule is rewritten as
- Rule is rewritten as
Option 1 still has left recursion. Option 2 still keeps the left-recursive rule . Option 4 changes the language.
Answer: Option 3
Which of the following languages is generated by the given grammar?
Answer: (D)
At every step, the rule puts down one a or one b. It can do this in any order and as many times as needed. So it generates every string over {a, b}, and this also covers .
Answer: {a,b}*
Answer: {a,b}*
Consider the following context-free grammars:
G1: SaS|B,
Bb|bB
G2: SaA|bB,
AaA|B|,
BbB|
Which one of the following pair of languages is generated by G1 and G2, respectively?
G1: SaS|B,
Bb|bB
G2: SaA|bB,
AaA|B|,
BbB|
Which one of the following pair of languages is generated by G1 and G2, respectively?
Answer: (D)
Let us check each grammar:
- G1: gives any number of a's, then one B. gives at least one b. So G1 gives .
- G2: gives , and gives . Starting with aA we get . Starting with bB we get . The union is , every string of a's then b's except the empty string.
Option (A) is wrong because G1 cannot give "a" (no b). Option (B) is wrong for both: its first language needs and , so it misses "b", which G1 gives, and its second language ( or ) also contains the empty string, which G2 cannot give. Option (C) is wrong for G2: it needs both and , so it misses "a" and "b".
Answer: (D)
- G1: gives any number of a's, then one B. gives at least one b. So G1 gives .
- G2: gives , and gives . Starting with aA we get . Starting with bB we get . The union is , every string of a's then b's except the empty string.
Option (A) is wrong because G1 cannot give "a" (no b). Option (B) is wrong for both: its first language needs and , so it misses "b", which G1 gives, and its second language ( or ) also contains the empty string, which G2 cannot give. Option (C) is wrong for G2: it needs both and , so it misses "a" and "b".
Answer: (D)
Which one of the following grammars is free from left recursion?
Answer: (B)
Check each option:
- Option 1: is directly left recursive.
- Option 2: S, A and B never begin with themselves, directly or indirectly. True
- Option 3: with gives (indirect).
- Option 4: with gives (indirect).
Answer: Option 2
- Option 1: is directly left recursive.
- Option 2: S, A and B never begin with themselves, directly or indirectly. True
- Option 3: with gives (indirect).
- Option 4: with gives (indirect).
Answer: Option 2
Keep practising