โ Compiler Design learning pathCompiler Design ยท Module 5 of 10
Syntax-directed translation
Attaching meaning to grammar rules.
๐ Key ideas
- Syntax-directed definitions attach attributes and semantic rules to productions.
- Synthesised attributes come from children; inherited attributes come from parent or siblings.
- S-attributed definitions use only synthesised attributes and suit bottom-up parsers.
- L-attributed definitions allow inherited attributes from the left and suit top-down parsing.
- 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