ADVANCED🔥 High-Yield Exam Topic 4 min read 3 views
Syntax-Directed Translation (SDT), Three-Address Code & Register Liveness
Synthesized vs Inherited attributes, S-attributed vs L-attributed SDTs, Basic Block leader identification, SSA static single assignment, and Chaitin register interference graph coloring.
1. Synthesized vs Inherited Attributes & SDT Classes
- Synthesized Attribute: Computed at parent node strictly from attributes of 's children (and tokens at ). Evaluated naturally during bottom-up LR parsing.
- Inherited Attribute: Computed at child node from 's parent and/or siblings.
| SDT Class | Allowed Attributes | Compatible Parser Evaluation |
|---|---|---|
| S-Attributed SDT | Synthesized ONLY (semantic actions at right end of production) | Bottom-up LR stack evaluation |
| L-Attributed SDT | Synthesized + Inherited ONLY from parent or LEFT siblings () | Top-down LL(1) / Depth-First Left-to-Right traversal |
Every S-attributed SDT is automatically L-attributed ().
2. Basic Blocks, Leaders & SSA Form
In Three-Address Code (TAC), Leader instructions partition code into Basic Blocks:
- The very first instruction of the intermediate code is a leader.
- Any instruction that is the target of a conditional or unconditional jump is a leader.
- Any instruction that immediately follows a conditional or unconditional jump is a leader.
- Static Single Assignment (SSA): Every variable is assigned at most once statically (), inserting -functions at control-flow merge points.
- Minimum Registers via Graph Coloring: Construct the Register Interference Graph where vertices = variables and an edge exists iff and are simultaneously live. Minimum registers without spilling = Chromatic Number !
📐 Quick Revision Formula Sheet
Data-Flow Liveness Equations (Backward Flow)
💡 Two variables interfere iff they are simultaneously live at some program point
#Compiler Design#SDT#S-Attributed#L-Attributed#Basic Blocks#Liveness
🎯 Practice PYQs on This Topic (2)
Q1.GATE CS CompilerMCQMEDIUM
+2 Marks • -0.67 NegIn an L-Attributed Syntax-Directed Definition for production , an inherited attribute of symbol may depend on:
Q2.GATE CS CompilerMCQMEDIUM
+2 Marks • -0.67 NegIn global register allocation via Chaitin’s algorithm, finding the minimum number of CPU registers needed for live variables without spilling reduces directly to: