introduction to parsing exists keyword("exists"implies literal("->"or_ literal("|"and_ literal("&"not_ literal("~"equals literal("="boolean keyword("false"keyword("true"symbol word(alphasalphanumsall the parser elements created here are straightforwardalthough we had to add underscores to the end of few names to avoid conflicts with python keywords if we wanted to give users the choice of using ascii or the proper unicode symbolswe could change some of the definitions for exampleforall keyword("forall"literal(""if we are using non-unicode editor we could use the appropriate escaped unicode code pointsuch as literal("\ ")instead of the symbol term forward(term <(group(symbol group(left_parenthesis delimitedlist(termright_parenthesis)symbola term is defined in terms of itselfwhich is why we begin by creating it as forward(and rather than using straight translation of the bnf we use one of pyparsing' coding patterns recall that the delimitedlist(function returns parser element that can match list of one or more occurrences of the given parser elementseparated by commas (or by something else if we explicitly specify the separatorso here we have defined the term parser element as being either symbol followed by comma-separated list of terms or symbol--and since both start with the same parser element we must put the one with the longest potential match first formula forward(forall_expression group(forall symbol colon formulaexists_expression group(exists symbol colon formulaoperand forall_expression exists_expression boolean term formula <operatorprecedence(operand(equals opassoc left)(not_ opassoc right)(and_ opassoc left)(or_ opassoc left)(implies opassoc right)]although the formula looks quite complicated in the bnfit isn' so bad in pyparsing syntax first we define formula as forward(since it is defined in terms of itself the forall_expression and exists_expression parser elements