The basic parser tools of repetition, sequence, and alternation are sufficient for building an infinite variety of parsers. You may find that you never need to extend this fundamental suite of tools. However, cases do arise in which new parser types are needed, and this section looks at several ways to extend the parser hierarchy. The most common need is for a new type of terminal. For example, a new terminal might distinguish an integer from a floating point number, or a lowercase word from an uppercase word. You may also need to adjust the tokenizer to change how it forms elements, and in conjunction create one or more new Terminal subclasses that recognize the new token types. In general, there is no way to predict the new types of parsers you might want to create. This section includes an example that shows how to add a new kind of sequence that complains intelligently when it fails to find the conclusion of a sequence. The sections that follow cover three ways in which you may want to extend the parser hierarchy: creating a new subclass of Terminal , creating a new token or terminal design, and creating a completely new parser type. |