Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

  (email not shown publicly)

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Wednesday February 19, 2003
10:02 AM

Minimalist Parse::RecDescent tutorial

[ #10663 ]

Okay, so first you write your grammar. You know how to do that, or you wouldn't be looking into Parse::RecDescent in the first place. (Or, at least, if you don't, you'll have to look elsewhere; this "tutorial" is aimed at folks with yacc experience or something.) Rules, colons, etc.. Refer to literal text in double quotes, and regular expressions with slashes. Put the thing in a file.

Now, you can compile your grammar to Perl code with perl -MParse::RecDescent - grammarfile Classname to make a class for your parser object. Use that in your code, create a parser object, and call a method on it named after your starting rule, with the text to parse as the argument. Returns true or false for success or failure.

What do you do after that? I dunno; I haven't gotten that far yet. Really, this entry just exists to express my joy at figuring out and finally trying some of Parse::RecDescent.

Oh, and to relate this back to current events, I'm parsing SQL for fun and experience. Gotta go back to real work, now; experiment is over.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Join the mailing list []!

    And read about spew [] and come up with some more spew grammars!

    • Randal L. Schwartz
    • Stonehenge
    • Ah, yes, that's what next! And then I start a local Parse::RecDescent user's group and plan a talk for the Parse::RecDescent conference. :)

      Hmmm, one day I just need to sit down and dedicate to reading through all those columns you have. There's always so much wonderful stuff there. I probably would've been up and running with P::RD long ago.

      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers