although this can lead to if statements with lots of elifs and nested if elifs that can be difficult to maintain for more complex grammarsand those that are recursivepyparsingplyand other generic parser generators are better choice than using regexes or finite state automataor doing handcrafted recursive descent parser of all the approachespyparsing seems to require the least amount of codealthough it can be tricky to get recursive grammars rightat least at first pyparsing works at its best when we take full advantage of its predefined functionality--of which there is quite lot more than we covered in this -and use the programming patterns that suit it this means that in more complex cases we cannot simply translate bnf directly into pyparsing syntaxbut must adapt the implementation of the bnf to fit in with the pyparsing philosophy pyparsing is an excellent moduleand it is used in many programming projects ply not only supports the direct translation of bnfsit requires that we do thisat least for the ply yacc module it also has powerful and flexible lexer which is sufficient in its own right for handling many simple grammars ply also has excellent error reporting ply uses table-driven algorithm that makes its speed independent of the size or complexity of the grammarso it tends to run faster than parsers that use recursive descent such as pyparsing one aspect of ply that may take some getting used to is its heavy reliance on introspectionwhere both docstrings and function names have significance nonethelessply is an excellent moduleand has been used to create some complex parsersincluding ones for the and zxbasic programming languages although it is generally straightforward to create parser that accepts valid inputcreating one that accepts all valid input and rejects all invalid input can be quite challenge for exampledo the first-order logic parsers in this last section accept all valid formulas and reject all invalid onesand even if we do manage to reject invalid inputdo we provide error messages that correctly identify what the problem is and where it occurredparsing is large and fascinating topicand this is designed to introduce the very basicsso further reading and practical experience are essential for those wanting to go further one other point that this hints at is that as large and wide-ranging as python' standard library ismany high-qualitythird-party packages and modules that provide very useful additional functionality are also available most of these are available through the python package indexpypi python org/pypibut some can only be discovered using search engine in generalwhen you have some specialized need that is not met by python' standard libraryit is always worth looking for third-party solution before writing your own