What is a Compiler and what are its tasks?
Generating 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.
Do you know what a Yottabyte is?