What is Compiler?

By | July 6, 2019

When we say programming and programming languages we start thinking of Python, Java, C++, C, JavaScript, Kotlin and so on, and the most common thing about these languages is that these all are High-level programming languages. For each high-level programming language, we need a translator because the computer does not understand high-language code written by the user. The translator converts the high-level language source file to byte code or object code. Mostly all programming language use compiler and interpreter translator to translate the source code. Here in this article, we have given a brief description of Compiler translator.

What is Compiler?

A compiler is a program which is usually known as a translator and it is used to turn the 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 machine and computer do not have a direct approach to these kinds of languages. For that, we use a translator so the machine could understand how that particular code should be executed.

How does a compiler work?

A compiler read source code line by line, at once and show appropriate error after reading the code, and it works on 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

Lexical analysis: This phase of compiler scans the code and divide the code into groups of tokens.

Syntax analysis: This phase of compiler checks the syntax of the program and assure whether the code is written according to the syntax or not.

Semantic Analysis: This phase of compiler checks the meaning of the program, it checks whether the program code following a meaningful approach or not.

Intermediate Code Generation: This phase of compiler commences with the generation of Intermediate code; this intermediate code is the middle language of high-level and machine language.

Code Optimization: This phase of compiler deal with the unwanted code written in the program and remove them. Code optimization creates a sequence of intermediate code so the execution of the code becomes easy.

Code Generation: This is the most important phase of the compiler which accepts the sequence of code form the optimization phase and converts it into object code.

Conclusion

The compiler just not convert the high-level code to the object code but also check its legitimacy. As the working of the compiler is divided into 6 phases, which state that it is a collection of subprograms. Programming language like C++, Java, C and Perl use the compiler as a translator.

People Also Read:

Leave a Reply

Your email address will not be published. Required fields are marked *