简体   繁体   English

语言被“解释”意味着什么?

[英]What does it mean for a language to be ‘interpreted’?

Do languages like eg Ruby (if running MRI, I mean not compiled to byte-code) run actually parsed everytime when an execution of, eg, method or loop body is needed? 像Ruby这样的语言(如果运行MRI,我的意思是没有编译成字节码)运行实际上每次执行时都需要解析,例如方法或循环体吗? I mean, to execute a loop, you need to parse its body N times? 我的意思是,要执行一个循环,你需要解析它的身体N次?

I just always thought that all these programs are being parsed one time at the bootstrap, transformed in a 'strongly-typed' statements tree, etc. Is that not true? 我一直以为所有这些程序都在引导程序中被解析一次,在“强类型”语句树中转换,等等。这不是真的吗?

Interpreted is a word with a very loose definition. 解释是一个定义非常宽松的词。 Even machine code instructions are interpreted by the processor. 甚至机器代码指令也由处理器解释。

In general a distinction is made between languages which are compiled before they are run and languages which do not have a compilation process and are run inside another program, called the interpreter. 通常,在运行之前编译的语言和没有编译过程并在另一个程序(称为解释程序)内运行的语言之间进行区分。 The latter types of languages are often referred to as interpreted languages . 后一种语言通常被称为解释语言

The line is not that clear in some cases: 在某些情况下,这条线并不清楚:

  • Some languages can be either compiled or interpreted, eg PHP. 有些语言可以编译或解释,例如PHP。
  • Some interpreted code might be compiled at runtime into native machine instructions ( JIT compilation ). 某些解释的代码可能在运行时编译为本机机器指令( JIT编译 )。
  • Some compiled languages may have an exec functionality which allows code to be generated and executed at run-time, bypassing the normal compilation process. 某些编译语言可能具有exec功能,允许在运行时生成和执行代码,绕过正常的编译过程。

I'll just be mean now and say that just about EVERY programming language is interpreted, whether it's a software (Ruby, Python, Java) or a hardware (C, C++) interpreter :) 我现在只是吝啬,并说几乎每种编程语言都被解释,无论是软件(Ruby,Python,Java)还是硬件(C,C ++)解释器:)

For a real answer, while I don't know about the internal Ruby implementation, I'm sure as hell they don't parse the statement over and over and over again. 对于一个真正的答案,虽然我不知道内部的Ruby实现,但我确定他们不会一遍又一遍地解析语句。 While not using bytecode in the original implementation (or did they migrate already?), they use some intermediate representation (you can see it nicely when you want to write C-extensions for it), thus just executing those over and over again. 虽然在原始实现中没有使用字节码(或者它们是否已经迁移?),但是它们使用了一些中间表示(当你想为它编写C扩展时可以很好地看到它),因此只是反复执行它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM