Translator
Source code refers to a program written in a high-level language. Translators are required to transform the source code to machine code. A translator takes a source language program as input and translates it into a target language program as output.
In simple words, a translator is a programming language processor that transforms a computer program from one language to another. It discovers and identifies the error during translation.
The roles of a translator are
- Translating the high-level language program input into an equivalent machine language program.
- Providing diagnostic messages wherever the programmer violates the specification of the high-level language program.
Different types of translators
The different types of translators are as follows:
- Interpreter
- Compiler
- Assembler
What is an Interpreter?
An interpreter is a translator which converts high-level language programs to low-level language programs. The interpreter translates line by line and notifies any errors that occur throughout the translation process.
When the user provides input, it directly executes the operations defined in the source program.
It provides more accurate error diagnoses than a compiler.
Some Examples of Interpreters:
- OCaml
- List Processing (LISP)
- Python
What is Compiler?
A compiler is a translator that converts programs written in high-level languages to low-level languages. It translates the complete program and indicates any problems found in the source program throughout the translation.
Types of Compiler
Following are the different types of Compiler:
- Single Pass Compiler
- Two-Pass Compiler
- Multipass Compiler
- Incremental Compiler
- Cross Compiler
- Source to source compiler
- Load & Go Compiler
- Threaded Code Compiler
- Stage Compiler
- Just-in-time (JIT) Compiler
- Parallelizing Compiler
Some Example of Compiler:
- Microsoft Visual Studio
- GNU Compiler Collection (GCC)
- Common Business Oriented Language (COBOL)
Assembler
A translator that converts assembly language to machine language is known as an assembler. It’s similar to an assembly language compiler, but it’s more interactive, like an interpreter. Because assembly is a low-level programming language, it is difficult to grasp. An assembler converts a low-level language called assembly into a lower-level language known as machine code. The CPU can understand the machine code directly.
Some Examples of Assembler:
- Fortran Assembly Program (FAP)
- Macro Assembly Program (MAP)
- Symbolic Optimal Assembly Program (SOAP)
Differences between compiler and interpreter
Compiler | Interpreter |
---|---|
Translates a whole program. | Translates statements one by one. |
Execution is faster. | Execution is slower. |
Generates Object Code which further requires linking, hence requires more memory. | No Object Code is generated, hence is memory efficient. |
Debugging is difficult since error warnings are only generated after the entire program has been scanned. | When the first error is encountered, the translation is terminated. As a result, debugging is simple. |
C, C++, C#, Scala, Java all use compilers. | JavaScript, Python, PHP, Perl, Ruby uses an interpreter. |