RUBY 中的编译器和解释器
编程语言有可能有解释器和编译器吗? 如果是,怎么办?
** 我认为 RUBY 有编译器和解释器 **
谢谢
Is it possible that a programming language has a interpreter and compiler?
if yes, how ?
** I think RUBY has compiler and interpreter **
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
某些语言既可以编译为平台特定的运行时可执行文件,也可以被解释。例如,Ruby 可以由多个解释器、本机 ruby、ree 等解释,也可以由 JRuby“编译”为本机 java 代码(不完全是本机可执行文件)。
Some languages can be both compiled into platform specific runtime executables and be interpreted. For example Ruby can be interpreted by multiple interpreters, native ruby, ree, etc as well as "compiled" into native java code (which is not exactly a native executable) by JRuby.
当然,你可以两者兼得。除了 Java、Python 和现在的 Ruby 等显而易见的示例之外,如果您确实愿意,您还可以为它们中的任何一个编写本机编译器。我认为 Ruby 编译器的实现很糟糕。
相反,你也可以为 C 编写一个解释器,我认为有一些。
由于技术原因,像 Ruby 这样的动态语言很难编写编译器,并且使用 C 解释器会抵消编写 C 语言相对于 Ruby 等语言的主要优势。这并不意味着它不能完成。
简而言之,您可以为您可以获得或弄清楚规范的任何语言和平台(本机或虚拟机)编写编译器或解释器,或两者兼而有之。
Sure, you can have both. Besides the obvious examples of Java, Python, and now Ruby, you could write a native compiler for any of them if you really wanted to. I think there is a poorly implemented Ruby compiler out there.
Conversely, you could also write an interpreter for C, I think there are a few around.
There are technical reasons why a dynamic language like Ruby is difficult to write a compiler for and using an interpreter for C defeats the main advantage of writing C over languages like Ruby. That doesn't imply it can't be done.
In short, you can write a compiler or an interpreter, or both for any language and platform(native or VM) that you can get or figure out the specifications.