我知道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)”中的讨论。
请注意07003
>有a grammar for Perl6
> Rakudo Perl有its own version of the grammar