GateMCQSCIENTIFIC PREP LAB
PlanSign Up
ADVANCEDFrequently Tested 4 min read 19 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 AA strictly from attributes of AA's children (and tokens at AA). Evaluated naturally during bottom-up LR parsing.
  • Inherited Attribute: Computed at child node XiX_i from XiX_i's parent and/or siblings.
SDT ClassAllowed AttributesCompatible Parser Evaluation
S-Attributed SDTSynthesized ONLY (semantic actions at right end of production)Bottom-up LR stack evaluation
L-Attributed SDTSynthesized + Inherited ONLY from parent or LEFT siblings (X1,…,Xi−1X_1, \dots, X_{i-1})Top-down LL(1) / Depth-First Left-to-Right traversal

Every S-attributed SDT is automatically L-attributed (extS−Attributed⊊extL−Attributed ext{S-Attributed} \subsetneq ext{L-Attributed}).

2. Basic Blocks, Leaders & SSA Form

In Three-Address Code (TAC), Leader instructions partition code into Basic Blocks:

  1. The very first instruction of the intermediate code is a leader.
  2. Any instruction that is the target of a conditional or unconditional jump is a leader.
  3. 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 (x1,x2,…x_1, x_2, \dots), inserting ϕ\phi-functions at control-flow merge points.
  • Minimum Registers via Graph Coloring: Construct the Register Interference Graph where vertices = variables and an edge (u,v)(u, v) exists iff uu and vv are simultaneously live. Minimum registers without spilling = Chromatic Number χ(G)\chi(G)!
Key Formulas Summary
Data-Flow Liveness Equations (Backward Flow)
IN[B]=use[B]∪(OUT[B]−def[B]),OUT[B]=⋃S∈succ(B)IN[S]\text{IN}[B] = \text{use}[B] \cup (\text{OUT}[B] - \text{def}[B]), \quad \text{OUT}[B] = \bigcup_{S \in \text{succ}(B)} \text{IN}[S]
Note: Two variables interfere iff they are simultaneously live at some program point
#Compiler Design#SDT#S-Attributed#L-Attributed#Basic Blocks#Liveness

Practice Questions on This Chapter (4)

Q1GATE CS CompilerMCQMEDIUM
+2M • -0.67

In an L-Attributed Syntax-Directed Definition for production A→X1X2X3A \to X_1 X_2 X_3, an inherited attribute of symbol X2X_2 may depend on:

⚡ Click an option above to verify instantly
Q2GATE CS CompilerMCQMEDIUM
+2M • -0.67

In global register allocation via Chaitin’s algorithm, finding the minimum number of CPU registers needed for live variables without spilling reduces directly to:

⚡ Click an option above to verify instantly
Q3GATE CS 2020NATEASY
+1M • 0 Neg

How many lexical tokens are produced by a standard C lexical analyzer (using Maximal Munch) on the statement: printf("i = %d, &i = %x", i, &i);?

Q4GATE CS 2021 Set-2NATMEDIUM
+2M • 0 Neg

Consider the Syntax-Directed Definition: E→E1 # T  {E.val=E1.val×T.val}∣TE \to E_1 \text{ \texttt{\#} } T \;\{E.val = E_1.val \times T.val\} \mid T, and T→T1 & F  {T.val=T1.val+F.val}∣FT \to T_1 \text{ \texttt{\&} } F \;\{T.val = T_1.val + F.val\} \mid F, with F→numF \to \mathbf{num}. Notice + (&) has higher precedence than * (#) and both are left-associative! Evaluate 2 # 3 & 5 # 4 & 1.

Previous TopicLL(1) & LR(0), SLR(1), LALR(1), CLR(1) Parsing Power & ConflictsNext Topic Compilers 2027 Rank-Decider: Basic-Block Leaders, SSA Phi-Functions, Dominators & Graph Coloring