
Applications and websites are of course built using a series of codes. Of course you already know about this, right? The code can be turned into applications and web properly thanks to the compiler. Compilers are important tools used by developers.
Then, what is the definition of a compiler and how does it work? Check out the full explanation below.
Definition of Compilers
A compiler is a special program that is used to convert code into natural language processing so that computers can understand it. This ongoing conversion process is known as compilation .
In this process, the compiler is tasked with executing the code and converting it into the binary signals needed in the processor , especially in the arithmetic logic unit (ALU).
There are two types of compilers that are generally used by developers , namely:
- Source to source compiler or transcompiler is a compiler whose job is to translate source code in one language and convert it into code in another language.
- Cross compilers are used to create new code so that it can be used on other platforms .
It was mentioned above that the compiler is in charge of translating the code. But the compiler also has other tasks such as:
- Divide the program into separate sections and apply grammatical structures to each section.
- Use intermediaries to build target programs and create symbol tables.
- Compile the source code to find out the problems in it.
- Storage space management for all code and variables.
- Support for separate compilation.
- Read and analyze all programs, then translate them into semantic equivalents.
- Translate source code into object code and adapt it to the type of machine used.
Steps in the Language Processing System
Before discussing the compiler further, you should first understand how the hardware understands the code or programming language.
Programming languages are called high level programming languages (HLL). This language tends to be easier for humans to understand because the language is more familiar.
Unfortunately, HLL is incomprehensible to computers or machines. Therefore it is necessary to follow the steps below so that the machine can understand the code.
Pre-Processor
At this stage, the compiler removes all code containing the #include instruction and then adds the file inclusion. After that, #define was also replaced with a macro expansion. The result of this process is called assembly language. This language is in between HLL and binary.
Assembly language is an intermediary that can combine machine commands and some data that will be useful in the next process.
Assemblers
All hardware platforms have different assemblers . The function of the assembler is to convert assembly language code into machine language.
The files generated by the assembler are referred to as object files. The file is the result of a combination of machine instructions and the data needed to store commands or instructions in memory.
interpreter
The interpreter is useful for translating from HLL into machine language. But the interpreter is different from the compiler . The interpreter takes longer to translate the code because the process is done at one time.
Relocatable Machine Code
Relocatable machine code can be executed whenever needed. This process generates addresses in the program that will work together to run the program.
Loaders or Linkers
Linkers or loaders are useful for concatenating all object files into one executable file. The role of the linker is very important to bring together the files compiled by the assembler.
The linker's job is to find modules, call them into the program, and find locations to store all of these modules.
Phases - Phases in the Compiler
In the compiler there are two main phases, namely the analysis phase and the synthesis phase.
1. Analysis Phase
The analysis or representation phase, created as an intermediate from the following source code:
- Lexical analyzer to divide the program into tokens.
- Syntax analyzer is useful for recognizing sentences in programs using language syntax .
- The function of the semantic analyzer is to examine the static semantics of each construct.
- Intermediate code generator is useful for generating abstract codes.
2. Synthesis Phase
When entering the synthesis phase, target program of the same level is created from intermediate analysis which is divided into two phases.
- Code optimizer which functions to optimize the abstract code generated from the last process of the first phase.
- The code generator translates the intermediate code generator into more specific and ready-to-execute machine instructions.
Compilers Benefits
In addition to the main use of translating HLL into machine language in making applications or web, there are many other benefits that can be felt when using a compiler , including:
- The compiler verifies all programs so that semantic or syntax errors are unlikely to be found .
- Files can be executed faster because they have been optimized by the compiler .
- Allows creation of internal structures in memory.
- Programs do not have to run on the machine on which they were built.
- All programs can be changed to other languages.
- Files can be created on disk and made executable .
- Assists in addressing language performance issues.
In conclusion, understanding the compiler will really help you in application or web development . Compilers are also important tools used by developers in their daily lives. Once you get to know these tools well, you will develop various applications and web more efficiently. So are you ready to become a developer? let's continue to learn your skills to use this compiler tool !