Perl 是编译型还是解释型编程语言? [英] Is Perl a compiled or an interpreted programming language?

查看:130
本文介绍了Perl 是编译型还是解释型编程语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl 是编译的还是解释的?

Is Perl compiled or interpreted?

推荐答案

嗯,这取决于您所说的编译语言是什么意思.也许这就是谷歌搜索没有为您的问题提供明确答案的原因.

Well, that depends on what you mean by a compiled language. Maybe this is why googling did not bring forth a clear answer to your question.

一种观点是编译意味着从源代码描述编译到另一个,即代码生成.

One viewpoint is that compilation means compiling from a source code description to another, i.e. code generation.

如果我们接受这些前提,那么 Perl 6 就可以编译,而 Perl 5 和更早的版本是解释性语言.

If we accept these premises, then Perl 6 can be compiled and Perl 5 and older are interpreted languages.

Perl 6 专门编译为 Parrot 字节码.因此,Perl 6 是一种正确编译的语言,就像 Java 是.

Perl 6 is specifically compiled to Parrot bytecode. Perl 6 is therefore a properly compiled language, in the same way say, Java is.

Perl 5 及更早版本将 Perl 源代码解析为内部列表或树,但我认为不应将其称为适当的编译器,除非是理论上的.它不输出通常与编译器相关的任何字节码、汇编或真实机器代码.Perl 用于检查 Perl 语法的解析阶段过去称为编译"源代码.它用于在不运行 Perl 源文件的情况下检查它的语法有效性.

Perl 5 and older parses the Perl source code to an internal list or tree, but I don't think it should be called a proper compiler, except maybe in a theoretical sense. It does not output any bytecode, assembly or real machine code usually associated with compilers. The parsing stage of Perl to check Perl syntax used to be called "compiling" the source. It is used to check the syntactical validity of a Perl source file without running it.

它被调用为:

perl -c myprog.pl

但是如果您查看 Perl 选项的帮助,-c 实际上代表检查".

But if you look at the help for Perl options, -c actually stands for "check".

-c                check syntax only (runs BEGIN and CHECK blocks)

(更复杂的是,Perl 5 支持写出内部字节码,但它是 在 5.10 版中删除.大概是因为它有问题,我不知道.)

(To further complicate things, Perl 5 had support for writing out internal bytecode but it was removed in version 5.10. Presumably because it was buggy, I don't know.)

另一方面,如果您认为编译是将源树解析为任何其他类型的表示的行为,那么解析使 Perl 成为一种编译语言.Perl 必须完全解析源文件才能开始执行它.根据这个定义,任何可以在解析前立即开始执行源文件的语言都是解释型语言.

On the other hand, if you argue that compilation is the act of parsing a source tree into any other kind of representation, well, that parsing makes Perl a compiled language. Perl must completely parse a source file before it can start executing it. By this definition, any language which can start executing a source file immediately before parsing would be an interpreted language.

查看此问题的第三种方法是从该领域的专业人士最常使用这些词解释"和编译"的方式来看.我敢打赌,如果让一部分程序员在考虑 Perl 时被要求选择已编译"或已解释",那么大多数人会选择已解释".不是因为一些关于 Perl 本质的理论争论,而是因为编译"通常会引起编译"、链接"、目标代码"等的想法,而解释"则意味着编写代码,尝试一下"".对或错,在试图确定 Perl 是否被真正解释或实际上已编译时,了解这一点可能会很好.在你的探索过程中,你会遇到很多争论.

A third way to look at this is from how these words, "interpreted" and "compiled" are most often used by professionals in the field. I would bet good money that if a random subset of programmers were asked to choose "compiled" or "interpreted" when thinking of Perl, most would choose "interpreted". Not because of some theoretical argument over the nature of Perl, but because "compiled" usually invokes thoughts of "compiling", "linking", "object code" etc, while "interpreted" is taken to mean "write the code, try it". Right or wrong, that may be good to know when trying to determine if Perl is, truly, interpreted or in fact, compiled. You are going to run into many arguments on your quest.

这篇关于Perl 是编译型还是解释型编程语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆