Home » Theory of Computation » Theory of computation miscellaneous » Question

Theory of computation miscellaneous

Theory of Computation

  1. 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 Grammar G2
    D → int L; D → int L;
    L → id [E L → id E
    E → num] E → E[num]
    E → num] [E E → [num]

    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
Correct Option: A

Both G1 and G2 can correctly generate the declarations.



Your comments will be displayed only after manual approval.