Table of Contents
- Computer Language Translator
- Why Computer Language Translator?
- Purpose of Computer Language Translator
- Types of Computer Language Translator
- Different Between Compiler, Interpreter, and Assembler
Computer Language Translator
Computer are electronic devices can only understand machine level binary code(0/1 or on/off) and it is very difficult to understand and write a program in machine language so, developers use human-understandable high level and assembly instructions. So, to solve this gap, a translator is used which is used to convert high-level instructions to machine-level instruction (0 and 1).
The translator is a programming language processor that translates a program written in high-level or assembly language program to machine-understandable low-level machine language without losing the functionality of the code.
Why Computer Language Translator?
The computer understands only machine code. It does not understand any low, assembly, and high-level language. There must be a program to convert the source into object code to make it understood by your computer. This is the task of the language translator. The programmer writes and then converts the source code into a readable machine format (object code)
Purpose of Computer Language Translator
The main purpose of the translator is to make the machine understand the program written in a low/assembly/high level language.
Types of Computer Language Translator
There are 3 types of computer language translators: They are:
The compiler is the language translator program that translates code written in a human-readable language like high-level language to low-level computer language either assembly language, machine code, or object code, and finally creates an executable program.
In the process of creating an executable file, the compiler goes into various phases like Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Representation(IR) Generation,(Intermediate Representation)IR Optimization, Code Generation, and Optimization.
In the process of compiling, the first code is sent to lexer which will scan the source code and split it into tokens and kept inside of computer memory, and send them to the parser where patterns are recognized and are converted into an AST (abstract syntax tree) which describes the data structure of the program representing then optimizer(if required) optimize away unused variable, unreachable code, roll back if possible, etc, then code generator converts to machine instruction code specific to the target platform and linker putting together all code into an executable program. Also, there is an error handler in all the phases which handles error and reports.
Some of the well-known compilers are: Borland Turbo C, Javac, GNU compiler, Microsoft Visual Studio, Xcode, Roslyn, etc
Some common compiled languages are C++, C
Characteristics of Compiler
- Source code is converted to machine code before runtime. So, code execution at runtime is faster.
- Takes a lot of time to analyze and process the program. The compiling process is complicated.
- But Program execution is Fast
- Cannot create an executable program when there is a compile type error in the program.
Advantage of Compiler
- The whole program is compiled and it seems to be secured than Interpreted Code
- Compiled Code is faster.
- The program can run directly from object code and doesn't need source code.
Disadvantage of Compiler
- For the executable file to be created, the source code must be error-free.
The interpreter converts high-level language into machine-level language, the compiler does the same things but its ways of converting are different from Compiler. In Interpreter, source code gets converted into machine code at run time. But in the compiler, code gets converted to machine code ie. an executable file before the program run.
The interpreter program executes directly line by line by running the source code. So, it takes the source code, one line at a time, and translates it and runs it by the processor, then moves to the next line, translates it and runs it, and repeats until the program finished.
Characteristics of Interpreter
- Spends less time converting to machine code.
- No compilation stage is present in the interpreter while generating machine instructions.
- Program execution is slower because it gets converted to machine code at runtime.
- Easy for debugging and finding errors.
Assembler converts code written in assembly language into machine-level code. Assembly language contains machine opcode mnemonics so that assemblers translate from mnemonics to direct instruction in 1:1 relation.
As we know the computer understands machine code only but programming is difficult for developers in machine language. So, low-level assembly language(ASM) is designed for a specific processor family that represents different symbolic code instructions.
Characteristics of Assembler
- As there is a 1:1 relationship exists between mnemonics to direct instruction so, translating is very fast.
- It requires less amount of memory and execution time.
- It does complex hardware-specific jobs in an easy way.
- It is ideal for a time-critical job.
Different Between Compiler, Interpreter, and Assembler
|It converts programs written in a high-level language into machine language before runtime||It converts programs written in a high-level language into machine language at runtime.||It converts the assembly language program into machine level language.|
|Used By: C, C++||Used By: Python, PHP, Ruby, PostScript, LISP, VB||Used By: GNU, GAS|
|Compiled code runs faster but compiling time may take a longer time.||For every time, the interpreter translates every time code is run so it is slower.||
Runs fast as the translating of two low-level languages depends on the processor instructions set only.
Compiler vs Interpreter
|Translate High-level language program into machine code before runtime||Translate High-level language program into machine code at runtime|
The compiler needs a lot of time for the whole source code to be analyzed
It takes less time for the source code to analyze
|The overall program execution time is relatively faster.||
Overall program execution time is relatively slower.
|The compiler only generates an error message only after scanning the whole program. And all the errors are shown at the same time.||
Interpreter only shows one error at a time and if solved and again after interpreting the code then shows the next error if exists.
|Debugging is relatively more difficult since there can be an error anywhere in the code.||
It is easier to debug since it continues to translate the program until the error is fixed. Show only one error at a time, and if solved then shows next error if exists.
|The compiler generates intermediate code.||
The interpreter does not generate intermediate code.
|The compiler compiles the code before execution.||
Compilation and execution take place simultaneously.
|Memory requirements are more because time is required for the creation of intermediate object code. This intermediate object code resides in memory.||
Requires less memory as it does not create intermediate object code.
|Difficult error detection and removal||
Easy for error detection and removal
|The programming language that uses Compiler: C, C++, Java,C#,Scala||
The programming language that uses Interpreter: Python, Perl,Ruby,PHP
|Compilers software are larger in size.||
The interpreter software is generally smaller in size.
|Focus on compile once, run anytime||
Focus on compile every time.
|The program doesn't run until all the error is fixed.||
A program runs the code and stops only when an error is found.
Frequently Asked Questions
Ans: Compiler has 3 important parts.
- Middle End
Ans: Some have distinct linkers and some do not. The linker is one of the important parts of the compiler which combines object code files and static file and produce an executable file.
8) What is Common Intermediate Language(CIL)?
Ans: All the application that is targeting .net framework is compiled first to Intermediate language called CIL, which is machine independent language and only at the run time those intermediate languages gets converted to native machine code.
The intermediate language in the Java environment is bytecode.
9) Is Java Compiled Language?
Ans: There are two steps in the Java compilation process. At first source code is converted to byte code by the compiler and at runtime that byte code is verified by byte verifier and it decides it may compile and/or interpret the bytecode using the Java Interpreter/JIT Compiler.(source:stackoverflow)
10) Is language translator a system software?
Ans: System Software is those types of software designed to provide a platform for other software. This software provides an environment for the operating and programming where the users interact for creating application software. This includes Operating System, Translator(Language Processor), Simulators, Emulators, Utility software, etc. So, translators like compilers, translators, and interpreters are all system software.