Re: Parse::RecDescent and need for speed (eq Parse::Yapp)
by grinder (Bishop) on Feb 16, 2005 at 08:26 UTC
|
If I was to use Parse::RecDescent, would it go faster?
Parse::RecDescent is known to be slow. So much so that Damian Conway want(?:ed|s) to write Parse::RecDescent::Fast. Or something like that.
Another alternative is to use Parse::Yapp (Yet Another Perl Parser). I haven't used it personally, but a number of people who have have appreciated the speed. They have also appreciated less, the fact that it is drop-in compatible with yacc(1). No-one knows yacc anymore. stefp was threatening a while back to write a front-end to P::Y to get it to accept P::RD's input, but I don't know if he got round to doing so.
- another intruder with the mooring in the heart of the Perl
| [reply] |
Re: Parse::RecDescent and need for speed
by VSarkiss (Monsignor) on Feb 15, 2005 at 22:48 UTC
|
If I was to use Parse::RecDescent, would it go faster? Maybe.
(is Parse::RecDescent all in perl?) Yes, but that may be irrelevant.
Before proceeding, you may want to try figuring out exactly where your file parsing script is spending its time. Packages like Devel::Timer and Devel::Profiler can help with that. The thing is that you may be surprised by the results -- the slow part may not be your parsing logic, but something else.
| [reply] |
|
it's in the functions where I am processing comment statements
| [reply] |
|
my script tries to preserve the whole file within a structure hash , including comments.
| [reply] |
|
Re: Parse::RecDescent and need for speed
by kvale (Monsignor) on Feb 15, 2005 at 23:41 UTC
|
Personally, I find that code generated by Parse::RecDescent is generally slower than a hand-coded recursive descent parser. But such comparisons really depend on the skill of the programmer.
Without seeing your language, grammar, or parser, I can't give any specific advice. In perl top-down parsers, nonterminals in your grammar generally correspond to functions and terminals to regular expressions. So eating comments should be a pretty fast operation. An excellent book on parsers and compilers is Compilers: Principles, Techniques, and Tools, by Aho, Sethi and Ullman.
| [reply] |
|
Also, keep in mind that Parse::RecDescent parses by "nibbling", which is very expensive for large strings. At one point, theDamian said he would rewrite it to use pos (which wasn't available in 5.004 when he wrote PRD), but has since gotten distracted by other things.
| [reply] |
|
At one point, theDamian said he would rewrite it to use pos (which wasn't available in 5.004 when he wrote PRD)
Bull. pos was available in 5.000, as the
perl5.000 manual will tell you.
| [reply] |
|
|
|
|
At one point, theDamian said he would rewrite it to use pos (which wasn't available in 5.004 when he wrote PRD)
First non-comment, non-whitespace line of Parse::RecDescent:
use 5.005;
| [reply] [d/l] |
|