now that we have passing familiarity with bnf syntax and with some of the terminology used in parsingwe will write some parsersstarting with ones written by hand writing handcrafted parsers ||in this section we will develop three handcrafted parsers the first is little more than an extension of the key-value regex seen in the previous but shows the infrastructure needed to use such regex the second is also regex-basedbut is actually finite state automata since it has two states both the first and second examples are data parsers the third example is parser for dsl and uses recursive descent since the dsl allows expressions to be nested in later sections we will develop new versions of these parsers using pyparsing and plyand for the dsl in particular we will see how much easier it is to use generic parser generator than to handcraft parser simple key-value data parsing |the book' examples include program called playlists py this program can read playlist in (extended moving picture experts group audio layer uniform resource locatorformatand output an equivalent playlist in pls (play list format--or vice versa in this subsection we will write parser for pls formatand in the following subsection we will write parser for format both parsers are handcrafted and both use regexes the pls format is essentially the same as windows ini formatso we ought to use the standard library' configparser module to parse it howeverthe pls format is ideal for creating first data parsersince its simplicity leaves us free to focus on the parsing aspectsso for the sake of example we won' use the configparser module in this case we will begin by looking at tiny extract from pls file to get feel for the datathen we will create bnfand then we will create parser to read the data the extract is shown in figure we have omitted most of the data as indicated by the ellipsis there is only one ini-style header line[playlist]with all the other entries in simple key=value format one unusual aspect is that key names are repeated--but with numbers appended to keep them all unique three pieces of data are maintained for each songthe filename (in this example using windows path separators)the titleand the duration (called "length"in seconds in this particular examplethe first song has known durationbut the last entry' duration is unknownwhich is signified by negative number pyparsing keyvalue parser ply keyvalue parser