![](https://i-blog.csdnimg.cn/blog_migrate/ffab0ee32656f639c8420f0d0fe62af2.png)
编译器和解释器区别
In this tutorial you will learn about difference between compiler and interpreter i.e. compiler vs interpreter.
在本教程中,您将了解编译器和解释器之间的区别,即编译器与解释器。
We know that computers can only understand machine language which is in binary format. But we write in natural programming language (like C, Java etc). So there must be something which converts these programming instructions into machine understandable instructions. Those are compilers and interpreters. Both are intended for same purpose. But there they differ in the way they accomplish the task.
我们知道计算机只能理解二进制格式的机器语言。 但是我们用自然编程语言(例如C,Java等)编写。 因此,必须有某种东西可以将这些编程指令转换为机器可理解的指令。 这些是编译器和解释器。 两者都是出于相同的目的。 但是他们在完成任务的方式上有所不同。
Compiler: Compiler can be defined as, it is a computer program, that used to convert high level instructions or language into a form that can be understood by the computer which is called low level language. There are specific compilers for certain specific languages. After compilation an executable file will be generated.
编译器 :编译器可以定义为计算机程序,用于将高级指令或语言转换为计算机可以理解的形式,称为低级语言。 有某些特定语言的特定编译器。 编译后,将生成一个可执行文件。
Interpreter: The programs created in high level languages can be executed by using different ways. The first one is the use of compiler and the other method is to use an interpreter. High level instruction or language is converted into intermediate from by an interpreter. The advantage of using an interpreter is that the high level program does not goes through compilation stage, which can be a time consuming method. So by using interpreter high level program executed directly.
口译员:使用高级语言创建的程序可以通过不同方式执行。 第一种是使用编译器,另一种方法是使用解释器。 高级解释器或语言由口译员转换为中间语言。 使用解释器的优点是高级程序不会经过编译阶段,这可能是一种耗时的方法。 因此,通过使用解释器可以直接执行高级程序。
All most all high level programming languages have compilers and interpreters. But some languages like LISP and BASIC are designed in such a way that the programs made using them are executed by an interpreter.
所有大多数高级编程语言都有编译器和解释器。 但是,某些语言(如LISP和BASIC)的设计方式是使使用它们编写的程序由解释器执行。
Now we will see some differences between them.
现在,我们将看到它们之间的一些差异。
编译器和解释器之间的区别 (Difference between Compiler and Interpreter)
Compiler | Interpreter |
1) Compiler converts high level instructions into machine understandable instructions. | 1) Interpreter directly executes high level code without converting. |
2) Before execution, entire program will be executed by compiler. | 2) Interpreter executes line by line. So after translating first line only it executes second line and so on. |
3) If there any compiler errors, it shows entire programs compiler errors once. First line error won’t stop program to be executed in compiler. | 3) If there any errors, only one line error displayed at once. Not all at once like compiler. Error in nth line will stop execution of lines form n+1. |
4) After compilation an executable file will be created. That will be executed for program output. | 4) Interpreter is required by an interpreted program each time. |
5) We can use object code which is generated by compiler (like .exe, a.out files) repeatedly, without executing original program every time. Unless we want to change original program. | 5) In interpreter whenever we want output of program we should execute entire original program. |
6) Compilation need more extra space since an extra executable file will be generated. | 6) Requires less memory space. Because no need to store any intermediate code. |
7) Compiled code runs faster than original code. This way of doing is faster than using interpreter | 7) There is no intermediate code generation/executable files. Each time entire program must be executed. Therefore interpreted program is slower than compiled program. |
8) It is faster in assigning memory to variables and accessing those. | 8) Access to variables is also slower in an interpreter because the mapping of identifiers to storage locations must be done repeatedly at run-time rather than at compile time. |
9) Spends a lot of time analyzing and processing the program. | 9) Relatively little time is spent analyzing and processing the program. |
10) Native compiler, cross compiler, Source to source compiler, one pass compiler, incremental compiler, source compiler are some different types of compilers. | 10) Bytecode interpreter, threaded code interpreter, abstract syntax tree interpreter are some types of interpreters. |
11) Example: C, Java compilers | 11) Example: LISP, BASIC interpreters |
编译器 | 口译员 |
1)编译器将高级指令转换为机器可理解的指令。 | 1)解释器无需转换即可直接执行高级代码。 |
2)在执行之前,整个程序将由编译器执行。 | 2)解释器逐行执行。 因此,在翻译第一行之后,仅执行第二行,依此类推。 |
3)如果有任何编译器错误,它将一次显示整个程序的编译器错误。 第一行错误不会停止要在编译器中执行的程序。 | 3)如果有任何错误,一次仅显示一行错误。 并非一次都像编译器一样。 第n行中的错误将停止执行n + 1行。 |
4)编译后,将创建一个可执行文件。 将执行该程序以输出程序。 | 4)解释程序每次都需要口译员。 |
5)我们可以重复使用由编译器生成的目标代码(如.exe,a.out文件),而不必每次都执行原始程序。 除非我们要更改原始程序。 | 5)在解释器中,每当我们要输出程序时,都应执行整个原始程序。 |
6)编译需要更多的额外空间,因为将生成一个额外的可执行文件。 | 6)需要更少的内存空间。 因为不需要存储任何中间代码。 |
7)编译后的代码比原始代码运行得更快。 这种方式比使用解释器更快 | 7)没有中间代码生成/可执行文件。 每次必须执行整个程序。 因此,解释程序比编译程序慢。 |
8)将内存分配给变量并访问变量更快。 | 8)在解释器中对变量的访问也较慢,因为标识符到存储位置的映射必须在运行时而不是在编译时重复进行。 |
9)花费大量时间分析和处理程序。 | 9)花费相对较少的时间来分析和处理程序。 |
10)本机编译器,交叉编译器,源到源编译器,一遍编译器,增量编译器,源编译器是一些不同类型的编译器。 | 10)字节码解释器,线程代码解释器,抽象语法树解释器是某些类型的解释器。 |
11)示例:C,Java编译器 | 11)示例:LISP,BASIC解释器 |
Comment below if you have queries related to above tutorial for difference between Compiler and Interpreter.
如果您对上面的教程有疑问,请对下面的注释进行评论,以了解编译器和解释器之间的区别。
翻译自: https://www.thecrazyprogrammer.com/2014/07/compiler-vs-interpreter.html
编译器和解释器区别