News for hackers. Stuff that matters.
Re:Perl Cannot Be Parsed: A Formal Proof (2008) by jrockway on Sunday May 26, 2013 @07:13AM (#5770801)
The article really doesn't prove that Perl can't be parsed, it proves that Perl can't be parsed unambiguously.

The example given is:

    whatever  / 25 ; # / ; die "this dies!";
This can be parsed into two variants without running any code or knowing the arity of whatever.

The case where whatever takes no arguments:

    8  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    7     <2> divide[t3] vK/2 ->8
    5        <1> entersub[t2] sKS/TARG,1 ->6
    -           <1> ex-list sK ->5
    3              <0> pushmark s ->4
    -              <1> ex-rv2cv sK/128 ->-
    4                 <#> gv[*whatever] s ->5
    6        <$> const[IV 25] s ->7
The case where whatever takes a single argument:

    b  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    6     <1> entersub[t2] vKS/TARG,1 ->7
    -        <1> ex-list K ->6
    3           <0> pushmark s ->4
    4           </> match(/" 25 ; # "/) sM/RTIME ->5
    -           <1> ex-rv2cv sK/128 ->-
    5              <#> gv[*whatever] s ->6
    7     <;> nextstate(main 1 -e:1) v:{ ->8
    a     <@> die[t3] vK/1 ->b
    8        <0> pushmark s ->9
    9        <$> const[PV "this dies!"] s ->a
What does this mean practically? If you want to rename "whatever" to something else, you can do that, since the name of the function is captured no matter how many arguments it takes. If you want to lint all your regular expressions, you can do that with the chance that you'll be wrong if you guessed the prototype wrong.

The only thing you can't do is figure out exactly how the code will run at runtime. But if you could do that, you wouldn't have a computer program, you'd just have a lookup table.

Another thing to keep in mind: if a static analysis tool can't understand your code, perhaps the future maintainer can't either. In that case, why not rewrite the code to not be ambiguous?

Re:Perl Cannot Be Parsed: A Formal Proof (2008) by overgard on Sunday May 26, 2013 @07:11PM (#5772763)
> it proves that Perl can't be parsed unambiguously.

That's what can't be parsed means. They're pretty clear about what they mean by something being "parsable", you're muddying that definition to extend it to: "parsable: things that can be vaguely processed most of the time"

Re:Perl Cannot Be Parsed: A Formal Proof (2008) by Vivtek on Sunday May 26, 2013 @08:31AM (#5770933)
This perfectly encapsulates my feelings about the Perl parsing question!

An ambiguous parse is still a parse, and yeah, the 'whatever' example is pathologically unmaintainable code. As you say, if a static parser finds it ambiguous, you should probably fix it.

Re:Perl Cannot Be Parsed: A Formal Proof (2008) by Vivtek on Sunday May 26, 2013 @01:01PM (#5771614)
(Or mark it in some way, you know: "This is ambiguous, but it needs to be because _______" - because frankly, ambiguous parses are destined to be bug sources.)