Next: , Previous: Editing grammars, Up: Working with grammars


4.2 Auto-generation of lexical rules

Using a %type statement, combined with %keyword and %token ones, permits the declaration of a lexical type and associates it with patterns that define how to match lexical tokens of that type.

The grammar construction process exploits that information to automagically generate the definition of a lexical rule (aka a single analyzer) for each explicitly declared lexical type.

It is then easy to put predefined and auto-generated lexical rules together to build ad-hoc lexical analyzers.

This chapter details the auto-generation process, and how you can control it to produce the lexical rules needed to scan your language.