Introduction
What do you understand by a translator? In layman's language, a translator translates one language into another language. But what do we have to do with this in computers?
Let me tell you about this, computers understand machine language, and we (users) understand high-level language called source code.
So a translator in compiler design translates this high-level language into machine code. The translator takes input as the source code (high-level language) and gives output as the machine code.
This article will help you understand the translators in compiler design and why there is a need for translators.

What is Translator?
A translator is a program that converts instructions written in source code to object code or from high-level to machine language.
Suppose you speak English and want to talk to a Japanese person. Then how will you communicate? You need someone to translate who is called a translator, who can speak English and Japanese both. So you both can communicate. The translator on a computer does the same job. It converts the source code into machine code, which the machine can understand.
Here are types of translators that will do the same in a computer and help to communicate from user to computer.
-
Compiler
-
Interpreter
-
Assembler
Now let us discuss each translator in depth one by one.
Compiler
The compiler is a translator that converts source code from high-level languages to machine code.
Compilers are much faster than interpreters, but error debugging is a little difficult process. Languages that use compilers are C++, C, and Java.
It works in three stages, explained below.

Stage 1: It takes the source code as input.
Stage 2: It checks the source code and validates it. If some error occurs(when the rule of the language is not followed), it will send an error message.
Stage 3: If no error occurs, it sends the machine code as output to the machine.
Interpreter
Interpreter changes the source code to machine code, but the process is a bit changed here than in compilers.
An Interpreter is a translator that effectively accepts a source program and executes it directly without producing any object code first. It does this by fetching the source program instructions one by one, analyzing them one by one, and then "executing" them one by one.
Here solving errors is very easy, but it increases the execution time. Languages in which interpreters are used: Python, Ruby, and BASIC.
The process of translating the source code to machine code using an interpreter is as follows:

Stage 1: It takes the source code as input.
Stage 2: It checks the source code line-by-line and validates it. If some error occurs(when the rule of the language is not followed), it will stop the code execution and send an error.
Stage 3: If no error occurs, it sends the machine code as output to the machine.
Now, in the article's next section, you'll learn about assemblers.
Assembler
Assembler is said to be the fastest translator among the three, as the assembler translates the low-level assembly code to machine code.
It translates by evaluating the symbols in the source code and generates the machine code accordingly. If an assembler does this in one scan, it is called a single-pass assembler; if it takes multiple scans, it is called a multi-pass assembler.
The process of translating the source code to machine code using assemblers is as follows:

Stage 1: It defines symbols of the assembly code.
Stage 2: It processes some pseudocode operations.
Stage 3: Generates object code.