introduction to parsing in generalif python already has suitable parser in the standard libraryor as third-party add-onit is usually best to use it rather than to write our own when it comes to parsing data formats or dsls for which no parser is availablerather than handcrafting parserwe can use one of python' third-party general-purpose parsing modules in this we will introduce two of the most popular third-party parsers one of these is paul mcguire' pyparsing modulewhich takes unique and very pythonic approach the other is david beazley' ply (python lex yacc)which is closely modeled on the classic unix lex and yacc toolsand that makes extensive use of regexes many other parsers are availablewith many listed at www dabeaz com/ply (at the bottom of the page)and of coursein the python package indexpypi python org/pypi this first section provides brief introduction to the standard bnf (backus-naur formsyntax used to describe the grammars of data formats and dsls in that section we will also explain the basic terminology the remaining sections all cover parsing itselfwith the second section covering handcrafted parsersusing regexesand using recursive descentas natural follow-on from the regular expressions the third section introduces the pyparsing module the initial examples are the same as those for which handcrafted parsers are created in the second section--this is to help learn the pyparsing approachand also to provide the opportunity to compare and contrast the section' last example has more ambitious grammar and is new in this section the last section introduces the ply moduleand shows the same examples we used in the pyparsing sectionagain for ease of learning and to provide basis for comparison note that with one exceptionthe handcrafted parsers section is where each data format and dsl is describedits bnf givenand an example of the data or dsl shownwith the other sections providing backreferences to these where appropriate the exception is the first-order logic parser whose details are given in the pyparsing sectionwith corresponding backreferences in the ply section bnf syntax and parsing terminology ||parsing is means of transforming data that is in some structured format--whether the data represents actual dataor statements in programming languageor some mixture of both--into representation that reflects the data' structure and that can be used to infer the meaning that the data represents the parsing process is most often done in two phaseslexing (also called lexical analysistokenizingor scanning)and parsing proper (also called syntactic analysis