Next: , Previous: , Up: Format   [Contents][Index]


5.2 Format of the Rules Section

The rules section of the flex input contains a series of rules of the form:

    pattern   action

where the pattern must be unindented and the action must begin on the same line. See Patterns, for a further description of patterns and actions.

In the rules section, any indented or %{ %} enclosed text appearing before the first rule may be used to declare variables which are local to the scanning routine and (after the declarations) code which is to be executed whenever the scanning routine is entered. Other indented or %{ %} text in the rule section is still copied to the output, but its meaning is not well-defined and it may well cause compile-time errors (this feature is present for POSIX compliance. See Lex and Posix, for other such features).

Any indented text or text enclosed in ‘%{’ and ‘%}’ is copied verbatim to the output (with the %{ and %} symbols removed). The %{ and %} symbols must appear unindented on lines by themselves.