Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2016 Set 2
Questions

Q46

MCQ2 marks, −0.67Compiler designMedium

A student wrote two context-free grammars G1 and G2 for generating a single C-like array declaration. The dimension of the array is at least one. For example,

int a[10] [3];

The grammars use D as the start symbol, and use six terminal symbols int ; id [ ] num.

Grammar G1Grammar G2D→int L;D→int L;L→id [EL→id EE→num ]E→E [num]E→num ] [EE→[num]\begin{array}{l|l} \text{Grammar } \textbf{G1} & \text{Grammar } \textbf{G2} \\\hline \text{D} \rightarrow \textbf{int L;} & \text{D} \rightarrow \textbf{int L;}\\ \text{L} \rightarrow \textbf{id [E} & \text{L} \rightarrow \textbf{id E}\\ \text{E} \rightarrow \textbf{num ]} & \text{E} \rightarrow \textbf{E [num]}\\ \text{E} \rightarrow \textbf{num ] [E} & \text{E} \rightarrow \textbf{[num]}\\ \end{array}

Which of the grammars correctly generate the declaration mentioned above?

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.