GATE Computer ScienceHardGATE CS (PYQ pattern)

SDD for S → ( S1 S2 ) | a: the inherited attribute S.n is 1 at the root, and for S → ( S1 S2 ) the rules are S1.n = 2 × S.n and S2.n = 2 × S.n + 1. The synthesised S.v is S.n for S → a and S1.v + S2.v for S → ( S1 S2 ). What is S.v at the root for "( ( a a ) ( a ( a a ) ) )"?

  1. A. 44
  2. B. 38
  3. C. 46
  4. D. 22

Correct answer: A. 44

The numbering is heap numbering of the parse tree. Root 1 has children 2 = (a a) and 3 = (a (a a)). Node 2's leaves are 4 and 5; node 3 has leaf 6 and node 7, whose leaves are 14 and 15. S.v sums the leaves: 4 + 5 + 6 + 14 + 15 = 44.

More Compiler Design questions

Exams that ask this topic