Compiler Design (All Modules) - 22

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

V (Execute)

+-----------------+
| Running Program |
+-----------------+

This diagram depicts the role of intermediate languages in compilation. The source code, written in a high-level language
like C++ or Java, is first compiled into an intermediate representation (IL). This IL code is then translated into machine code
specific to the target architecture (e.g., the processor of the computer). Finally, the machine code is executed by the
computer to run the program.

Explanation:

 The compilation process starts with the source code written in a high-level language like C++.
 The compiler performs various tasks like lexical analysis (breaking code into tokens), syntax analysis (verifying
code structure), and semantic analysis (ensuring code makes sense).
 After these initial stages, the compiler generates an intermediate representation of the program in the form of IL.
 The IL code is platform-independent, meaning it doesn't rely on the specific instructions of a particular processor.
 The code generator, a component of the compiler, then translates the IL into machine code.
 This machine code is tailored to the instruction set of the target processor where the program will eventually run.

Q3: Three address code

Ans: Three-address code (TAC), also known as triples or quads, is a type of intermediate language used in compiler design.
It represents each operation in a program using a fixed format with at most three operands. This simplicity makes TAC easy
to generate and manipulate during the compilation process. Here's a breakdown of TAC's key characteristics:

Structure:

 Each TAC instruction has the following format:


 target = operation source1 source2

o target: The variable or register where the result of the operation is stored.
o operation: The arithmetic, logical, or assignment operator (e.g., +, -, *, /, =).
o source1, source2 (optional): The operands used in the operation.
 TAC instructions are typically stored in a sequence, representing the program's flow of execution.

Example:

temp1 = x + y
z = temp1 * 2
a=z/3

Benefits of TAC:

 Simplicity: Easy to understand and generate during compilation.


 Machine Independence: Platform-independent representation, facilitating code generation for various
architectures.
 Optimization Potential: TAC serves as a good starting point for applying various code optimization techniques
(e.g., constant folding, common subexpression elimination).

Limitations of TAC:

 Verbosity: Can become verbose for complex expressions requiring multiple TAC instructions.
 Control Flow Representation: Control flow statements (if-else, loops) might require additional mechanisms for
proper representation.

Applications of TAC:

You might also like