gpt4 book ai didi

perl - 在哪里可以找到 Perl 编程语言的正式语法?

转载 作者:行者123 更新时间:2023-12-03 13:17:47 24 4
gpt4 key购买 nike

我知道 Perl 语法是模棱两可的,并且它的消歧是不平凡的( sometimes involving execution of code during the compile phase )。无论如何,Perl 是否有正式的语法(尽管是模棱两可的和/或上下文相关的)?

最佳答案

来自 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."



要查看为什么由于上下文影响几乎不可能解析 Perl 的精彩示例,请查看 Randal Schwartz's post: On Parsing Perl

此外,请参阅 Simon Cozens 在“ Perl 5 Internals (Chapter 5. The Lexer and the Parser)”中的讨论。

请注意 answer is different for Perl6:
  • a grammar for Perl6
  • Rakudo Perl 有 its own version of the grammar
  • 关于perl - 在哪里可以找到 Perl 编程语言的正式语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4625408/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com