GATE Computer ScienceVery hardGATE CS (PYQ pattern)
SDD: S → ( S S ) | a. Inherited attribute S.d: the root has S.d = 0 and each child of a node gets parent.d + 1. Synthesised S.v: for a → a, S.v = S.d; for S → ( S1 S2 ), S.v = S1.v + S2.v. What is S.v at the root for the input "( ( a a ) ( a ( a a ) ) )"?
- A. 12
- B. 5
- C. 15
- D. 9
Correct answer: A. 12
Each leaf contributes its depth; the sum of leaf depths for this tree is 12. This definition is L-attributed (inherited depth flows down, the sum flows up).
More Compiler Design questions
- A Pascal-like scanner uses longest match (ties to the earlier rule) with rules: FLOAT = [0-9]+.[0-9]; INT = [0-9]+; RANGE = ..; DOT =…
- SDD: S → ( S S ) | a. S.d is inherited: root d = 0, children get parent.d + 1. For a → a: S.v = S.d if S.d is even, otherwise −S.d. For S…
- int i = 1; int A[1..4] = {4, 7, 2, 9}; void swap(x, y) { int t = x; x = y; y = t; } The call swap(i, A[i]) is made. The parameters are…
- For S′ → S; S → A | x b; A → a A b | B; B → x, what is the LALR(1) lookahead set of the item B → x · in the state reached from the start…
- int x = 1; int a() { return x; } int b(int n) { int x = n 10; if (n == 0) return a(); return b(n - 1) + a(); } What does b(2) return under…
- A basic block is converted to a DAG with value numbering (+ and commutative; a new leaf is made for each variable's initial value; a…