in reply to Re: Re: Re: Re: Appropriate CPAN namespace for perl parser
in thread Appropriate CPAN namespace for perl parser
But if I understand some of the docs correctly, even perl itself doesn't really know what everything is, it guesses based on heuristicsBut it doesn't guess! It knows precisely. And for you to properly parse Perl, you must emulate those precisely.
There's very little statistical guessing in /usr/bin/perl. About the only two things is the hash-element vs. scalar-followed-by-char-class thingy in a regex, and the "is this a block or a hashref" in certain places that might have either. Everything else is deterministic. Your code must do it right, or it's not parsing Perl as perl would.
Put another way, I know that since sin takes an argument, that if I use slash following it, it's a regex-start. It's never a divide. I can tell that without running it or debugging it. And if I put a double-less-than, it's a here doc. It's never a left shift. But if I replace sin with time, the exact opposite choices are taken.
You cannot guess. To parse Perl, you must know at all times whether you are in a place expecting a value or a place expecting an operator. And to do that, you have to know the prototype of all the built-ins, and how to get the prototype of all the user-defined functions. Which also means you have to step along with the code, executing all the BEGIN blocks, including those spelled u-s-e.
This is not a simple task. Larry admits it. Damian was going to spend the better part of this year working on Parse::Perl as a YAS-funded project. If you are taking it on, but not aware of the things I've posted in this thread, it's a bit like saying "I can fly that plane", but just getting in, without realizing there are clouds and bad weather and other planes, and that landing can be a real pain sometimes, and what happens when the engines go out.
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: But perl is not guessing!
by adamk (Chaplain) on Feb 13, 2002 at 13:41 UTC | |
by merlyn (Sage) on Feb 13, 2002 at 13:46 UTC | |
by adamk (Chaplain) on Feb 13, 2002 at 13:48 UTC | |
by demerphq (Chancellor) on Feb 14, 2002 at 16:39 UTC | |
|
Re: But perl is not guessing!
by Smylers (Pilgrim) on Feb 13, 2002 at 13:39 UTC |