For each high-level programming language, we need a translator because the computer does not understand the high-language code written by the user. The translator converts the high-level language source file to byte code or object code. Most all programming languages use a compiler and interpreter translator to translate the source code.
Here in this article, we have given a brief description of the Compiler translator.
What is a Compiler?
A compiler is a program that is usually known as a translator, and it is used to turn high-level language into machine language so the computer can execute the human-written code. These days developers only use high-level languages, which are not machine-friendly, and machines and computers do not have a direct approach to these kinds of languages. For that, we use a translator so the machine can understand how that particular code should be executed.
How does a compiler work?
A compiler reads source code line by line at once and show appropriate error after reading the code, it works in various phases, and each phase depends on the previous phase. A compiler includes 6 phases which are:
- Lexical analysis
- Syntax analysis
- Semantic analysis
- Intermediate code generator
- Code Optimizer
- Code generator
This phase of the compiler scans the code and divides the code into groups of tokens.
This phase of the compiler checks the syntax of the program and assures whether the code is written according to the syntax or not.
This phase of the compiler checks the meaning of the program. It checks whether the program code follows a meaningful approach or not.
Intermediate Code Generation
This phase of the compiler commences with the generation of Intermediate code; this intermediate code is the middle language of high-level and machine language.
This phase of the compiler deals with the unwanted code written in the program and removes them. Code optimization creates a sequence of intermediate code, so the execution of the code becomes easy.
This is the most important phase of the compiler, which accepts the sequence of code from the optimization phase and converts it into object code.
The compiler just does not convert the high-level code to the object code but also checks its legitimacy. As the working of the compiler is divided into 6 phases, which state that it is a collection of subprograms. Programming languages like C++, Java, C, and Perl use the compiler as a translator.
People are also reading:
Leave a Comment on this Post