the final example we will also see how to handle operators and their precedences and associativities parsing the blocks domain-specific language |handcrafted blocks parser in the previous section' third subsection we created recursive descent parser for blk files in this subsection we will create pyparsing implementation of blocks parser that should be easier to understand and be more maintainable two example blk files are shown in figures ( and ( the bnf for the blocks format is shown in figure ( we will look at the creation of the parser elements in two partsthen we will look at the helper functionand then we will see how the parser is called and at the end we will see how the parser' results are transformed into root block with child blocks (which themselves may contain child blocksetc )that is our required output left_bracketright_bracket map(suppress"[]"new_rows word("/")("new_rows"setparseactionlambda tokenslen(tokens new_rows)name charsnotin("[]/\ ")("name"setparseactionlambda tokenstokens name strip()color (word("#"hexnumsexact= word(alphasalphanums))("color"empty_node (left_bracket right_bracketsetparseactionlambdaemptyblockas always with pyparsing parserswe create parser elements to match the bnf from last to first so that for every parser element we create that depends on one or more other parser elementsthe elements it depends on already exist the brackets are an important part of the bnfbut are of no interest to us for the resultsso we create suitable suppress(parser elements for them for the new_rows parser element it might be tempting to use literal("/")--but that must match the given text exactly whereas we want to match as many / as are present having created the new_rows parser elementwe give name to its results and add parsing action that replaces the string of one or more / with an integer count of how many / there were notice also that because we gave name to the resultwe can access the result ( the matched text)by using the name as an attribute of the tokens object in the lambda the name parser element is slightly different from that specified in the bnf in that we have chosen to disallow not only brackets and forward slashesbut also newlines againwe give the result name we also set parse actionthis ply blocks parser