As a parser recognizes a string, it usually performs a corresponding function, translating the string into a meaningful result. This work forms the semantics, or meaning, that the parser brings to a language.
The methods that perform a parser's work must appear as methods of a class. This book places such methods in subclasses of an Assembler class. To allow a parser to build a meaningful result, a Parser object collaborates with Assembler objects that know which work to perform as a parser recognizes parts of a string.
The results of a parser's work must, logically, produce or modify objects. This book associates work areas with the text to recognize Assembly subclasses. A Parser object uses Assembly objects to record the progress of Assembler objects.
Figure 2.1 shows the three main classes that are used to make practical parsers. These classes complement the Parser class hierarchy with Assembly and Assembler hierarchies. The following summarizes the roles of these three classes.
Figure 2.1. The three main classes that collaborate to create a working parser are Parser , Assembly , and Assembler .
A parser is an object that recognizes a language.
An assembler helps a parser build a result.
An assembly provides a parser with a work area.
Objects of these three classes collaborate to recognize an element of a language and to perform work based on the recognition.
This diagram is consistent with the Unified Modeling Language [Booch], as are most of the diagrams in this book. Appendix A explains the features of the Unified Modeling Language that this book applies.