Aller au contenu

Introduction: compilation

What is compilation? Compilation is translation from a high-level computer language (meant to be read by a human being) to a low-level language (instructions meant to be read and executed efficiently by a machine). The low-level language can be called machine-language, it is specific to the target processor. So, a priori, you cannot use on machine B the result of compilation on machine A. During compilation, errors, if any, in the grammar of the high-level language are signaled.

The compiler is the piece of software that does the compilation.

There are interpreted languages and there are compiled languages. Fortran, C and C++ are examples of compiled languages. Python and Bash are examples of interpreted languages.

Interpreted languages versus compiled languages

For an interpreted language, the language interpreter is in charge of execution of (aka running) the program. Each line of the program is directly run by the interpreter.

For a compiled language, compilation precedes execution of the program. The file which contains the text of the program in the compiled language (Fortran, C++ …) is called the source file. Compilation creates a new file (not readable by a human), called the executable file. The executable file is the file that you run. The operating system is in charge of the run, it no longer needs the compiler. In general, the relation between the lines of source code and the content of the executable file is lost, or complex, so you cannot execute the program line by line as simply as you would with an interpreted language (but it is possible with some compiling options and a debugger).

The compiler accomplishes a complex task, but it does it only once, producing an executable file that will work with any data. The interpreter accomplishes a simpler task, but has to do it again for each run with new data.

A program written in a compiled language produces an executable file which, in principle, should run faster than the equivalent program written in an interpreted language.

If you want to know more about compilation:

  • Langages de programmation et compilation, Jean-Christophe Filliâtre. https://www.lri.fr/~filliatr/ens/compil

  • Aho et al. Compilers: Principles, Techniques, and Tools, 2nd edition, Addison-Wesley, 2006