in reply to Parse::RecDescent and perlcc ?

If you're building an assembler, and the syntax is line based, you'll get a speed-up by parsing each line individually, rather than as one big file.

The reason is that P::RD performs the equivalent of:

s/^$syntax_I_recognize// && do { &Action_for_syntax };
And it does this for everything, over and over again. This "nibbling" approach is great for short strings, but for long strings, there's a whole lot of string copying going on.

theDamian said that a significant speedup would have been realized by changing these to:

/\G$syntax_I_recognize/gc && do { &Action_for_syntax };
and letting pos() walk through the string, but alas never got the time to change P::RD into Parse::FastDecent (this would have been the basic change).

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Parse::RecDescent and perlcc ?
by bear_hwn (Acolyte) on May 29, 2003 at 19:16 UTC
    it's not a classic assembler syntax and my language is not line based: the machine i am programming has several compute units and multiple address units going simultaneously, so i adopted a c-like syntax where whitespace doesn't count. (5-8 lines of source code per instruction are not uncommon.) hopefully, the pre-compile approach will buy me decent speed up. many thanks to all!
      the pre-compilation of the grammar helps quite a bit: the startup time is much shorter, though still long, and i can now see the processing time per instruction. with my grammar separated for precompilation, i decided to try perlcc again on my little bit of user interface and the inclusion of the precompiled grammar module - the result was the same sort of "it failed to compile, but that is not possible!" error message. does anybody know of a documented case where Parse::RecDescent has actually been compiled with perlcc, or am i chasing a willo' the wisp? thanks in advance.