Compiler Vs Transpiler

Compiler Vs Transpiler

Hi 👋everyone, in this blog I'm going to tell you about compiler and transpiler.

Compiler

The term compiler was coined by American computer scientist Grace Hopper, who designed one of the first compilers in the early 1950s.

What a compiler does?

Compiler takes source code written in one language and produces an output in binary language. In simple words we can say that it takes code written by user(High level language) and converts it in machine understandable code (low level language).

1_Qbm5_d5EYIbYa1-jN4JmSg.jpeg

In case of JavaScript the process of compilation is a little bit different:- JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.

Advantages of Compiler

  • We can create executable files and send them to other users. An executable file is a file that canot be modified but it can be run on any machine and displays the output.
  • Compiler optimise the code so that it can run quickly and takes less momory space.

2.jpg

Disadvantages of Compiler

  • Each and every time we change our program the compiler has to recompile the source code every time.
  • Source code compiled on one machine can not run on another machine as the machine code is specific to the processor's architecture.

Transpiler

What a transpiler does?

Transpiler also known as source-to-source compiler, is a tool that read source code written in one language and produces the equivalent code in another language with a similar level of abstraction.

Transpiler-Architecture.001.jpeg

Example of transpiler:-

  • Typescript transpiler which converts Typescript code to JavaScript.
  • Babel transpiler can also be used for converting the ES6 JS code to ES5 JS sourcecode.

How does Transpiler work internally?

  • A transpiler parses the code and extracts the tokens(keywords,literals,variables, operators).
  • Then it forms an Abstract Syntax Tree to suit the targeted language.

1_pbiJh2DzpQQRcIUOyhcp-g.png

Summary of main points

  • Compiler converts High Level Program to Low Level Program.
  • Transpiler converts a source code into target source code with simillar level of abstraction.

Thank you for reading till now! Hope now you will have a clear difference between compiler and transpiler.