Chapter 8: Generated files

Flexc++ generates 4 files:

  1. lex.cc
  2. scanner.h
  3. scanner.ih
  4. scannerbase.h

lex.cc and scannerbase.h are overwritten every time flexc++ is called, while scanner.h and scanner.ih are written either when they do not exist, or when flexc++ is explicitly told to overwrite one of these files.

The above filenames are the defaults, and can be changed by the following options:

  1. %option lexsource="lex.cc"
  2. %option classheader="scanner.h"
  3. %option implementationheader="scanner.ih"
  4. %option baseclassheader="scannerbase.h"

The manual refers to these files by their default filenames.

The contents for these files are taken from skeleton files. It is possible to install any of these skeletons in a separate location and tell flexc++ to use this alternative location. This allows one to make changes to the default sources. This is usually not needed for most users.

The first file, lex.cc contains lookup tables, the code to walk through the lookup tables and the actions specified in the lexer file. Since the lookup tables and actions (possibly) change every time flexc++ is called, lex.cc is overwritten on each invocation.

The file scannerbase.h contains the base classes for the final Scanner class and the enum of start conditions. The Scanner class is derived from ScannerBase, which is derived from ScannerTemplate. ScannerBase specifies the exact StreamInfoType to instantiate ScannerTemplate with (see also the multiple streams chapter 9). Since this StreamInfoType and the start conditions can change, scannerbase.h is overwritten every time flexc++ is invoked.

The other two files scanner.h and scanner.ih are usually not touched by flexc++ (unless explicitly specified). scanner.h contains the final Scanner class, which the user is encouraged to modify. Additional members can be added here.

One can adjust the behaviour of lex() and executeAction() (this last function is a private function which is called whenever an action is to be executed). This allows the user to execute some extra code before or after the default behaviour of lex() and executeAction().

Also, extra constructors, or extra functionality to the default constructors can be added in scanner.h.

Finally, scanner.ih contains some declarations which are used by the implementations of the Scanner members. One can place using statements here as well as includes which are only required by member implementations.