Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: RFC: Parsing with perl - Regexes and beyond

by sundialsvc4 (Abbot)
on Apr 03, 2008 at 14:22 UTC ( #678171=note: print w/replies, xml ) Need Help??

in reply to RFC: Parsing with perl - Regexes and beyond

You may or may not find that “recursive descent” parsing is right for you. Recursive-descent is very appropriate when there's a lot to do at each point, and the structure of the input-language is very consistent and predictable. Cases where the input is, if you will, “heavy and full of meaning.”

But there is another approach that is sometimes quite useful:   it's a more grammar-driven, state-table-driven approach, the one used by bison or yacc, in which a grammar-following engine is chugging through its internal description of the language, building trees (“hashes and lists of hashes and lists”) along the way, and calling-out to your code as pure subroutines along the way.

In this scenario, that “grammar-following engine” is driving the bus for the entire time. It calls-out to you at the prescribed times, passing your routines the information they're supposed to receive, and expecting each routine to mind its own business. The complexities of the language being processed are not represented in (nor should they be represented in) the discrete subroutines that you write... unlike recursive-descent, where more-or-less the opposite is true.

Which is “better?” That question can't be answered categorically: “it depends.” It's enough to know that in Perl both approaches are available to you. Each approach is distinct, and each approach is distinct for a to-it appropriate reason. That's why you get to choose.

This is, or can be, a very deep pool ... but don't go any deeper than you actually need to go, unless you're curious and you've brought your life-jacket with you.

I applaud this piece because ... parsers are an extremely powerful technology that you need to become aware-of. I'm not quite sure why they get relegated to the cloistered halls of graduate-school. They're actually relatively straightforward these days. So... if you're wrestling your way through “regular expression hell,” remember that ... especially in Perl-land ... There's More Than One Way To Do It.™

  • Comment on Re: RFC: Parsing with perl - Regexes and beyond

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://678171]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-10-31 23:09 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (291 votes). Check out past polls.