note that here and in the subsections that followwe import each pyparsing name that we need individually for examplefrom pyparsing_py import (alphanumsalphascharsnotinforwardgrouphexnumsoneormoreoptionalparseexceptionparsesyntaxexceptionsuppresswordzeroormorethis avoids using the import syntax which can pollute our namespace with unwanted namesbut at the same time affords us the convenience to write alphanums and word(rather than pyparsing_py alphanums and pyparsing_py word()and so on before we finish this quick introduction to pyparsing and look at the examples in the following subsectionsit is worth noting couple of important ideas relating to how we translate bnf into pyparsing parser pyparsing has many predefined elements that can match common constructs we should always use these elements wherever possible to ensure the best possible performance alsotranslating bnfs directly into pyparsing syntax is not always the right approach pyparsing has certain idiomatic ways of handling particular bnf constructsand we should always follow these to ensure that our parser runs efficiently here we'll very briefly review few of the predefined elements and idioms one common bnf definition is where we have an optional item for exampleoptional_item ::item empty bnf if we translated this directly into pyparsing we would writeoptional_item item empty(wrongthis assumes that item is some parser element defined earlier the empty(class provides parser element that can match nothing although syntactically correctthis goes against the grain of how pyparsing works the correct pyparsing idiom is much simpler and involves using predefined elementoptional_item optional(itemsome bnf statements involve defining an item in terms of itself for exampleto represent list of variables (perhaps the arguments to function)we might have the bnfvar_list ::variable variable ',var_list variable ::[ -za- ]\wat first sight we might be tempted to translate this directly into pyparsing syntaxbnf