One way to learn parsing is to study a working example. First, you need to have a grammar to go by. Without a grammar, parsing becomes an ad-hoc affair. For one example of a parser, you can see AI::Prolog::Parser. That provides the parsing tools used in AI::Prolog::Term::_new_from_parser and AI::Prolog::TermList::_new_from_parser. The grammar is described in AI::Prolog::Builtins. By seeing how the parser provides the tools for parsing and how the Term and TermList modules use the parser to parse themselves, you'll have a fairly decent understanding of one way to parse. Note that my examples are ported from a Java app, so the parsing is much lower level than you are likely to experience in Perl.

Admittedly, this parser is specifically for Prolog programs, but Prolog is easy enough to parse that it's a fairly simple example.

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: Basics of parsing (using RTF as a testbed) by Ovid
in thread Basics of parsing (using RTF as a testbed) by Mugatu

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.