A compiler it allows the translation of a source code of a program in a high level language to one of a lower language (machine language) for its interpretation.
It may interest you: PROGRAMMING LANGUAGES | Types, characteristics and application
What is a compiler and what is it for?
A compiler It is a computer program that is responsible for translating a program that has been written in a programming language to be understandable in another language of interpretation, in order to generate an equivalent program that a machine will be able to interpret.
It is emphasized that this second language that passes through the compiler It is almost always machine language, although it can also be of intermediate code or text directly. The translation compress is what is known as compilation.
A compiler serves so that when developing a program the process is carried out in a language very similar to the thought of a human, but that when compiled becomes a more understandable language for a computer.
How does a compiler work?
The procedure that translates from a high-level programming language to machine language goes through several phases or stages where logical operations are applied. You can think about these phases of how a compiler works as separate pieces of the translator, but that are integrated together.
Analysis phase of a compiler
It is the first phase of the operation of a compiler that, due to its characteristics, three great procedures can be identified:
- Lexical Analysis Moment in which the source program is read from the left to the right to be grouped into lexical components, forming character sequences with a meaning. Also unnecessary information such as blanks or blank lines are removed from the source code. Language symbols are checked.
- Synthetic analysis The lexical components or characters are grouped hierarchically in grammatical phrases that the compiler will use to synthesize an output. It is also checked if what was obtained from the previous step is correct synthetically.
- Semantic analysis It is a procedure where the source program is reviewed to identify possible semantic errors and also gather information on the types used for the post-code generation phase. A hierarchy structure is used that is determined by the phase of synthetic analysis for the identification of operators and operands of propositions and expressions.
Synthesis phase of a compiler
It is the second phase of a compiler where the object code that acts as the equivalent of the source program is generated. It only happens if it is free of analysis errors.
Intermediate code generation
In some cases, compilers will generate an explicit intermediate representation of the source code. Its most relevant properties are: easy to produce and easy to translate the program into an object. On certain occasions the three-way code which is a kind of machine assembly language where each position of memory It can act as a record. Its properties are:
- First Each instruction will have at most one operator, while including the assignment, so that the instructions are generated in account, the translator must decide the order in which they are carried out.
- Second The translator generates a temporary name to store the values calculated by instruction.
- Third Some instructions of the three directions They will have less than three operations, such as the assignment.
Code optimization phase
Is a compiler phase where the intermediate code of the previous step is improved, so that it is a machine code of much easier interpretation. It is possible more than anything if the translator is a compiler.
There is a lot of variation in the way a code is optimized depending on the different compilers. In certain cases there are some that are called optimizing compilers because much of the time they focus on this procedure, but it is not always necessary to do so.
What is an optimizer compiler?
Is a compiler which has been developed to minimize certain attributes of a computer program so as to increase its performance and efficiency. These optimizations of a compiler are applied in most cases through a transformation of optimization, algorithms to produce the same with another equivalent, but optimized, semantic output.
What optimizes an optimizer compiler?
There are several aspects that focus on compiler with these characteristics, but in this regard can be highlighted:
- Temporary optimization Reduction of the execution time of a program.
- Spatial optimization Reduce the amount of memory space that a running program will occupy.
- Size The size of the program is reduced so that it occupies as little as possible.
- Power It works to minimize the power consumed by a program, more than anything for laptops.
You can continue reading:
SOFTWARE | What is it, types of Software, 15 examples and features
APPLICATION SOFTWARE | What is it, examples and characteristics
PYTHON (computer science) | What it is, what it is for and features