∑GateAndNet
Practice MCQs
GATE CS / Compiler Design
Edit
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 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)!
📐 Quick Revision Formula Sheet
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]
💡 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 Neg

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:

Q2.GATE CS CompilerMCQMEDIUM
+2 Marks • -0.67 Neg

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

Previous TopicLL(1) & LR(0), SLR(1), LALR(1), CLR(1) Parsing Power & ConflictsNext Topic CPU Scheduling, Semaphores & Deadlock Banker’s Formula