โ† Compiler Design learning path
Compiler Design ยท Module 5 of 10

Syntax-directed translation

Attaching meaning to grammar rules.

๐Ÿ“– Key ideas

  1. Syntax-directed definitions attach attributes and semantic rules to productions.
  2. Synthesised attributes come from children; inherited attributes come from parent or siblings.
  3. S-attributed definitions use only synthesised attributes and suit bottom-up parsers.
  4. L-attributed definitions allow inherited attributes from the left and suit top-down parsing.
  5. Translation schemes build syntax trees, check types and generate code during parsing.
๐Ÿ’ก Real-life example: Like adding up a bill: each item has a price (attribute) and the total is computed from the items below it.
Synthesised attributeComputed from child nodes
Inherited attributeComputed from parent or left siblings
S-attributedUses only synthesised attributes
Annotated parse treeParse tree showing attribute values