Difference Between Compiler and Interpreter - Computer Information Technology - CIT
Computer Information Technology - (CIT).

Friday, 8 March 2019

Difference Between Compiler and Interpreter

Difference Between Compiler and Interpreter
A compiler is a translator which transforms source language (high-level language) into object language (machine language). In contrast with a compiler, an interpreter is a program which imitates the execution of programs written in a source language. Another difference between Compiler and interpreter is that Compiler converts the whole program in one go on the other hand Interpreter converts the program by taking a single line at a time.
Evidently, the permeability of humans and an electronic device like a computer is different. Humans can understand anything through the natural languages, but a computer doesn’t. The computer needs a translator to convert the languages written in the human readable form to the computer readable form.
Compiler and interpreter are the types of language translator. What is Language translator? This question might be arising in your mind.
A language translator is a software which translates the programs from a source language that are in human readable form into an equivalent program in an object language. The source language is generally a high-level programming language, and the object language is typically the machine language of an actual computer.
Definition of Compiler:
A compiler is a program that reads a program written in the high-level language and converts it into the machine or low-level language and reports the errors present in the program. It converts the entire source code in one go or could take multiple passes to do so, but at last, the user gets the compiled code which is ready to execute.

Compiler operates on phases; various stages can be grouped into two parts that are:
  •  Analysis Phase of the compiler is also referred to as the front end in which program is divided into fundamental constituent parts and checks grammar, semantic and syntax of the code after which intermediate code is generated. Analysis phase includes lexical analyzer, semantic analyzer and syntax analyzer.
  • Synthesis phase of the compiler is also known as the back end in which intermediate code is optimized, and target code is generated. Synthesis phase includes code optimizer and code generator.

PHASES OF COMPILER:
Now let’s understand the working of each stage in detail.
1.   Lexical Analyzer: It scans the code as a stream of characters, groups the sequence of characters into lexers and outputs a sequence of tokens with reference to the programming language.
2.   Syntax Analyzer: In this phase, the tokens that are generated in the previous stage are checked against the grammar of programming language, whether the expressions are syntactically correct or not. It makes parse trees for doing so.
3.   Semantic Analyzer: It verifies whether the expressions and statements generated in the previous phase follow the rule of programming language or not and it creates annotated parse trees.
4.   Intermediate code generator: It generates equivalent intermediate code of the source code. There are many representations of intermediate code, but TAC (Three Address Code) is the used most widely.
5.   Code Optimizer: It improves time and space requirement of the program. For doing so, it eliminates the redundant code present in the program.
6.   Code generator: This is the final phase of the compiler in which target code for a particular machine is generated. It performs operations like memory management, Register assignment, and machine specific optimization.

The symbol table is somewhat a data structure which manages the identifiers along with the relevant type of data it is storing. Error Handler detect, report, correct the errors encountering in between the different phases of a compiler.
Definition of Interpreter:

The interpreter is an alternative for implementing a programming language and does the same work as a compiler. Interpreter performs lexingparsing and type checking similar to a compiler. But interpreter processes syntax tree directly to access expressions and execute statement rather than generating code from the syntax tree.
An interpreter may require processing same syntax tree more than once that is the reason why interpretation is comparatively slower than executing the compiled program.
Compilation and interpretation probably combined to implement a programming language. In which a compiler generates intermediate-level code then the code is interpreted rather than compiled to machine code.
Employing an interpreter is advantageous during program development, where the most important part is to be able to test a program modification rapidly rather than run the program efficiently.

1 comment:

  1. Thanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.
    JCATS
    VBS

    ReplyDelete

Post Top Ad