A compiler is a program that translates source code written in a high-level language such as Java, into machine-readable language called object code, target language, or even assembly language. A compiler could therefore be called a translator, but its tasks are broader because as part of compiling the program, it also reports errors when reading the code.
A compiler always works completely through an entire document. In this way, its function differs from an interpreter. Before a compiler can translate higher-level source code into machine-readable target language, the source code must be scanned and program characters have to be extracted. Parsing is done after this lexical analysis. The syntactic correctness of the code is checked. Subsequently, the semantics of the code is determined to create the target code at the end. The compiler tries to optimize or hide errors in the code. Usually, all steps are executed within a few seconds.
It is important that the compiler continues to work despite errors in the code. Otherwise, the source code cannot be translated into machine-readable target languages.
Using compilers, you can ultimately execute programs that have been designed in various common programming languages such as C or Pascal, since the compiler translates the source code of a text file so that a machine can read and use it. The advantages of compiler programs are that they are very fast because no errors have to be corrected during execution.