Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler vs Interpreter vs Transpiler

During a reactJS session that I was attending, the presenter used a term transpiler for some code conversion/porting happening. I've always used and heard the terms compiler and interpreter when it comes to converting a language code to a runnable form on a computer system/machine. Transpiler is new to me. How is a transpiler different from a compiler or an interpreter and why it is really needed?

like image 362
RBT Avatar asked Aug 31 '16 10:08

RBT


People also ask

What is difference between compiler and transpiler?

A compiler is a software that converts high-level language to low-level assembly language and we are all quite familiar with its name and work. A transpiler is another software, sometimes called a source-to-source compiler, which converts a high-level language to another high-level language.

What is the difference between a compiler and an interpreter?

A compiler translates the entire source code in a single run. An interpreter translates the entire source code line by line. It consumes less time i.e., it is faster than an interpreter. It consumes much more time than the compiler i.e., it is slower than the compiler.

What is transpiler programming?

A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language.


2 Answers

Compiler - compiles code to a lower level code.

Example:

  • "Developer code" -> "Machine code"
  • PHP -> C
  • Java -> bytecode

Transpiler - compiles code to same level of code/abstraction.

Example:

  • "Developer code" -> "Another developer code or version"
  • JavaScript ES2015+ -> JavaScript ES5

Interpreter - interprets code, not really in the same class/league/context with the two above.

Example: php.exe

  • "Your PHP code/scripts inside index.php" -> "Results to html or just like pure index.html"
like image 50
Jim M Avatar answered Nov 01 '22 06:11

Jim M


As is mentioned in this Wiki article, it is a type of compiler which translates source code from one programming language to another programming language. The source code might be in some language no longer used, or doesn't support latest hardware/software advancements, or as per programmer's convenience/favoritism.

A VB6 to VB.NET converter can be thought of as a Transpiler. I might think of COBOL to C# / C++ / Java tool as a transpiler.

like image 44
Ajay Avatar answered Nov 01 '22 06:11

Ajay