How are Compiler and Interpreter different?

Firstly let's know what is HIGH-LEVEL LANGUAGE and LOW-LEVEL LANGUAGE.

In basic terms, High-Level Language is in human understandable form and Low-Level Language is in machine-understandable form.

Compiler and Interpreter, both are a type of translators which are used to translate our program written in a high-level language into low-level language.

compiler:-

The compiler takes high-level langauge as input and produces an output which is in machine-understandable form(binary numbers like 0 and 1).

  • It lists all the errors if the input code does follow the rules of its language.

  • The compiler is a translating program.

  • There are different types of Compilers available: cross compiler,bootstrap compiler, transcompiler, and decompiler.

  • The compiler can translate those input codes for which the language compiler is meant for.

    • c-Turbo C, GCC, Tiny C compiler.

    • c++-GCC,intel c++,Code Block

    • Java-IntelliJ IDEA,Eclipse IDE,NetBeans,BlueJ

    • Python-Spyder, JPython, CPython

    • JavaScript-Visual Studio Code, Atom IDE, Komodo edit

Characteristics of the compiler:

  1. It generates an intermediate object code.

  2. c,c++,c#, etc are the programming languages that use compilers.

  3. compiler scans the whole program at once.

  4. Faster when compared to the interpreter.

  5. Before execution of any program, program is compiled first to ensure no errors are present in input file.

Interpreter

The interpreter is a translator which is also used to convert the code written in high-level language into machine language. But it translates only a single statement of the program at a time. It interprets code line by line.

  • Less time to analyze the code but the total time for translation is higher when compared to the compiler.

  • It can work in three ways:

  • 1. Execute the source code directly and produce the output.

  • 2. Translate the source code into some intermediate code and then execute this code.

  • 3. Use an internal compiler to produce a precompiled code. Then, execute this precompiled code.

  • types of interpreter are: Bytecode interpreter,Threaded Code interpreter, Abstract Syntax Tree Interpreter, Self Interpreters,

  • languages that use interpreters are python, ruby,etc.

Therefore,main advantage of using compiler is its execution time which is less than interpreter and advantage of using interpreter is its translation of line of program.This keeps translating input program line by line,when there are any error spotted,it stops working,hence debugging becomes easier.