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 ) ) )"?
- A. 44
- B. 38
- C. 46
- 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
- Minimal SSA form (φ-functions placed at the iterated dominance frontier of each variable's definition blocks, without liveness pruning…
- Which of the following about run-time environments is/are true? I. An access (static) link points to the frame of the lexically enclosing…
- For S′ → S; S → S ( S ) | ε, LALR(1) merges canonical LR(1) states with equal cores. The LALR state whose only item is S → S ( S ) · is…
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: i = i + 1; 4: if i > k goto L1; 5: j = j + i; 6: goto L1; 7: L3: return j, how many back edges…
- An SLR(1) shift-reduce parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses "id + id id". Each shift and…
- Backpatching scheme (each relation gives 'if r goto ' and 'goto ', no fall-through optimisation, instruction numbers from 100). How many…