日常翻译【Difference between Interpreter and Compiler Interpreter vs Compiler Animated】

发布时间 2023-04-26 16:47:11作者: One7

  When you land in the world of computers with their strange convoluted machine language, it's a bit like landing on another planet, whose inhabitants speak an equally strange convoluted alien language. Getting a mechanic on planet Gobbledygook to repair your spaceship would present the same sort of problem that you have. when you want to get a computer to do something, everything you say has to be translated, and you have a choice between two different sorts of translator, one of them is called an interpreter and the other is called a compiler. let's suppose that you've previously written out your list of instructions for the repair of your spaceship, and suppose that you choose the interpreter to do the translating. he reads your first instruction, open lid of rocket engine, translates this the GOBBLE-GOOK-GOBBLE-GOOBBLE, and immediately passes it on to the mechanic, who executes the instruction, then the interpreter reads your second instruction, remove spark plug, translates this in the gobbledygook and passes it on to the mechanic, who executes it, and so on and so forth. now notice how the interpreter works, he stays with you all the time, and he translates each of your instructions immediately one by one, this is a rather slow process because the mechanic has to wait while each instruction is being translated, but on the other hand, it does give you a chance to correct your mistakes as you go along. if the mechanic removes the wrong sparkplug for instance, you'll see this happen right away, and you'll be able to change your instruction accordingly.

  Compare this with the way the second sort of translator, the compiler goes about his work, he takes your complete list of instructions, and without further ado, translates the whole lot straight into GOBBLE-GOOK. he then hens them back to you, and goes away leaving you all on your own. All this has taken some time, but from now on things will go very fast, you hand the complete list of gobbledygook to the mechanic, and he executes them all in one go bang bang bang. there's no waiting about this time, but there's one disadvantage to this of course, if there was a mistake in your instructions, it's too late now. this analogy comes very close to the way the interpreter and compiler translator programs actually work with computers. An interpreter runs slowly, starts right away, and lets you see how things are going, whereas a compiler takes extra preparation time before your program can run, but then lets it run very quickly and efficiently. To help you remember the difference between an interpreter and a compiler, look at the words themselves, inter means between, the interpreter is always between your program and the computer, and it translates line by line. To compile on the other hand means to pile together, a compiler piles together your entire program and translates the whole thing all at once, which one you use on planet gobbledygook is entirely up to you.

  当你进入计算机世界时,面对它们奇怪、复杂的机器语言,就像降落在另一个星球上,其居民讲着同样奇怪、复杂的外星语言。如果要在GOBBLE-GOOK“星球”找到机械师来修理你的飞船,你会遇到与你在计算机上做事情时相同的问题。当你想让计算机执行某项任务时,你说的每句话都必须翻译,你可以选择两种不同类型的翻译器,其中一个叫解释器,另一个叫编译器。现在假定您之前已经写下了宇宙飞船维修说明列表,并假设您选择解释器来进行翻译。他读了第一条指令“打开火箭引擎盖”,翻译为“GOBBLE-GOOK”,并立即将它递给执行指令的机械师,然后解释器读取第二个指令“取下火花塞”,翻译为“GOBBLE-GOOK”,将其递给执行它的机械师,依此类推。现在,注意解释器是如何工作的,他一直待在你身边,他会立即一条一条地翻译每条指令,这是一个相当缓慢的过程,因为机械师必须在翻译每条指令时等待,但是从另一方面来说,它确实给了你一个机会来纠正你的错误。例如,如果机械师移除了错误的火花塞,您会立即看到这种情况发生,并且能够对指令进行相应的更改。

  将其与第二种翻译器的工作方式进行比较,编译器进行他的工作,他获取你的完整指令列表,然后毫不费力地将所有内容直接翻译成“GOBBLE-GOOK”。然后他把它们还给你,然后离开,留下你一个人。这一切都花了一些时间,但从现在开始,事情会进展得非常快。你将完整的“GOBBLE-GOOK”清单交给机械师,他会一口气执行完所有的任务。这次无需等待,但这样做有一个缺点,如果您的指令有误,现在就太晚了。这个类比非常接近解释器和编译器程序在计算机上的实际工作方式。解释器运行缓慢,可以立即启动,让你看到事情的进展情况。而编译器在程序运行之前需要额外的准备时间,但随后它非常快速和高效地运行。为了帮助你记住解释器和编译器之间的区别,看Interpreter这个单词本身,inter的意思是between,解释器永远在你的程序和计算机之间,并且一行一行地翻译。另一方面,编译意味着堆在一起,编译器将整个程序堆在一起并一次性翻译所有内容,在GOBBLE-GOOK星球上使用哪种翻译器完全取决于你。