一种语言被“解释”意味着什么?
像 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在只是刻薄地说,几乎所有编程语言都是解释的,无论是软件(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.
解释是一个定义非常宽松的词。甚至机器代码指令也由处理器解释。
一般来说,在运行之前进行编译的语言和没有编译过程并在另一个程序(称为解释器)内运行的语言之间存在区别。后一种类型的语言通常称为解释语言。
在某些情况下,界限并不那么清晰:
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:
exec
functionality which allows code to be generated and executed at run-time, bypassing the normal compilation process.