只能“perl6”解析 Perl 6?
有一条(相对)众所周知的 Perl 公理:“只有 Perl 可以解析 Perl”。我想知道,Perl 6 仍然如此吗?
扩大讨论......考虑到 PyPy 最近的更新,我想到了这个问题。 Perl 独特的可解析性是否使其无法进行类似的努力? Perl 代码的受限静态视图(PPI?)有多大价值吗? Perl 6 可以有 JIT 编译器吗?*
* 我不确定这些概念是否相关。他们是吗?
There's that (relatively) well known Perl axiom, "Only perl can parse Perl." I'm wondering, will that remain true for Perl 6?
Expanding the discussion... I thought of this question given the recent update of PyPy. Does Perl's unique parsability preclude it from similar efforts? Is there much value in a restricted, static view of Perl code (PPI?)? Can Perl 6 have a JIT compiler?*
* I'm not sure if these concepts are related. Are they?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
没有perl6,但有很多Perl 6编译器。 Perl 6 有一个语法,尽管它是用 Perl 6 编写的,因此只要你能理解,它就会告诉你你需要知道的一切。
我刚刚问了 Larry 这个问题,因为我在圣保罗 Perl 研讨会。他说现在是“只有 Perl 6 可以解析 Perl 6”,两个 Perl 上的字母都大写,这意味着与原来的声明不同。
不过,您不需要特定的程序来执行此操作,因为 Perl 6 的目标是一个标准和多种实现。没有“perl6”,尽管 Larry 在今天的演讲中使用了他的 Rakudo 的别名,尽管他在示例中使用了一些不同的实现。
There is no perl6, and there are many Perl 6 compilers. Perl 6 has a grammar, although it's written in Perl 6, so as long as you can understand that, it tells you everything you need to know.
I just asked Larry this question, since I'm sitting across from him at lunch at the São Paulo Perl Workshop. He says it's now "Only Perl 6 can parse Perl 6", with capital letters on both Perls, which means something different than the original statement.
You don't need a specific program to do that though since Perl 6's goal is one standard and many implementations. There is no "perl6", although Larry had that aliased to his Rakudo for today's talk, even though he used a few different implementations for the examples.
最后我看到,Perl 6 继承了 Perl 5 的 / 字符,当需要术语时,这可能意味着“正则表达式的开始”,或者当需要运算符时意味着“除法”。鉴于此和原型,Perl 6 至少在静态标记化方面与 Perl 5 属于同一阵营。标记 Perl 6 程序的唯一方法是在 Perl 6 编译器中运行 Perl 6 解释器。海龟再次一路下降。
Last I looked, Perl 6 inherits Perl 5's / character, which can mean "beginning of regex" when a term is expected, or "divide" when an operator is expected. Given that, and prototypes, and Perl 6 is at least in the same camp as Perl 5 for static tokenization. The only way to tokenize a Perl 6 program is to have a running Perl 6 interpreter in the Perl 6 compiler. Turtles all the way down, once again.
公理“只有 perl 可以解析 Perl”,其中“perl”是解释器二进制文件,“Perl”是语言,很大程度上源于解析规则在解析文件时可以更改的事实。在 Perl 5 中,这来自原型子例程声明、各种编译指示和源过滤器。
在我看来,这在 Perl 6 中只会成为一个更大的问题。在 Perl 5 中,解析器规则可以更改的位置数量有限,而在 Perl 6 中,它们的范围广泛且多种多样。除了 Perl 5 拥有的所有功能之外,Perl 6 还允许您定义自己的运算符,并且由于此定义是在 Perl 代码中完成的,因此需要 Perl 解释器来理解它。
据我所知,还没有实现支持它,但 Perl 6 规范还包括真正的语言级宏,它可以通过文本或操作 AST 来重构 Perl 6 代码。这两者都需要 Perl 解释器的存在来发挥它们的魔力。
所以总而言之,我有一种感觉,Perl 6 将使公理比 Perl 5 更强大。(对于语法荧光笔的作者来说,这将是一场噩梦:))当然,这都是为了增加表现力语言的力量,所以我可以接受这种让步。
上述推论是,与 Perl 5 不同,Perl 6 有正式规范,因此公理可能必须更改为“只有实现 Perl 6 规范的解释器才能解析 Perl 6”,但这有点迂腐。
根据更新:
我不认为上述内容排除了 Perl 6 的 JIT 编译器的想法,因为根据定义,这样的编译器还必须包含 Perl 6 解释器。就静态编译而言,这可能是可能的,但它会严重限制语言的运行时能力,因为任何涉及 eval 的构造都不起作用。
PPI 在 Perl 5 领域很有用,因为 Perl 解释器没有为其 AST 提供许多丰富且易于使用的接口。在 Perl 6 中,内省的水平要高得多,因此解释器本身可以提供所有必要的工具。
The axiom "Only perl can parse Perl" where "perl" is the interpreter binary and "Perl" is the language largely stems from the fact that parsing rules can change while the file is being parsed. In Perl 5, this comes from prototyped subroutine declarations, from various pragmas, and from source filters.
In my opinion, this is only going to become more of a problem in Perl 6. In Perl 5, the number of places where parser rules could change are limited, whereas in Perl 6, they are wide and varied. In addition to everything Perl 5 has, Perl 6 allows you to define your own operators, and since this definition is done in Perl code, a Perl interpreter is needed to make sense of it.
As far as I know, no implementation supports it yet, but the Perl 6 spec also includes real language level macros, which can restructure Perl 6 code either textually or by manipulating the AST. Both of these require the existence of a Perl interpreter to perform their magic.
So in conclusion, I have a feeling that Perl 6 will make the axiom stronger than it is for Perl 5. (And will be even more of a nightmare for the authors of syntax highlighters :) ) Of course this is all to increase the expressive power of the language, so I am ok with the concession.
A corollary to the above is that unlike Perl 5, Perl 6 has a formal spec, so the axiom might have to change to "Only an interpreter implementing the Perl 6 spec can parse Perl 6", but that's being a bit pedantic.
Per the update:
I don't think that the above precludes the idea of a JIT compiler for Perl 6, since by definition, such a compiler would also have to contain a Perl 6 interpreter. As far as static compilation goes, it MIGHT be possible, but it would severely restrict the language's runtime power, since any construct involving eval would not work.
PPI is useful in Perl 5 land because the perl interpreter does not provide many rich and easy to use interfaces to its AST. In Perl 6, the level of introspection is FAR greater, so the interpreter itself may provide all of the necessary tools.
Perl 6 是一个规范,任何遵循该规范的程序都是 Perl 6,就像大多数其他语言一样。有许多 Perl 6 实现正在开发中。
Perl 6 is a specification and any program that follows that spec is Perl 6, just as is true for most other languages. There are a number of Perl 6 implementations in the works.
您暗示 Perl5 无法基于“只有
perl
可以解析 Perl5”进行 JIT 编译,但事实并非如此。尽管 Perl5 程序每次运行时可以进行不同的编译,但这并不能阻止它进行 JITted。因此,如果 Perl5(定义最松散的语言之一)可以进行 JIT 编译,那么为什么 Perl6 不能也是如此。
You imply that Perl5 can't JITted based on "only
perl
can parse Perl5", but that's not true. Even though a Perl5 program can compile differently each time it's run, that doesn't prevent it from JITted.So, if Perl5 —one of the most loosely defined languages— can be JITted, why Perl6 couldn't be too.