By now, we have come to know that a computer,
or a Central Processing Unit does not
understand programs written in any high-level language.
A computer processor can understand a program
when it is written in machine-friendly binary format
consisting of 0s
and 1s only.
This binary format is known as the
Machine language or machine code,
which is the lowest level of computer languages.
So, we need some type of translator inbetween high level language
and machine code that can understand what is
written in high level language, and can convert it into machine code.
A compiler translates a program written in high-level language
into Machine language (machine code).
It itself is a special computer program that understands both the
high-level language and the machine language.
Once a program is written in any high level language, the programmer
raises a compilation request. Then the compiler scans the whole source program and analyses
the instructions in depth.
If there are errors, details like error-line-no., error-type etc. are
reported to the programmer for rectification. The actual compilation
does not happen until the source program becomes completely error-free.
When the source program becomes completely error-free,
compilation process is initiated. An executable file, containing machine codes, is created,
and executed for the desired output.
This executable program can be executed whenever it is required.
This whole process is known as compilation.
An interpreter does the similar job, but in a different way. It is a program which reads and analyses an instruction from a high-level program, translates it into machine code, and immediately executes the instruction. Then it repeats with the next instruction.
This translate-and-execute process continues until the end of the program reached.
When an error is found, interpretation stops immediately, and error-details
is reported to the programmer for rectification and re-interpretation.
An assembler functions almost like a compiler, where assembly language is the source code. It translates a program written in assembly language into machine language. The symbolic instructions of an assembly language program is converted into executable codes for execution by the CPU. An assembler is the compiler of assembly language.
In a nutshell, compilers, interpreters and assemblers are basically translators. They all ultimately translate human-readable codes into machine language, but they do it in different ways.
--- x ---
Want to leave a message for me?