are straightforward to definewe've just used group(to make them sublists within the results list to keep their components together and at the same time distinct as unit the operatorprecedence(function (which really ought to have been called something like createoperators()creates parser element that matches one or more unarybinaryand ternary operators before calling itwe first specify what our operands are--in this case forall_expression or an exists_expression or boolean or term the operatorprecedence(function takes parser element that matches valid operandsand then list of parser elements that must be treated as operatorsalong with their arities (how many operands they take)and their associativities the resultant parser element (in this caseformulawill match the specified operators and their operands each operator is specified as threeor four-item tuple the first item is the operator' parser elementthe second is the operator' arity as an integer ( for unary operator for binary operatorand for ternary operator)the third is the associativityand the fourth is an optional parse action pyparsing infers the operatorsorder of precedence from their relative positions in the list given to the operatorprecedence(functionwith the first operator having the highest precedence and the last the lowestso the order of the items in the list we pass is important in this examplehas the highest precedence (and has no associativityso we have made it left-associative)and -has the lowest precedence and is right-associative this completes the parserso we can now look at how it is called tryresult formula parsestring(textparseall=trueassert len(result= return result[ aslist(except (parseexceptionparsesyntaxexceptionas errprint("syntax error:\ { line}\ { }^format(err(err column ))this code is similar to what we used for the blocks example in the previous subsectiononly here we have tried to give more sophisticated error handling in particularif an error occurs we print the line that had the error and on the line below it we print spaces followed by caret (^to indicate where the error was detected for exampleif we parse the invalid formulaforall xx truewe will getsyntax errorforall xx true