1.5 Program Translation
A program written in a high-level language can not be executed directly by the processor. The program source code must first be translated into machine code or executed indirectly by another program. There are a variety of ways in which this translation can occur, which we explore below.
Compilation
High-level programming languages can be divided into two types, compiled and interpreted. A compiled language is one in which the source code must be converted or translated into the machine of the processor on which it will be executed. This process is illustrated in Figure 1.5.1. Examples of compiled languages include C, C++, and PHP. The compiled languages that translate directly to machine code are among the oldest high-level languages.
A program written in a high-level language is called a source program. The file that contains the high-level instructions is a simple text file called a source file, which becomes the input of the compiler program. The compiler verifies the instructions adhere to the syntax of the language and produces machine code specific to a given processor. If the syntax is violated, the source program can not be translated into an executable program. Instead, the compiler will report the violations as syntax errors.

A software application that translates high-level language instructions into machine code. This process is known as compiling.
The machine code produced by the compiler is not sufficient to actually run the program. There are many low-level operations that must be performed in most programs, such as printing to the screen or reading from the keyboard or a file. The language itself does not provide these operations. Instead, the language designers provide a language specific library that implements a large number of common and useful operations. A library is a collection of operations written and translated by someone else that is ready for use in your program. In our case, it's the standard C library. Large and complicated programs may require multiple libraries.
A second program called the linker takes the machine code produced by the compiler from your source file and pulls in the necessary components from the library to build an executable file which contains an executable program. Once produced, the executable program can be executed directly by the processor just like any other executable program on that computer.
Interpretation
An interpreted language is one in which the source code is translated and executed by another program called an interpreter instead of directly by the processor. Interpreted languages are commonly used by a variety of applications for performing user-specified tasks or extending the capabilities of the application. Examples of interpreted languages include Javascript, bash, Basic, and lisp. This process is illustrated in Figure 1.5.2.
An interpreter, which is executed by the processor, reads the high-level source code from the source file in small parts or as single statements. As each statement or groups of statements are read and translated, they are immediately executed by the interpreter. The next statement or groups of statement are then read, translated, and executed. This process is repeated until the program terminates. The statements in an interpreted language must be translated each time the program is executed.
Virtual Machine
Languages that are compiled directly into machine code produce programs that execute at the speed of the processor. The translation or compilation only occurs once, allowing the program to be executed directly by the processor anytime it's needed. The disadvantage of these languages, however, is that if changes are needed in the program, it must be recompiled before it can be re-executed. In addition, you would need access to the source code in order to make any such modifications. For commercial software, you can only use what has already been compiled.
Interpreted languages produce programs that execute much slower than since they are translated and executed "on the fly" by another executable program. The advantage of interpreted languages is that they can be easily modified when needed without having to be recompiled. Interpreted languages are typically used for writing simple scripts and for specifying user-defined operations within other applications such as spreadsheets and browsers.
Some languages use a combined approach to take advantage of a compiler to translate the source code once while producing programs that are more portable across different types of processors. In this approach, both a compiler and a special type of interpreter are used. As illustrated in Figure 1.5.3, a compiler is used to translate the source code to byte code, which is similar to machine code, but designed and created for a virtual processor (or virtual machine) that executes on top of a the real processor. In this case, the virtual processor acts like an interpreter which executes the byte code instructions. Examples of these hybrid type languages include Java, Python, and C#. Languages that use this combined approach are considered compiled languages.
- compiled
- interpreted
- compiled with a virtual machine
- all of the above

