Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.™


In reply to Re: RFC: Parsing with perl - Regexes and beyond by sundialsvc4
in thread RFC: Parsing with perl - Regexes and beyond by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found