Perl可以“静态地"添加到Perl吗?解析了吗? [英] Can Perl be "statically" parsed?

查看:60
本文介绍了Perl可以“静态地"添加到Perl吗?解析了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

名为无法解析Perl,是正式证明"的文章正在做这些回合.那么,Perl是否在运行时"或编​​译时"决定其解析代码的含义?

An article called "Perl cannot be parsed, a formal proof" is doing the rounds. So, does Perl decide the meaning of its parsed code at "run-time" or "compile-time"?

在我读过的一些讨论中,我得到了论点源于不精确术语的印象,因此请尝试在答案中定义您的技术术语.我故意没有定义运行时",静态"或已解析",以便可以从那些可能对我定义不同术语的人那里获得观点.

In some discussions I've read, I get the impression the arguments stem from imprecise terminology, so please try to define your technical terms in your answer. I have deliberately not defined "run-time", "statically" or "parsed" so that I can get perspectives from people who perhaps define those terms differently to me.

这与静态分析无关.这是有关Perl行为的理论问题.

This isn't about static analysis. Its a theoretical question about Perl's behaviour.

推荐答案

Perl有一个定义明确的编译时间"阶段,其后是一个定义明确的运行时"阶段.但是,存在从一种过渡到另一种的方法.许多动态语言具有eval构造,允许在运行时阶段编译新代码.在Perl中,逆过程也是可能的,并且很常见. BEGIN块(以及由use引起的隐式BEGIN块)在 编译时调用一个临时运行时阶段. BEGIN块在编译后立即执行,而不是等待编译单元的其余部分(即当前文件或当前eval)编译.由于BEGIN在编译其后的代码之前运行,因此它们实际上可以以任何方式影响以下代码的编译(尽管实际上,它们所做的主要工作是导入或定义子例程,或者启用严格性或警告. ).

Perl has a well-defined "compile time" phase, which is followed by a well-defined "runtime" phase. However, there are ways of transitioning from one to the other. Many dynamic languages have eval constructs that allow compilation of new code during the runtime phase; in Perl the inverse is possible as well -- and common. BEGIN blocks (and the implicit BEGIN block caused by use) invoke a temporary runtime phase during compile-time. A BEGIN block is executed as soon as it's compiled, instead of waiting for the rest of the compilation unit (i.e. current file or current eval) to compile. Since BEGINs run before the code that follows them is compiled, they can influence the compilation of the following code in practically any way (although in practice the main things they do are to import or define subroutines, or to enable strictness or warnings).

use Foo;基本上等同于BEGIN { require foo; foo->import(); },并且要求(例如eval STRING)是从运行时调用编译时的一种方法,这意味着我们现在处于编译时在运行时内时间,并且整个过程都是递归的.

A use Foo; is basically equivalent to BEGIN { require foo; foo->import(); }, with require being (like eval STRING) one of the ways to invoke compile-time from runtime, meaning that we're now within compile-time within runtime within compile-time and the whole thing is recursive.

无论如何,归结为解析Perl的可判定性在于,由于一小段代码的编译会受到前一段代码的执行的影响(从理论上讲,做任何事情),我们遇到了一个停顿问题类型的情况;通常,正确解析给定Perl文件 的唯一方法是执行该文件.

Anyway, what it boils down to for the decidability of parsing Perl is that since the compilation of one bit of code can be influenced by the execution of a preceding piece of code (which can in theory do anything), we've got ourselves a halting-problem type situation; the only way to correctly parse a given Perl file in general is by executing it.

这篇关于Perl可以“静态地"添加到Perl吗?解析了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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