Context Free Grammar: GATE CS Previous Year Questions

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 6–10 of 33

Q6GATE 2024 (Session 1)2 marksNAT
Let G=(V,Σ,S,P)G=(V, \Sigma, S, P) be a context-free grammar in Chomsky Normal Form with Σ={a,b,c}\Sigma=\{a, b, c\} and VV containing 10 variable symbols including the start symbol SS. The string w=a30b30c30w=a^{30} b^{30} c^{30} is derivable from SS. The number of steps (application of rules) in the derivation S→∗wS \rightarrow^* w is _____

Q7GATE 2024 (Session 2)2 marksMCQ−0.67 if wrong
Consider the following context-free grammar where the start symbol is SS and the set of terminals is {a,b,c,d}\{a, b, c, d\}.

S→AaAb∣BbBaA→cS∣ϵB→dS∣ϵ\begin{aligned} & S \rightarrow A a A b \mid B b B a \\ & A \rightarrow c S \mid \epsilon \\ & B \rightarrow d S \mid \epsilon \end{aligned}

The following is a partially-filled LL(1) parsing table.

abcd$SS→AaAbS→BbBa(1)(2)AA→ϵ(3)A→cSB(4)B→ϵB→dS\begin{array}{|c|c|c|c|c|c|} \hline & a & b & c & d & \$ \\ \hline S & S \rightarrow A a A b & S \rightarrow B b B a & (1) & (2) & \\ \hline A & A \rightarrow \epsilon & (3) & A \rightarrow c S & & \\ \hline B & (4) & B \rightarrow \epsilon & & B \rightarrow d S & \\ \hline \end{array}

Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?
Note: In the options, "blank" denotes that the corresponding cell is empty.

Q8GATE 2024 (Session 2)2 marksMSQ
Consider a context-free grammar GG with the following 3 rules.
S→aS,S→aSbS,S→cS \rightarrow a S, S \rightarrow a S b S, S \rightarrow c
Let w∈L(G)w \in L(G). Let na(w),nb(w),nc(w)n_a(w), n_b(w), n_c(w) denote the number of times a,b,ca, b, c occur in ww, respectively. Which of the following statements is/are TRUE?

One or more options are correct.

Q9GATE 2024 (Session 2)2 marksNAT
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a,b,c,d,#,@}\{a, b, c, d, \#, @\}
S′→SS→SS∣Aa∣bAc∣Bc∣bBaA→d#B→@\begin{aligned} & S^{\prime} \rightarrow S \\ & S \rightarrow S S|A a| b A c|B c| b B a \\ & A \rightarrow d \# \\ & B \rightarrow @ \end{aligned}
Let I0=CLOSURE⁡({S′→∙S})I_0=\operatorname{CLOSURE}\left(\left\{S^{\prime} \rightarrow \bullet S\right\}\right). The number of items in the set GOTO⁡(I0,S)\operatorname{GOTO}\left(I_0, S\right) is ____

Q10GATE 20232 marksMCQ−0.67 if wrong
Consider the context-free grammar GG below
S→aSb  ∣  XS\rightarrow aSb \;| \;X
X→aX  ∣  Xb  ∣  a  ∣  bX\rightarrow aX \;| \;Xb \;|\; a\;|\; b
where SS and XX are non-terminals, and aa and bb are terminal symbols. The starting non-terminal is SS.
Which one of the following statements is CORRECT?

Keep practising

Topics in Theory of Computation

All CS topics ›