What is a Compiler? In Computer, the compiler is defined as the computer program that easily converts source code of source language into another required computer language. The conversion of the source language is possible with the help of the compiler.
The various elements of Compiler are source code, lexical analyzer, tokenized code, syntactic analyzer, parsed code, semantic analyzer, qualified code, code generator, object code, optimizer, final code, etc.
There are generally five stages of a compiler to convert any source language into another low level desired language.
In the first stage, the lexical analyzer plays an important role in the conversion. Here, the source code is analyzed by the lexical analyzer to convert it into the tokenized code. The main function of lexical analyzer is to generate or create tokens. In this stage, the source code is formatted for easy access to get required tokens.
In the second stage, the syntactic analyzer plays an important role in further conversion. Here, the tokenized code is converted into parsed code. The main function of the syntactic analyzer is to analyze the tokenized codes for structure and further processing.
In the third stage, the semantic analyzer plays an important role to convert the parsed code into the qualified code. Also, the main function of the semantic analyzer is to analyze the parsed code for meaning.
In the fourth stage, the qualified code is linearized with the help of code generator to produce or generate object code. The main function of the code generator is to create equivalent object codes for further processing of codes.
In the intermediate code generator, the compiler converts some of the intermediate representation of available source code into a machine code that can be easily read and executed by the machine or computer.
In fifth or last stage, the optimizer plays an important role to create required final code. Here, the optimizer analyzes the object code produced by the code generator into the final code.
Code Optimization In Computer Program
What is code optimization? Why code optimization is needed? Why it is important? It is mainly used for the purpose of code modification. The code optimization modifies variously available codes to improve code quality and efficiency so that there should be very less error.The code optimization is also used to convert large size codes into the smaller one. Due to code size conversion, the particular code consumes less memory compared to other untouched codes. The largely sized codes consume larger space memory. Due to code optimization, certain space or block of memory is saved or consumed. Also, the optimized code performs just a few inputs and output operations as compared to the non-optimized codes. Another important property of optimized code is that it executes more faster and rapidly.
Interpreter In Computer Program:
It directly executes as compared to the compiler. It is quite different than compiler in the context of instructions written because, in the interpreter, the instructions are written directly in the scripting language.