3 ms·
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 ; # /
by jrockway 13y ago
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?
- Vivtek 13y agoThis 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.
- Vivtek 13y ago(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.)
- overgard 13y ago> 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"