Compilers和 Interpreters简要介绍

本文简要介绍Compilers and Interpreters

 

Compilers (编译器)和 interpreters(解释器)都是将人类可读的代码转换为机器可读的代码,只不过二者的实现形式有所不同。

 

An interpreter produces a result from a program, while a compiler produces a program written in assembly language.

 

Compilers :将源程序转换为可执行目标文件,该文件可以直接被计算机执行。

Interpreters: 读取源程序的同时,将之转换为指令传递给计算机执行。

同一段程序可以解释执行,也可以编译执行,因此不存在“某种语言时解释执行还是编译执行”的命题

 

别人家的类比:

So let’s say you have a hummus recipe that you want to make, but it’s in Ancient Greek. There are two ways you, as a non-Ancient-Greek speaker, could follow its directions.

The first is if someone had translated it into English for you already. You (and anyone else who could speak English) could get the English version and make hummus. This is the compiled version.

The second is if you had a friend who knows Ancient Greek. Your friend can sit next to you and translate Ancient Greek into English, line by line, as you go. In this case, your friend is the interpreter. This is the interpreted version.

 

特点分析:

Compilers :

  1. 当程序被编译为可执行目标文件后,计算机执行该可执行目标文件是相当快速的。
  2. 可移植性差。一旦源程序被编译成可执行目标文件,该文件只能在特定的指令集架构中运行,但是源程序可以被编译成不同指令集架构下的可执行目标文件。
  3. 修改性差。一旦源程序被编译成可执行目标文件,当源程序被修改后,只有进行再次编译才可进行修改。
  4. 个人认为,在商业用途上,可以只提供可执行目标文件以达到保密源代码的目的。

Interpreters:

  1. 可移植性强。只要拥有对应指令集体系架构下的解释器,就可以对源程序进行解释。这也存在某种局限性,一旦没有相应的interpreters,程序将无法运行,而由解释器产生的可执行目标程序,无compilers也可以运行。
  2. 不产生文件占用内存。只产生一种结果,不会产生文件。
  3. 修改性强。一旦源程序被修改,直接解释就可以完成。

参考引用:

1. https://guide.freecodecamp.org/computer-science/compiled-versus-interpreted-languages/

2. https://kb.iu.edu/d/agsz

本文如有错误,请在评论中指出,谢谢。

posted @ 2020-03-10 10:31  zqybegin  阅读(611)  评论(0编辑  收藏  举报