![]() |
|
Perl: the Markov chain saw | |
PerlMonks |
On Parsing Perlby merlyn (Sage) |
on Dec 04, 2000 at 04:21 UTC ( #44722=perlmeditation: print w/replies, xml ) | Need Help?? |
{from an alt.perl post I just made, reposted here to solicit feedback from fellow monks...}
Perl is extremely difficult to parse. In fact, some would say impossible. One thing that makes it difficult is the dual nature of a half dozen characters like "/". If that / is being used in a place that's expecting an operator, it's divide. If it's being used in a place that's expecting an operand, it's the beginning of a regular expression. So you have to keep track at all times of whether you're looking for an operator or an operand. "No problem", you say? Quick... for the following, play the game of "regex or divide?" Got those right? How about these? OK, and now some of your own: Got those too? How about these (same problem, different file): A little harder, eh? So now you have to parse OUTSIDE the file to get your answer. And as if that wasn't enough, let's get weird: Quick, was that last one a divide or a regex start? Why does it matter? Look at this: The first one is computing the sin of the true/false value gotten by matching " 25 ; # " against $_. Then it dies. The second one is computing the time of day divided by 25, then ignoring the comment. Starting to see the trouble? This leads people to say "the only thing which can parse Perl (the language) is perl (the binary)". Maybe not for Perl6. But for the Perl we know and can use today, certainly so. -- Randal L. Schwartz, Perl hacker
Back to
Meditations
|
|