introduction to parsing sociativities and will set the precedences from lowest (first tuple in the listto highest (last tuple in the listfor unary operatorsassociativity isn' really an issue for ply (although it can be for pyparsing)so for not we could have used "nonassocand the parsing results would not be affected at this point we have the tokensthe lexer' functionsthe parser' functionsand the precedence variable all set up now we can create ply lexer and parser and parse some text lexer ply lex lex(parser ply yacc yacc(tryreturn parser parse(textlexer=lexerexcept valueerror as errprint(errreturn [this code parses the formula it is given and returns list that has exactly the same format as the lists returned by the pyparsing version (see the end of the subsection on the pyparsing first-order logic parser to see examples of the kind of lists that the parser returns ply tries very hard to give useful and comprehensive error messagesalthough in some cases it can be overzealous--for examplewhen ply creates the firstorder logic parser for the first timeit warns that there are " shift/reduce conflictsin practiceply defaults to shifting in such casessince that' usually the right thing to doand is certainly the right action for the first-order logic parser the ply documentation explains this and many other issues that can ariseand the parser' parser out file which is produced whenever parser is created contains all the information necessary to analyze what is going on as rule of thumbshift/reduce warnings may be benignbut any other kind of warning should be eliminated by correcting the parser we have now completed our coverage of the ply examples the ply documentation (www dabeaz com/plyprovides much more information than we have had space to convey hereincluding complete coverage of all of ply' features including many that were not needed for this examples summary ||for the simplest situations and for nonrecursive grammarsusing regexes is good choice--at least for those who are comfortable with regex syntax another approach is to create finite state automata--for exampleby reading the text character by characterand maintaining one or more state variables-in pyparsingprecedences are set the other way upfrom highest to lowest