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

发布于 2024-09-01 09:30:48 字数 156 浏览 8 评论 0原文

像 Ruby 这样的语言(如果运行 MRI,我的意思是不编译为字节码)是否每次需要执行方法或循环体时都会实际解析?我的意思是,要执行循环,您需要解析其主体N次?

我只是一直认为所有这些程序都在引导程序中被解析一次,在“强类型”语句树中进行转换,等等。这不是真的吗?

Do languages like e.g. Ruby (if running MRI, I mean not compiled to byte-code) run actually parsed everytime when an execution of, e.g., method or loop body is needed? I mean, to execute a loop, you need to parse its body N times?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软的没边 2024-09-08 09:30:48

我现在只是刻薄地说,几乎所有编程语言都是解释的,无论是软件(Ruby、Python、Java)还是硬件(C、C++)解释器:)

对于真正的答案,虽然我不这样做了解内部 Ruby 实现,我确信他们不会一遍又一遍地解析该语句。虽然在原始实现中没有使用字节码(或者它们已经迁移了吗?),但它们使用一些中间表示(当您想为其编写 C 扩展时可以很好地看到它),因此只需一遍又一遍地执行这些表示。

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 :)

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. 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.

不…忘初心 2024-09-08 09:30:48

解释是一个定义非常宽松的词。甚至机器代码指令也由处理器解释。

一般来说,在运行之前进行编译的语言和没有编译过程并在另一个程序(称为解释器)内运行的语言之间存在区别。后一种类型的语言通常称为解释语言

在某些情况下,界限并不那么清晰:

  • 某些语言可以编译或解释,例如 PHP。
  • 一些解释代码可能会在运行时编译为本机机器指令(JIT 编译) 。
  • 某些编译语言可能具有 exec 功能,允许在运行时生成和执行代码,绕过正常的编译过程。

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, e.g. PHP.
  • Some interpreted code might be compiled at runtime into native machine instructions (JIT compilation).
  • Some compiled languages may have an exec functionality which allows code to be generated and executed at run-time, bypassing the normal compilation process.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文