在哪里可以找到Perl编程语言的正式语法? [英] Where can I find a formal grammar for the Perl programming language?

查看:116
本文介绍了在哪里可以找到Perl编程语言的正式语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到Perl语法是模棱两可的,并且它的歧义是很简单的(解决方案

来自 perlfaq7

我可以为Perl语言获得BNF/yacc/RE吗?

没有BNF,但是您可以用脚掌 通过yacc语法 如果在源分布中 你特别勇敢.语法 依靠非常智能的令牌化代码, 因此,准备冒险进入toke.c 也是

用Chaim Frenkel的话说:"Perl的 语法不能简化为BNF.这 解析perl的工作是分布式的 在yacc,lexer,烟和 镜子."

要查看为什么这样的精彩示例,由于上下文的影响,几乎无法解析Perl,请查看 Randal Schwartz的帖子:关于解析Perl

此外,请参见" Perl 5 Internals(第5章.Lexer)中的讨论.和解析器)".


请注意,答案对于Perl6是不同的:

I understand that the Perl syntax is ambiguous and that its disambiguation is non-trivial (sometimes involving execution of code during the compile phase). Regardless, does Perl have a formal grammar (albeit ambiguous and/or context-sensitive)?

解决方案

From perlfaq7

Can I get a BNF/yacc/RE for the Perl language?

There is no BNF, but you can paw your way through the yacc grammar in perly.y in the source distribution if you're particularly brave. The grammar relies on very smart tokenizing code, so be prepared to venture into toke.c as well.

In the words of Chaim Frenkel: "Perl's grammar can not be reduced to BNF. The work of parsing perl is distributed between yacc, the lexer, smoke and mirrors."

To see the wonderful set of examples of WHY it's pretty much near impossible to parse Perl due to context influences, please look into Randal Schwartz's post: On Parsing Perl

In addition, please see the discussion in "Perl 5 Internals (Chapter 5. The Lexer and the Parser)" by Simon Cozens.


Please note that the answer is different for Perl6:

这篇关于在哪里可以找到Perl编程语言的正式语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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