Compiler, interpreter and virtural machine.

Computers, or more precisely the processor, or CPU, only understand "Machine Language". This is a set of instructions represented by ones and zeros, e.g.: "0011010111".

I recommend you read, the tutorials "Hexadecimal and binary numbers, byte, bit and word" and "What is a computer" before this one.

Machine language and assembler

Each CPU is designed to understand a low-level set of instructions. These instructions, use a limited number of records that are like "CPU variables", where most operations are performed.

Usually, data is moved from memory to registers, then operations are performed and the results are moved back to memory.

Low-level programming is complex, it has low productivity and often generates errors difficult to find.

To make programming easier, each machine instruction is given a name like "add", "mov", etc.. This is what is known as assembly language.

Compiler

The next major development was the creation of high-level programming languages. The idea was to use a more human friendly programming language. These languages ​​are more productive because they have more powerful and simple instructions, that equal a lot more machine instructions.

Once the program is written in a high-level language, a translator converts it into machine language. This translator is called compiler.

The set of machine instructions that are understood by different processors can be different. Programs also call different operating system routines depending on the system.

These differences have forced to create a specialized compiler for each type of machine and operating system, even though they use the same high-level language.

Cobol, C and C + + are the most representative high-level programming languages.

 

Compilador

Interpreter

A variation of the idea of the compiler is the interpreter. Instead of translating the program into machine code, the idea is to create a fictitious machine that understands high-level language. I call it fictitious machine, because it is not a machine, it is a program that executes or interprets high-level instructions.

We can think of the interpreter as a processor, which instead of executing machine instructions, executes high-level instructions.

Smalltalk and Javascript are the best examples of this type of languages.

Virtual machine

This is an intermediate concept, between the compiler and the interpreter, popularized by the Java programming language. The idea is to write programs in high-level language, but instead of compiling it (translating) into machine language, it translates it into an intermediate code. This intermediate code is executed by an interpreter known as Virtual Machine.

Java and C # are the best examples of this type of languages.

Máquina Virtual de Java

Advantages and disadvantages of compiled and interpreted languages

Compiled languages ​​are often considered a lower level than the interpreted languages. Usually, they run faster and consume fewer resources, but are criticized for their lack of compatibility. It is common to have to program different versions for different computers.

In contrast, interpreted languages ​​tend to be more powerful and flexible but are slower and consume more resources. Interpreted languages ​​tend to allow the use of a variable without a defined type, which is often seen as an increase in the power and productivity, but can have great cost producing errors difficult to detect.

Java, with its virtual machine, tries to take the best of both worlds. It has better efficiency than interpreted languages as well as being a ​​high productivity language. It also claims to be highly compatible; "write once, run anywhere".