News for hackers. Stuff that matters.
Re:Perl Cannot Be Parsed: A Formal Proof (2008) by avar on Sunday June 14, 2015 @07:36AM (#9714525)
The gist of this is that perl's parser depends on previously symbols that are already defined to figure out how to parse things.

The same goes for languages like C, but the difference is that in perl you can define symbols at compilation time as a result of running other code, e.g.:

    $ perl -wE 'BEGIN { eval "sub spew { say \@_ }" if time % 2 == 0 } spew "hello"'
    hello
    $ perl -wE 'BEGIN { eval "sub spew { say \@_ }" if time % 2 == 0 } spew "hello"'
    Unquoted string "spew" may clash with future reserved word at -e line 1.
Here the program can be syntactically correct or incorrect depending on the compilation time.
Re:Perl Cannot Be Parsed: A Formal Proof (2008) by dagw on Sunday June 14, 2015 @07:54AM (#9714566)
for what it's worth the same 'problem' exists in python and probably most other similar languages.

edit: here's the same code in python

  from time import time
  if round(time())%2==0:
      exec("def spew(x): print x")
  spew("hello")
Re:Perl Cannot Be Parsed: A Formal Proof (2008) by ceronman on Sunday June 14, 2015 @11:24AM (#9715182)
It's not the same thing. In Python this is a run-time error. The code you posted is parsed and compiled to byte-code just fine. Then, depending on the time, a new function is created dynamically at run-time or a NameError is raised at run-time.

In Python and other dynamic languages the compilation part is very simple, the code is parsed (the grammar is very simple) and converted to byte-code. Then the byte-code is executed. Things like function and class definitions happen at run-time, not at compile-time.

In Perl 5, the line between compilation-time and run-time is very fuzzy. It doesn't have a simple grammar that you can use to convert Perl to op-code. You can run code at compilation-time and change the way the compiler interprets things.

Re:Perl Cannot Be Parsed: A Formal Proof (2008) by avar on Sunday June 14, 2015 @09:44AM (#9714849)
As the sibling points out this isn't quite like what you have in Perl. In this case the python code will be parsed the same way. The difference with Perl is that depending on previously defined symbols something might parse as a function call, an indirect method call etc.

This comment in the perl parser describes some of the beginnings of that rabbit hole: http://perl5.git.perl.org/perl.git/blob/70f63a4c7dba89e8e48b...

Re:Perl Cannot Be Parsed: A Formal Proof (2008) by bartbes on Sunday June 14, 2015 @08:10AM (#9714602)
Except that doesn't change the way 'spew("hello")' is parsed, as far as I know. The 'proof' given for perl actually means you can't fully parse the file without also running it.