0% found this document useful (0 votes)
4 views3 pages

Document From Aditya Tripathi

The document discusses Intermediate Code Generation and Runtime Memory Management in programming languages. It covers concepts such as Three Address Code, Quadruples, Triples, and the translation of assignment and Boolean expressions, along with backpatching techniques. Additionally, it explains memory management strategies including static and dynamic allocation, stack-based memory allocation, and symbol table management.

Uploaded by

Aditya Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Document From Aditya Tripathi

The document discusses Intermediate Code Generation and Runtime Memory Management in programming languages. It covers concepts such as Three Address Code, Quadruples, Triples, and the translation of assignment and Boolean expressions, along with backpatching techniques. Additionally, it explains memory management strategies including static and dynamic allocation, stack-based memory allocation, and symbol table management.

Uploaded by

Aditya Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIT-IV: Intermediate Code Generation and

Runtime Memory Management

1 Intermediate Code Generation


Intermediate Code (IC) is generated between the high-level source code and the machine
code. It is independent of both the source and target languages and makes optimization
easier.

1.1 Three Address Code (TAC)


TAC uses at most three addresses (operands) per instruction.
Example: Expression: a = b + c * d TAC:

t1 = c * d
t2 = b + t1
a = t2

Reference: Intermediate Code Generation - GFG

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

1.5 Translation of Boolean Expressions and Control Structures


Boolean expressions are translated using:

• Short-circuit evaluation

• Control flow translation

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 _")

Later, the target label is patched using: backpatch(E.true, target)


Reference: Backpatching - GFG

2 Run-Time Memory Management


Manages allocation and deallocation of memory during program execution.

2.1 Static vs Dynamic Storage Allocation


• Static Allocation: Memory allocated at compile time.

• Dynamic Allocation: Memory allocated at runtime using stack/heap.

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

Reference: Runtime Memory Management - GFG

3 Symbol Table Management


A symbol table holds information about identifiers (variables, functions, classes, etc.).

Operations:
• insert(name, type, scope)

• lookup(name)

• delete(scope)

Data Structures Used:

• Hash tables

• Linked lists

• Trees

Reference: Symbol Table - GFG

You might also like