You are on page 1of 7

‫وزارة التعليم العالي والبحث العلمي‬

‫جامعة واسط‬
‫كلية علوم الحاسوب وتكنولوجيا‬
‫المعلومات‬
‫علوم البرمجيات‬

‫تقرير بعنوان‬
‫‪Compiler‬‬

‫مقدم من الطالب‬
‫حيدر عبد الرضا عبد الحسين‬
‫المرحلة‬
‫األولى مسائي‬

‫بأشراف‬

‫م‪.‬م ثائر فرج علي‬


COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

introduction:

When we look at any script from one of the famous programming


languages, we will notice that it is written using strange words
and symbols that are familiar to us, as they are at least in English
letters and include some expressions and terms that are common
in our daily lives. Unfortunately, presenting the same program to
the processor will not lead to any similar result: the letters,
symbols, and expressions written in English are things that are
impossible for the processor to understand directly, as he
understands only one language: the binary language composed of
strings of zeros and ones.

In this way, in order for the programs that we write to be


understandable to the processor, we will need someone to
explain them to him and explain exactly what we want from him.
The program, in the end, is nothing but a set of instructions that
we want the processor to implement. In the world of
programming languages, the term “compiler” appears to refer to
the middleware that undertakes the task of making scripts written
in a high-level programming language understandable to the processor.

1
COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

What is a compiler?

A compiler is a program that converts source code written in a


high-level programming language into a low-level representation
while preserving the meaning and intent of the source code. The
term “source code” is used to refer to code written in a high-level
language, while the term “target code” is used to refer to the
code produced by the compiler, which is usually in a low-level
language. In addition, the compiler performs optimizations on the
source code to make it more efficient in terms of execution speed
and the amount of memory that the program will occupy. The
compiler can be represented simply using the following diagram:

2
COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

Types of compilers
Compilers can be divided into three types in terms of how they
perform their task and generate the target code:
1- Single-Pass Compiler: With this type of compiler, high-level
source code is translated directly into low-level code
without any intermediate stages.
2- Two-Pass Compiler: With this type of compiler,
intermediate source code is generated so that the work of
the compiler as a whole is understood as two parts: the
front-end and the back-end. The function of the proximal
section is to convert the source code to the intermediate
representation and perform text and vocabulary analysis
operations in addition to optimization operations, and then
the back-end section converts the intermediate source code
to the low-level target code.

3- Multiphases Compiler: Instead of dividing the translation


process into only two parts, there are compilers that divide
the translation process into several parts, each of which
produces intermediate source code, and the output of each
stage represents the input of the next stage. The end result
is low-level source code.

Language Processing System


Before going into the details of the work of the compiler itself and
the operations it performs on the source code, an important thing
must be made clear: the compiler itself is a larger part of an
integrated system through which instructions written in machine
language are generated and which the processor can understand.
3
COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

The output of the compiler is not directly executable by the


processor, and the compiler depends on other stages before it to
be able to perform its task in the best possible way.
The term “Language Processing System” is used to refer to the
various stages through which high-level script is converted into
machine language. This system consists of the following
components and stages:
Source Code: It represents the program written in a high-level
programming language and required to be executed by the
processor.
Pre-Processing stage: This stage is considered part of the
translation process itself, where a new representation of the high-
level source code is generated that is used by the translator. The
primary goal of this stage is to define pre-programming directives,
definitions, and embedded libraries.
Interpreter: An interpreter is a program similar to a compiler in
that it converts the source code to a low-level representation, but
the main difference is that the interpreter reads the source code
and executes it one instruction at a time, while the compiler
analyzes the entire code and then generates the low-level code.
Some languages rely on an interpreter as a way to implement
programs rather than a compiler.

4
COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

Assembler: The assembler takes the output of the compiler and


converts it into instructions written in machine language. The
result of the interpreter's work is what is called an “object-file,”
which includes the executable instructions in addition to the data
necessary to store these instructions in memory. The output of
the assembler's work is also defined as "Relocatable Machine
Code", meaning that running the program itself (here we mean its
executable instructions written in machine language) does not
need to be placed at specific addresses in RAM, and the
executable files are in RAM. exe. A famous example of portable
machine instructions.
Linker: Within this stage, the various object files resulting from
the work of the assembler are linked and collected in order to
generate the executable file. The linker searches for the call units
included in the program and determines the memory locations
that contain these units.

Loader: The loader is one of the parts of the operating system and
its function is to download the executable file resulting from the
link, place it in memory, and then run it.

5
COMPILER ‫ مسائي‬/ ‫المرحلة األولى‬ ‫ حيدر عبد الرضا عبد الحسين‬/ ‫اعداد الطالب‬

Compiler Phases
As we found, the compiler itself represents a step in the
processing steps needed to transform the script from its high-
level form into machine language instructions executable by the
processor, but this does not mean that the compiler itself is an
independent stage in itself, but rather it also consists of a set of
steps In general, the translator's work can be divided into two
basic parts:
Analysis Phase / Front-End
Synthesis Phase / Back-End

The terms “front-end” and “back-end” are used as a way to


indicate the nature of the code that is being dealt with. In the
analysis phase (i.e. the near end), the high-level language code is
subjected to a set of steps that process it according to its form.
The original, that is, it is still “close” to the form that the
programmer understands, while the synthesis stage (i.e., the far
end) deals with the script after converting it to a form that is
closer to the machine and more “distant” from the form that the
programmer understands.

You might also like