Parse::RecDescent (RD) looks like the best parsing option in Perl for me, for two reasons. First, it is very lightweight - only one .pm file to carry around. Second, I like recursive descent parsing :-) RD parsing is, IMHO, easier to visualize and understand. Looking at the grammar (BNF) it is immediately obvious how each rule will be parsed given the input. This is very nice for grammar debugging.

Yesterday was my first serious experience with the RD module (historically, I did a lot of Yacc (in C), and coded some simple recursive descent parsers by hand). The module works nicely, and is easy to learn and understand. Some notable differences from Yacc:

  1. Integrated lexing. Very nice ! It looks much more natural this way, and there's no need for extra headache with Lex linkage. Tokens are defined as simple regex rules in the grammar itself.
  2. Some little things that make life easier and more pleasant. For example, the rule quantifiers (s), (s?) etc.
  3. Left recursion problem. Hits blatantly when arithmetic expressions must be parsed. A different mindset must be employed when comparing with Yacc.
Additionally, RD has a very useful trace option, that traces parsing and allows to see where things went wrong with the grammar.

Comments

comments powered by Disqus