COMPILERS
A compiler refers to a computer program that is used to translate a computer code that is written in one programming language (referred to as the source language) into another programming language (referred to as the target language). The term compiler is primarily applied for programs that translate source codes from a high level programming language to a lower level programming language. For example, machine code, object code or assembly language to create an executable program.
It is important to note there are many different types of compilers. In case the program that is compiled can run on a computer whose operating system or CPU is different from the one which the compiler runs, the compiler is referred to as a cross-compiler. A bootstrap compiler on the other hand is written in the language that it intends to compile. A decompiler is a program that is used to translate a low level language to a higher level language. A program that is used to translate between high level languages is referred to as a source-to-source compiler. It can also be referred to as a transpiler. A program that is responsible for translating the form of expressions without a language change is known as a language rewriter. The term compiler-compiler refers to those tools that are used to create parsers responsible for performing the syntax analysis.
Some of the operations that are performed by a compiler include: preprocessing, parsing, (syntax directed translation) semantic analysis, lexical analysis, code generation, code optimization and conversion of input programs into an intermediate representation. Compilers are responsible for implementing these operations in different phases that promote correct transformations and efficient design of source input to target output. Program faults that are caused by incorrect behavior of the compiler can be very difficult to track down and work around. Compiler implementers therefore invest significant efforts to ensure compiler correctness.
It is important to note that compilers are not the only translators that are used to transform source programs. A computer software that is responsible for transforming and then executing the indicated operations is referred to as an interpreter. The process of translation influences the computer languages design which leads to a preference of interpretation or compilation. In practice, the implementation of an interpreter for compilers and compiled languages can be implemented for interpreted languages.
Note that when using a compiler, a two-step process is used to run a program,
THE COMPILATION TOOL CHAIN
For programs that are large, the compiler is part of a multi step tool chain,
(preprocessor)- (compiler)- (assembler)- (linker)- (loader).
STRUCTURE OF A COMPILER
Modern compilers are made up of two major parts. Each of these parts is often subdivided. These two major parts are the front end and the back end.
The front end is responsible for analyzing the source program, constructs an intermediate representation of the program and determines its constituent parts. Generally, the front end is independent of the target language.
The back end on the other hand is responsible for synthesizing the target program from the intermediate representation that is produced by the front end. Generally, the back end is said to be independent of the source language.