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 11–15 of 33
Consider the following context-free grammar where the set of terminals is .
The following is a partially-filled LL(1) parsing table.
Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?
The following is a partially-filled LL(1) parsing table.
Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?
Answer: (A)
Cells (1) and (2) are [S, c] and [S, f]. The rule goes under every symbol in FIRST of . can start with c or can be , and then f comes next, so . So cells (1) and (2) both hold .
Cells (3) and (4) are [T, c] and [T, ]. The rule goes under every symbol in FOLLOW(T). Find it from the rules that have T on the right side:
- : T is followed by R, so c is in FOLLOW(T). R can be , so FOLLOW(R) is also in FOLLOW(T). R is followed by f in , so .
- : T is at the end, so FOLLOW(S) is in FOLLOW(T).
- : S is at the end, so FOLLOW(T) is in FOLLOW(S). S is the start symbol, so is in FOLLOW(S). Together with the previous point, is in FOLLOW(T).
So . The f cell already has , and the c and cells get it too.
So (1) , (2) , (3) , (4) .
Answer: (A)
Cells (3) and (4) are [T, c] and [T, ]. The rule goes under every symbol in FOLLOW(T). Find it from the rules that have T on the right side:
- : T is followed by R, so c is in FOLLOW(T). R can be , so FOLLOW(R) is also in FOLLOW(T). R is followed by f in , so .
- : T is at the end, so FOLLOW(S) is in FOLLOW(T).
- : S is at the end, so FOLLOW(T) is in FOLLOW(S). S is the start symbol, so is in FOLLOW(S). Together with the previous point, is in FOLLOW(T).
So . The f cell already has , and the c and cells get it too.
So (1) , (2) , (3) , (4) .
Answer: (A)
Consider the following context-free grammar over the alphabet = {a,b,c} with S as the start symbol.
SabScT|abcT
TbT|b
Which one of the following represents the language generated by the above grammar ?
SabScT|abcT
TbT|b
Which one of the following represents the language generated by the above grammar ?
Answer: (B)
produces with .
Each use of adds "ab" on the left and "cT" on the right, and the last step adds one more such pair. After pairs the string is
with copies of .
Every is a separate non-terminal, so each one is replaced by on its own, with its own . So the language is
with .
This rules out the others. (A) fixes every . (C) forces all to be equal. (D) has blocks of , but the grammar always gives exactly c's. For example, is in the language but its two blocks differ, so it is in neither (C) nor (D).
Answer: (B)
Each use of adds "ab" on the left and "cT" on the right, and the last step adds one more such pair. After pairs the string is
with copies of .
Every is a separate non-terminal, so each one is replaced by on its own, with its own . So the language is
with .
This rules out the others. (A) fixes every . (C) forces all to be equal. (D) has blocks of , but the grammar always gives exactly c's. For example, is in the language but its two blocks differ, so it is in neither (C) nor (D).
Answer: (B)
Consider the following grammar.
PxQRS
Qyz|z
Rw|
Sy
What is FOLLOW (Q) ?
PxQRS
Qyz|z
Rw|
Sy
What is FOLLOW (Q) ?
Answer: (C)
Look at the rule . Here Q is followed by RS. FIRST(R) = {w, }, so w goes into FOLLOW(Q). R can also become empty, so FIRST(S) = {y} goes in as well.
FOLLOW(Q) = {w, y}
Answer: {w, y}
FOLLOW(Q) = {w, y}
Answer: {w, y}
If G is grammar with productions
where S is the start variable, then which one of the following is not generated by G?
where S is the start variable, then which one of the following is not generated by G?
Answer: (D)
Every rule keeps the number of b's from going above the number of a's. The rules aSb and bSa add one a and one b each. The rule SaS adds one extra a. The rules SS and add nothing. So every string G generates has .
The string babba has 2 a's and 3 b's so G cannot generate it.
Answer: babba
The string babba has 2 a's and 3 b's so G cannot generate it.
Answer: babba
Which of the following statements about parser is/are CORRECT?
I. Canonical LR is more powerful than SLR.
II. SLR is more powerful than LALR
III. SLR is more powerful than Canonical LR.
I. Canonical LR is more powerful than SLR.
II. SLR is more powerful than LALR
III. SLR is more powerful than Canonical LR.
Answer: (A)
Order of power among LR parsers: LR(0) SLR LALR Canonical LR. This means only the statement "Canonical LR is more powerful than SLR" is correct.
Answer: I only
Answer: I only
Keep practising