Parse::RecDescent

Chapter 7 - Great CPAN Modules
by?Sam Tregar?
Apress ? 2002
has companion web siteCompanion Web Site

No discussion of great CPAN modules would be complete without at least one module by the "Mad Scientist of Perl", Dr. Damian Conway.[25] His Parse::RecDescent module generates recursive descent parsers from a vaguely yacc-like grammar. If you've never used yacc, the concept is simple: you write a description of the grammar you want to parse and the parser compiler, yacc, generates an executable parser that will parse your grammar. Parse::RecDescent extends this concept in a number of directions that allow the grammar writer far more freedom of expression than yacc.

Parse::RecDescent's interface is superficially object oriented-parser objects are instantiated by passing the grammar to Parse::RecDescent->new(). The returned parser object has methods to parse input text. However, the real interface to Parse::RecDescent is in the grammar. The syntax of Parse::RecDescent grammars is essentially an entirely new programming language designed specifically for building parsers that interact with Perl. The advantage of this approach over an entirely object-oriented interface are brevity and flexibility.

The success of Parse::RecDescent is largely the usual mix of a common problem and an efficient solution. However, like many of Damian's modules, it is also an enjoyable technical challenge for the user. Learning to use Parse::RecDescent is fun in and of itself; the fact that it helps you solve parsing problems too can seem almost secondary!

The most common complaint about Parse::RecDescent is that it's too slow and uses too much memory. My opinion is that for what Parse::RecDescent accomplishes, it's amazing that it uses as few resources as it does. However, to answer these critiques, Damian is hard at work on a completely new module, Parse::FastDescent, which may be available as you read this. If it is, I heartily recommend you check it out, whether you have some parsing to do or not! It's sure to be a mind-bending experience.

[25]See Dr. Damian Conway's sites at http://www.cs.monash.edu.au/~damian and http://www.yetanother.org/damian/.



Writing Perl Modules for CPAN
Writing Perl Modules for CPAN
ISBN: 159059018X
EAN: 2147483647
Year: 2002
Pages: 110
Authors: Sam Tregar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net