What is a Compiler?
Smartpedia: A compiler is a program that translates the source code written in a higher programming language into the machine-readable binary language – as executable code.
Compiler – the generation of machine-readable code
A computer’s program only consists of two different characters – the 0 and the 1 – therefore it is also called a binary program. A compiler is a program that translates the source code written in a higher programming language into the machine-readable binary language code. The result is “executable code”, also known as object code or target language. In some cases the translation is done by an intermediate step with an assembler language, so that afterwards an assembler is needed to generate the machine code.
Tasks of the Compiler
However, a compiler is more than just a “translator”, because other tasks arise in the course of compiling:
- The lexical analysis scans the source code and extracts program symbols. Superfluous and missing characters are detected as errors.
- This is followed by parsing with a syntactic analysis in which the grammar of the source code is checked.
- The subsequent semantic analysis checks whether the source code makes sense.
Finding program errors is therefore an essential task of the compiler. If a compiler finds an error, an error message with line number is returned, so that the navigation of the developer to the error becomes very easy.
Not all programming languages require a compiler. Java, for example, as an object-oriented programming language, is compiled into Java bytecode by the Java Just-in-Time compiler, a component of the Java development environment. Java byte code is a so-called hybrid language, i.e. a compromise between fully compiled binary code and interpretable source code. C#, VB.NET and Python are also hybrid languages. Typical programming languages with compilers are C, C++. Pascal, Modula, COBOL and Fortran.
In the course of translating programme code into machine-executable code, the term “interpreter” also frequently comes up. The difference between the two services lies in the execution: a compiler translates the entire programme code into machine language at once. This makes compilation slower, but the resulting code executes faster. In contrast, an interpreter translates the programme code line by line during execution. The interpreter reads each line of code and executes it immediately without creating a separate executable. This makes the interpretation faster but the execution of the programme slower.
Here you can find a German-language video: Compiler einfach erklaert.
Here you will find additional information from our Smartpedia section: