Language processor or translator is a type of system software that translates a source program (other than machine language) into an object program (Machine language).
What is Source Code/Program?
When we write code using a High-Level Language (i.e., C, C++), that code is known as source code.
//Example of Source Code (C++) #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
So, in simple words, source code is a piece of code written in English-like languages (High-Level languages) like C++, Java, Python, and more.
What is Object Code/Program?
When our written code (i.e., the source code) is translated to the machine language, then that translated code is known as object code or program.
1001000 0111111 000000 000000 000000 000000 000000 000000 0010000 0100000 0100011 0110000 0100000 0100101 0111110 0100010 0010000 0100011 0110100 0110101 0111010 0110111 0110111 0111001 0010000 0100011 0110111 0110111 0111001 0111010 0110111 0010110
The above code is a machine-readable representation of a simple “Hello, World!” program in C++. The code prints “Hello, World!” to the console. The first line is a header containing binary instructions telling the computer what type of file it is and what instructions to interpret it. The remaining lines are instructions that tell the computer to print the text “Hello, World!” to the console.
Why Use Language Processor?
The machine only understands binary language (i.e., 0s and 1s). How will the compiler understand the code when we write code in English-like languages?
The answer is simple “Language Processor.”
The language processor translates the high-level source code to low-level object code.
For example:
You only understand the English language; when a person comes to you and starts speaking to you in Chinese, will you understand?
Of course NO! Because you don’t know Chinese. You need a third person who will translate Chinese for you.
In the same way, the machine only understands the binary language. If we write code in a high-level language (English-like Languages), the machine will not understand unless translated.
So, a language processor simply translates the high-level language to a low-level language.
Now! I hope you’ve understood what a Language Processor is.
Types of Language Processor:
There are three types of language processors that we will address in this article.
#1. Assembler:
An assembler is a translator used to translate an assembly language program into a machine language program for later execution.
In assembly language, Mnemonics were used. Mnemonics means symbolic code, and that’s why we know Assembly language by Assembly language.
#2. Interpreter:
An interpreter is a language processor that converts a high-level language program line by line (statement by statement) and executes the prescribed actions in the sequence.
It converts one program statement into machine language, executes it, and then proceeds to the following statement.
BASIC, LISP, Smalltalk, PHP, and PERL are examples of interpreter-based languages.
#3. Compiler:
A compiler is a language processor that converts source code (written by a programmer in a high-level language such as Java) into machine-language instructions that the machine can understand.
A compiler is an extensive language processor with error-checking and other abilities. Examples of languages that use compilers include COBOL, FORTRAN, C/C++, JAVA, and more.
Difference Between Compiler & Interpreter
Compiler | Interpreter |
---|---|
A compiler is a program that takes a single unit of complete source code and translates it into machine code that a CPU can execute. | The interpreter takes a source program then translates and executes it one by one. |
The compiler takes a long time to evaluate the source code; however, the program's total execution time is much faster. | An interpreter takes less time to evaluate the source code; however, the program's overall execution time is longer. |
Each time you need to execute the program, you'll need a translator program to translate the source code. | When you want to execute the program, a translator is not required to translate the source code. |
Because the compiler only generates the error message after scanning the entire program, debugging is more difficult because the problem might occur anywhere in the program. | It makes debugging easy since it keeps translating the program until the fault is encountered. |
For the compiler to generate object codes, it needs a lot of memory. | Because no object code is created, it uses less memory than a compiler. |
It is more beneficial for business purposes since it saves object code. | It does not include object code and is thus better for learning. |
Examples are C/C++, JAVA, and more. | Examples are BASIC, LISP, Smalltalk, PHP, and PERL. |