编译与编译 [英] Compiling vs Transpiling

查看:105
本文介绍了编译与编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在寻找差异时,我遇到了以下定义:

While searching about the difference, I came across these definitions:

编译是获取用一种语言编写的源代码的总称

Compiling is the general term for taking source code written in one language and transforming into another.

翻译是一个特定术语,用于获取用一种语言编写的源代码并转换成具有相似级别的另一种语言

Transpiling is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction.

我理解什么是抽象。

但是相似级别的抽象在什么意思上面的定义?我们如何找到一种语言的抽象水平?

But what does "similar level of abstraction" mean in the above definition? And how do we find the level of abstraction in a language?

推荐答案

您上面引用的定义对于初学者来说太笼统,无法完全理解,因此让我将其简化为我们

The definition you have quoted above is too general for a beginner to understand completely and so let me just simplify it to something we see practically.

编译器:是一个笼统的术语,用于描述采用一种语言编写的源代码并产生一个(或多个)源代码的程序。用其他语言输出文件。
实际上,我们大多使用该术语来描述诸如gcc之类的编译器,它将C代码作为输入,并生成二进制可执行文件(机器代码)作为输出。

Compiler: is an umbrella term to describe a program that takes source code written in one language and produce a (or many) output file in some other language. In practice we mostly use this term to describe a compiler such as gcc which takes in C code as input and produces a binary executable (machine code) as output.

编译器也被称为源到源编译器。因此,从本质上讲,它们是编译器的子集,它们将源代码文件导入并转换为其他某种语言或同一语言的不同版本的另一个源代码文件。输出通常是人类可以理解的。此输出仍必须通过编译器或解释器才能在机器上运行。

Transpilers are also known as source-to-source compilers. So in essence they are a subset of compilers which take in a source code file and convert it to another source code file in some other language or a different version of the same language. The ouput is generally understandable by a human. This output still has to go through a compiler or interpreter to be able to run on the machine.

一些编译器示例:


  1. 脚本:将C / C ++转换为JavaScript

  2. Babel :将ES6 +代码转换为ES5(ES6和ES5是不同版本或JavaScript语言的世代)

  1. Emscripten: Transpiles C/C++ to JavaScript
  2. Babel: Transpiles ES6+ code to ES5 (ES6 and ES5 are different versions or generations of the JavaScript language)

现在,它们的相似抽象水平是什么意思:
它可以编译/编译为源文件,可以说汇编语言也是源文件,因此gcc也是一种编译器。因此,这种论点就是这种类似级别的抽象无效。

Now, what do they mean by "similar level of abstraction": As I said it compiles/transpiles to a source file, one can argue that assembly language is also a source file and thus gcc is also a transpiler. So, this argument is what this similar level of abstraction voids.

将语言分为低级,中级和高级级别的概念基于它们从机器/体系结构的实际工作中提供的抽象级别。

The notion of categorizing languages into lower, middle and higher level is based on the level of abstraction they provide from the actual working of the machine/architecture.

像汇编这样的较低级语言非常接近处理器体系结构,即针对不同处理器具有不同的指令。在使用C / C ++ / Java / JavaScript时,请对所有这些内容进行抽象以提供更多的抽象。

Lower level languages like assembly are very close to the processor architecture i.e. have different instructions for different processors. While C/C++/Java/JavaScript, abstract all this away providing more abstraction.

因此,编译器将其编译为与您在其中开始的语言更接近的语言。

So, a transpiler compiles to a language that is closer to the language you started with in the terms of this abstraction (or is closer to the level of that language in the lower-middle-higher level language ladder).

希望这会有所帮助!

这篇关于编译与编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆