TRANSLATORS
Computers are electronic devices that can only understand machine-level binary code (0/1 or on/off), and it is extremely difficult to understand and write a program in machine language, so developers use human-readable high level and assembly instructions. To bridge that gap, a translator is used, which converts high-level instructions to machine-level instructions (0 and 1). The translator is a programming language processor that converts a high-level or assembly language program to machine-understandable low-level machine language without sacrificing the code's functionality. The computer only understands machine code. It is unable to understand any low, assembly, or high-level language. There must be a program to convert the source code into object code so that your computer can understand it. This is the job of the language translator. The programmer creates source code and then converts it to machine-readable format (object code)
The main purpose of the translator is to make the machine understand the program written in a low/assembly/high-level language.
There are 3 types of computer language translators: They are:
- Compiler
- Interpreter
- Assembler
COMPILER
The compiler is a language translator program that converts code written in a human-readable language, such as high-level language, to a low-level computer language, such as assembly language, machine code, or object code, and then produces 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 a 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 errors and reports. Common languages which are using compiler are C , C++ , C# etc.
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 more secure than Interpreted Code. Code once compiled and when you view the compiled code then you will not be able to understand it.
Compiled Code is faster because compiled code is near to machine code.
The program can run directly from object code and doesn't need source code.
The compiler translates commands into machine language binaries, no other program or application is needed to be installed to execute the executable file of sources codes. The only thing needed is that each software has to be compiled for certain operating systems. If an application is compiled for a particular OS architecture, the user simply needs to OS that operates on the same OS architecture.
Disadvantage of Compiler
For the executable file to be created, the source code must be error-free.
For a large application, it may take a larger time to compile the code as compared to small programs.
When you compiled an application then it creates a new compiled file which takes
INTERPRETER
The interpreter converts high-level language to machine-level language, while the compiler accomplishes the same but in a different method. The Interpreter's source code is transformed into machine code at run time. The compiler, however, converts the code to machine code, i.e. an executable file, before the program starts. 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 is finished.
Some of the popular interpreted languages are Php, Python, Javascript, Ruby
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.
Advantage of Interpreter
Some of the main advantages of interpreters are as follows:
Because interpreted code is not machine-dependent, so interpreted code can operate on any system and be shared between platforms without incompatibility issues.
The interpreter does not compile the code like a compiler, allowing you to publish the work to a live environment more quickly.
An interpreter does not create additional new files like a compiler, which saves memory and space.
Disadvantage of Interpreter
Some of the main disadvantages of Interpreter are as follows:
Interpreter is slower
As interpreted codes can easily be read by humans so we can say data and code are insecure.
To run the code, a client or anybody else who has access to the shared source code must have an interpreter installed on their system.
ASSEMBLER
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, 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.
Comments
Post a Comment