Chapter 11
Structure of the package
11.1 General structure of the package
TPG is delivered in a Python package named tpg. It is composed of:
-
__init__.py
- turns tpg directory into a package. It defines some data about the current release
(version, author, ...) and it imports in its local namespace the five useful objects compile,
translate, LexerError, ParserError and SemanticError.
-
base.py
- defines the base class of the generated parsers and other classes used by these parsers.
It’s a kind of runtime for the parsers.
-
codegen.py
- contains the classes used by the parser to represent the AST corresponding to the
parsed grammar. Theses classes have the necessary methods for code generation.
-
parser.g
- contains the grammar that recognizes TPG grammars. It defines the syntax of TPG
grammars and builds the AST of the grammar.
-
parser.py
- is automatically generated by TPG itself from parser.g.
-
Release.py
- contains release data (version, author, ...).
-
tpg
- is a wrapper script for TPG. It reads a grammar and produces a Python script.