edited by
8,821 views
40 votes
40 votes

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.
$$\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?

  1. Both G1 and G2
  2. Only G1
  3. Only G2
  4. Neither G1 nor G2
edited by

1 Answer

Best answer
61 votes
61 votes

Correct Option: A (Both $G1$ and $G2$)

edited by
Answer:

Related questions

22 votes
22 votes
1 answer
2
Akash Kanase asked Feb 12, 2016
5,021 views
Match the following:$$\begin{array}{ll|ll}\hline \text{(P)} & \text{Lexical analysis} & \text{(i)} & \text{Leftmost derivation} \\\hline \text{(Q)} & \text{Top down pars...