File: flex.info, Node: Definitions Section, Next: Rules Section, Prev: Format.php">Format, Up: Format.php">Format 5.1 Format of the Definitions Section ===================================== The "definitions section" contains declarations of simple "name" definitions to simplify the scanner specification, and declarations of "start conditions", which are explained in a later section. Name definitions have the form: name definition The 'name' is a word beginning with a letter or an underscore ('_') followed by zero or more letters, digits, '_', or '-' (dash). The definition is taken to begin at the first non-whitespace character following the name and continuing to the end of the line. The definition can subsequently be referred to using '{name}', which will expand to '(definition)'. For example, DIGIT [0-9] ID [a-z][a-z0-9]* Defines 'DIGIT' to be a regular expression which matches a single digit, and 'ID' to be a regular expression which matches a letter followed by zero-or-more letters-or-digits. A subsequent reference to {DIGIT}+"."{DIGIT}* is identical to ([0-9])+"."([0-9])* and matches one-or-more digits followed by a '.' followed by zero-or-more digits. An unindented comment (i.e., a line beginning with '/*') is copied verbatim to the output up to the next '*/'. Any _indented_ text or text enclosed in '%{' and '%}' is also copied verbatim to the output (with the %{ and %} symbols removed). The %{ and %} symbols must appear unindented on lines by themselves. A '%top' block is similar to a '%{' ... '%}' block, except that the code in a '%top' block is relocated to the _top_ of the generated file, before any flex definitions (1). The '%top' block is useful when you want definitions to be evaluated or certain files to be included before the generated code. The single characters, '{' and '}' are used to delimit the '%top' block, as show in the example below: %top{ /* This code goes at the "top" of the generated file. */ #include#include } Multiple '%top' blocks are allowed, and their order is preserved. ---------- Footnotes ---------- (1) Actually, in the C/C++ back end, 'yyIN_HEADER' is defined before the '%top' block.
