in reply to Basics of parsing (using RTF as a testbed)
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.
|
|---|