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 ) ) )"?

  1. A. 12
  2. B. 5
  3. C. 15
  4. 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

Exams that ask this topic