Understanding The Different Phases of Compiler

Understanding The Different Phases of Compiler

4 mins read609 Views Comment
Jaya Sharma
Senior Executive Content
Updated on Jan 5, 2023 17:35 IST

The process of compilation is segregated into six different phases of compiler. Every phase takes input from the previous phase to convert the high-level language into low-level language.


In this article, we will be discussing the different phases of compiler and how it works. 

Table of Contents

What is a compiler?

A compiler is a computer program that translates a source program written in high-level programming language into machine code for computer architecture. It ensures that the source code is accurate and properly formulated and the program is easy to understand. It can be used for several purposes, such as optimization, error detection, bug detection, and optimization of the generated code for performance. A compiler implements formal transformation from high-level source program to low-level target program.

Explore programming courses

Designs of compiler define an end-to-end solution and they tackle a defined subset that interfaces with compilation tools. Design requirements include a rigorously defined interface internally among compiler components and externally between supporting toolsets. If a compiler is written for a relatively simple language, it would be considered a monolithic piece of software. As the complexity of the source language increases, the design can be split into several interdependent phases. 

Explore networking and hardware courses

Importance of Compiler

The requirement for compilers arises due to the way in which traditional processors execute object code. Processors utilize logic gates for routing signals to circuit board. They manipulate binary high and low signals to work the arithmetic logic unit. Since the initial high-level code contains commands, variables, calls, functions, and methods in a combination of lexical and arithmetic syntax. 

Types of Compiler

There are different types of compilers in use:

  1. Cross compiler: It is a technology that allows developers to compile and run codes on multiple platforms. Such a compiler is useful while working on multiple versions of the code to ensure that all platforms in use are being supported. This is also useful while working on a new platform to verify if the code works on this platform. 
  2. Just-in-time (JIT) compiler: It is a compiler that is designed to compile programs as they are executed. The compiler is much faster than a traditional compiler that has to compile a program from scratch whenever it needs to be run. These help in reducing the program size by eliminating the redundant code. This makes the program smaller and more efficient, which helps in improving performance. 
  3. Source-to-source compiler: It is a software tool that is used for translating the source code into an executable code. This compiler is used for translating source code written in various programming languages. The process of translation can be completed both manually and automatically. It is performed by compiler that translates the source code into machine code which is then executed by target machine.
  4. Bytecode compiler: It is a compiler that is used for translating high-level language into machine code that is executable on the target machine. These compilers allow developers to write codes in high-level language and compile them to machine code. Through bytecode compilers, developers can write concise and easy to understand codes. However, these compilers need to be written in high-level language and are not suitable for developing low-level code.
  5. Binary compiler: It is a type of compiler that translates source code files into binary format. This format stores information of the program in a compact form which can be easily read by the computer. Developers use such compilers for database administration, network programming and web development.
  6. Hardware compiler: These compilers compile source code into machine code to transform the source code into machine code. After that, the computer executes this code. Such a compiler is used in embedded systems, operating systems and computer games. Assembler is an example of a hardware compiler.

Explore operating system courses

Difference Between Compiler and Assembler
Difference Between Compiler and Assembler
The main difference between compiler and assembler is that a compiler allows you to convert high-level programming language code into machine language code. In contrast, an assembler allows you to...read more
The Difference between Compiler and Interpreter
The Difference between Compiler and Interpreter
Both compiler and interpreter are responsible for converting source code into machine code. However, compiler converts the code before execution whereas interpreter converts the code after execution. The two also...read more
What is the Difference Between Hardware and Software?
What is the Difference Between Hardware and Software?
Businesses today rely on software and software relies on hardware to function properly. In this blog, let us explore the difference between hardware and software.

Phases of Compiler

In a compiler, there are the following six phases:

  1. Lexical analysis: This is the first phase of compiler which converts high level input programs into sequence of tokens. These tokens are sequence of characters that are treated as a unit in grammar of the programming language. It can be implemented with Deterministic finite Automata. The output is a sequence of tokens sent to parser for syntax analysis.
  2. Syntactic analysis or Parsing: Also known as syntax analysis; this is the second phase where provided input string is scanned for validation of structure of standard grammer. The syntactical structure is analysed and inspected to check whether the given input is correct in terms of programming syntax. 
  3. Semantic analysis: In the third phase, the compiler scans whether parse tree follows the guidelines of language. The compiler keeps track of identifiers and expressions. A semantic analyzer defines the validity of parse tree and an annotated syntax tree is the output.
  4. Intermediate code generation: Once the parse tree is semantically confirmed, an intermediate code generator develops three address codes. During the time of the translation of source program into object code, a middle-level language code is generated by the compiler. 
  5. Code optimizer: This is an optional phase of compiler that is used for optimizing the intermediate code. Through this optimization, the program runs fast and consumes less space. To increase the program speed, unnecessary strings of code are eliminated and sequences of statements are organized.
  6. Code generation: It is the final phase of compiler where the compiler acquires fully optimized intermediate code as input and maps it to machine code. During this phase, the intermediate code is translated into machine code.

Explore free online courses with certificates


Recently completed any professional course/certification from the market? Tell us what you liked or disliked in the course for more curated content.

Click here to submit its review.

Download this article as PDF to read offline

Download as PDF
About the Author
Jaya Sharma
Senior Executive Content

Jaya is a writer with an experience of over 5 years in content creation and marketing. Her writing style is versatile since she likes to write as per the requirement of the domain. She has worked on Technology, Fina... Read Full Bio


We use cookies to improve your experience. By continuing to browse the site, you agree to our Privacy Policy and Cookie Policy.