Gate CS-2016-2 Question Paper With Solutions

Q. 56 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 G1
D → int L;
L → id [E
E → num]
E → num] [E

Grammar G2
D → int L;
L → id E
E → E[num]
E → [num]

Which of the grammars correctly generate the declaration mentioned above?

(A) Both G1 and G2

(B) Only G1

(C) Only G2

(D) Neither G1 nor G2

Answer: (A)

Explanation:

Gate CS-2016-2 Question Paper With Solutions Gate CS-2016-2 Question Paper With Solutions Gate CS-2016-2 Question Paper With Solutions

Learn More:   Gate ME-2006 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here