What is a compiler in a computer? How does a compiler work?

Do you know what is compiler? If not, then there is a great opportunity for you to understand this technology easily. Whether you are from a technical student or a non-tech background, it is good for everyone to understand this compiler. Because it is used in all places. By the way, it is very important for a Computer Science student to understand it. Because if you have to understand about programming completely then it becomes very important to know about the work of the compiler.


What is Compiler

A Compiler is a software program that transforms high-level source code written by a developer into a high-level programming language into a low level object code (binary code) machine language, and which Can be shared easily through the Key Processor. This process in which high-level programming is converted to machine language is called Compilation.

What is compiler called

Like I have already introduced you to the technical definition of Compiler, as everyone often does, but now I am going to explain the definition of Compiler itself in a very easy language so that even a non-technical person Can understand.

For some time, forget about compiler and imagine that you have gone to a beautiful country to spend your vacation. A very basic problem in this is that you speak, write and understand only in your regional language which is Hindi. But the citizens of that country do not know anything other than English only. Then how will you communicate with others there?

In such a situation, the only solution is that you will need a language translator, which can be a human or a book or even an App. This language translator will translate your Hindi into English so that the other person can understand your words. Together, he will convert English into Hindi as well so that you can understand his language too.

The same thing happens with a computer. Computers also understand only binary language (language which consists of 0s and 1s), while users who understand Computer as English or any language. In such a situation, how will the computer understand the commands given by you? Also, you will not understand any process calculation performed by the computer. In such a situation, there is a need for a language translator so that it can match the two.


What is the use of compiler

Compilers are most commonly used to perform four major steps.

1. Scanning: This scanner reads one character at a time from the source code and keeps track of all the characters, which shows which character is present in which line.

2. Lexical Analysis: The compiler converts sequence of characters that appear in source code into a series of strings of characters (called key tokens) that are associated with a specific rule in a program. By whom a lexical analyzer. A symbol table is used in the lexical analyzer to store the words in the source code that correspond to the token generated.

3. Syntactic Analysis: In this step, syntax analysis is done, which involves preprocessing which determines whether the tokens that are created are in proper order during lexical analysis or not according to usage. The correct order of set of keywords that ultimately yields a desired result is called Syntax. In this, the compiler has to check these source code so as to ensure syntactic accuracy.


4. Semantic Analysis: This step consists of many intermediate steps. First, the structure of tokens is checked in this, along with their order is also checked whether it is according to the grammar of the given language or not. The meaning of the Token Structure is interpreted by parser and analyzer to finally generate an intermediate code called Object code. These object codes contain instructions that represent the processor action for a corresponding token when it is encountered in the program. Finally, the entire entire code is parsed and interpreted to check whether any optimizations are possible or not. Once the optimizations are performed, then the appropriate modified tokens are inserted into the object code to generate the final object code, which is saved within a file.

What is different phases of compiler

Come here, you people know about the different phases that are being used to operate the compiler.

1. Lexical Analysis
2. Synatx Analysis
3. Semantic Analysis
4. Intermediate Code Generator
5. Code optimizer
6. Code generation





Comments