Subtopic 1 of 5
6.1Synthesized and inherited attributes
Synthesized: computed from the children (bottom-up), e.g. E.val. Inherited: computed from the parent or left siblings (top-down), e.g. the type passed along a declaration list.
E
E
T
T
F
digit 3
*
F
digit 5
+
T
F
digit 4
- digit.lexval = 3 (from the lexer)
- F.val = digit.lexval = 3
- T.val = F.val = 3
- digit.lexval = 5 (from the lexer)
- F.val = digit.lexval = 5
- T.val = T1.val × F.val = 3 × 5 = 15
- E.val = T.val = 15
- digit.lexval = 4 (from the lexer)
- F.val = digit.lexval = 4
- T.val = F.val = 4
- E.val = E1.val + T.val = 15 + 4 = 19
Information flows UP the tree: each node computes val from its children.
Previous year questions: Syntax-Directed Translation (9)
PYQs are grouped by topic, so this is the full set for Syntax-Directed Translation; try the ones that match this subtopic. Open all 9 on the topic page.