TPG is a package which main function is to take a grammar and return a parser1. You only need to import TPG and use these four objects:
The grammar must be in a string (see figure 4.1).
The tpg.compile function produces Python code from the grammar (see figure 4.2).
Then you can use the new generated parser. The parser is now simply a Python class (see figure 4.3).
The tpg script is just a wrapper for the package. It reads a grammar in a file and write the generated code in a Python script. To produce a Python script from a grammar you can use tpg as follow:
tpg [-v|-vv] grammar.g [-o parser.py]
tpg accepts some options on the command line: