GATEverse Practice, past papers & mock tests
GATE 2016 · CS2 - Afternoon
Compiler DesignParsing TechniqueseasyMCQ2 marks
A student defines two context-free grammars \(G_1\) and \(G_2\) for generating C-style array declarations having at least one dimension. For example, \[ \texttt{int a[10][3];} \] The start symbol is \(D\), and the terminals are int, ;, id, [, ], and num. The grammars are: \[ \begin{aligned} G_1:\qquad D &\rightarrow \texttt{int }L\texttt{;}\\ L &\rightarrow \texttt{id [}E\\ E &\rightarrow \texttt{num ]}\\ E &\rightarrow \texttt{num ][}E \end{aligned} \] \[ \begin{aligned} G_2:\qquad D &\rightarrow \texttt{int }L\texttt{;}\\ L &\rightarrow \texttt{id }E\\ E &\rightarrow E\texttt{[num]}\\ E &\rightarrow \texttt{[num]} \end{aligned} \] Which of the grammars can generate the declaration \(\texttt{int a[10][3];}\)? A. Both \(G_1\) and \(G_2\) B. Only \(G_1\) C. Only \(G_2\) D. Neither \(G_1\) nor \(G_2\)
Save your progress

Related Compiler Design PYQs