Document From Aditya Tripathi
Document From Aditya Tripathi
t1 = c * d
t2 = b + t1
a = t2
1.2 Quadruples
A 4-field structure for intermediate representation.
Format: (op, arg1, arg2, result) Example:
( *, c, d, t1 )
( +, b, t1, t2 )
( =, t2, -, a )
1.3 Triples
A compact form using implicit results (referenced by index).
Format: (op, arg1, arg2) Example:
( *, c, d )
( +, b, (0) )
( =, (1), a )
1
1.4 Translation of Assignment Statements
Translation involves breaking complex expressions into TAC, storing intermediate results in
temporary variables.
Example: x = (a + b) * (c - d)
t1 = a + b
t2 = c - d
t3 = t1 * t2
x = t3
• Short-circuit evaluation
Example: if (a < b) x = y;
if a < b goto L1
goto L2
L1: x = y
L2:
1.6 Backpatching
Backpatching is the process of filling in the target labels of jumps after code generation.
Example:
E.true = makelist(nextinstr)
emit("if a < b goto _")
2
2.2 Stack-Based Memory Allocation
Follows LIFO (Last-In-First-Out) using activation records for each function call.
Activation Record Contents:
• Return address
• Parameters
• Local variables
• Temporaries
Operations:
• insert(name, type, scope)
• lookup(name)
• delete(scope)
• Hash tables
• Linked lists
• Trees