Complied VS Interpreted Language编译型语言与解释型语言

来源:互联网 发布:中国网络世界好先进 编辑:程序博客网 时间:2024/05/16 08:31

Not so much a feature of language syntax as of how language is converted into machine instructions.

Many languages use elements of both.

与其说是语言语法的特点不如说是怎么样把编程语言转化为机器语言。

许多语言两种元素兼有。


Interpreter:

  • Takes commands one at a time, converts into machine code, and executes
  • Allows interactive programming at a shell prompt, as in Python or Matlab.
  • Can't take advantage of optimizing over a entire program- does not know what instructions are coming next.
  • Must translate each command while running the code, possibly many times over in a loop.
解释器:
  • 在同一时间接收一个命令,将其转化为机器码并执行。
  • 允许在命令行提示符中进行交互式编程,就像在Python或者Matlab中那样
  • 不能利用优化整个程序所带来的好处——不知道接下来所要运行的命令。
  • 在运行代码时,必须逐个命令的进行转换翻译,可能在一个循环中执行了很多次(注:对一个命令编译很多遍)
Compiled language:

The program must be written in one or more files(calledsource code).

These files are input data for the compiler, which is a computer program that analyzes the source code and converts it intoobject code.

The object codes is then passed to a linker or loader that turns one or more objects into an executable.
编译语言:

程序必须写在一个或者几个文件之中(源文件)。

这些文件就是编译器的输入数据。编译器可以视为一种计算机程序,分析源代码并将其转化为目标代码。

这些目标代码会被传递给连接器或者装载器,将其转化为一个可执行文件。

WHY TWO STEPS?
Object code contains symbols such as variables that may be defined in other objects. Linker resolves the symbols and converts them into addresses in memory.

Often large projects consist of many separate files and/or library routines -- don't want to re-compile them all when only one is changed.(Makefiles can be used)
为什么分为两步?
目标文件包含像变量这样的符号,这些符号可能在其他目标文件中被定义。连接器分解这些符号并将其转换为其在内存中对应的地址。

大型项目经常包含很多独立的文件或者程序库——当只有一个文件改动的时候并不像全部都重新编译(可使用Makefiles)


参考: http://faculty.washington.edu/rjl/uwhpsc-coursera/index.html

0 0