Compiler Design Tutorial

Our compiler design tutorial will provide all the information about compiler from basic to advanced level. This compiler tutorial will help the student for their semester as well as for competitive exams. This compiler tutorial is designed for both beginners and professionals as well.

What is Compiler?

The compiler is a software that converts high-level (Source Code) language to low-level language (Machine code) without changing the meaning of the Source code. In order to provide an optimized result, the compiler should be efficient enough that it takes less time and space while executing the code.

What is Compiler?

Why Compiler?

Language Processing System

The computer is built as a combination of hardware and software. The hardware cannot understand a human-readable language, or mainly, the code is written in the high-level language. So, in order to understand this code by machines, it goes through multiple transformations, and this is when the language processing system comes into play. It plays an important role in compiler design.

Whenever we write code in any high-level language, the high-level language goes through different phases and converts into binary language.

In the language procedure system, we’ll see how a code written in any high-level language is converted into machine-level language.

Consider the following example;

Why Compiler?
  • A user writes code in a high-level language like c. 
  • The compiler of high-level language converts source code into assembly language.
  • An assembly language is an intermediate between source code and machine language.
  • Then assembler converts the code that is compiled before into relocatable machine code.
  • Lastly, the linker links all the files and loader puts all the executable program together and load into memory.

Before moving forward, we need to understand the few terms related to the compiler.

HLL – If any program consists #<include> or #<define>, then it is known as high-level language (HLL)

Pre-Processor – Pre-Processor will remove all the #<include> by file inclusion and #<define> by macro expansion.

Assembly Language – It’s neither completely in the form of 0s and 1s nor in a high-level language. It is somewhere intermediate between the high-level language and machine code.

Assembler – Assembler is platform dependent. It means that for every platform (Hardware + OS), we’ll have an assembler. It takes assembly language as an input and converts it into relocatable machine code.

Linker/Loader – Linker and loader is the component of the operating system. The linker is a program that combines different object files into a single executable file. The main task of the linker is to search and locate the reference in the main memory when an executable code will be loaded. Then loader loads all the programs into the main memory and executes them.

Interpreter – The interpreter also converts high-level language into low-level language. But interpreter is different from the compiler based on how they take the input. An interpreter takes input in different ways. The compiler reads all the input at one time and does the processing and execute them. But in the case of an interpreter, it takes input line by line and shows if the source code is error-free or has some error. The compiler takes the whole program at the same time and converts it into machine-level language, whereas the interpreter takes input line by line. Interpreter language is slower than compiler language.

Difference between Interpreter and Compiler

1.It scans the whole program at one time.It scans each line of the program line by line.
2.It shows the error at the end of the execution of the program.It shows the error line by line.
3.It is faster than the interpreter.It is much slower as compared to the compiler.
4.Error detection in the compiler is difficult.Error detection in the interpreter is easy.
5.It shows all the error after the execution of the programIt shows all the error line by line
6.Examples are C, C#, C++Examples are PHP, Python, Perl etc.

Compiler Design Index

Pin It on Pinterest

Share This