GATE CS 2016, set 2 · Question 56 · Theory of Computation · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

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 .
Which of the grammars correctly generate the declaration mentioned above?

Grammar G1Grammar G2
D → int L;D → int L;
L → id [EL → id E
E → num]E → E[num]
E → num] [EE → [num]
  1. (A) Both G1 and G2
  2. (B) Only G1
  3. (C) Only G2
  4. (D) Neither G1 nor G2
Answer

Answer (A)

Answer from the official GATE CS 2016 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes