Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
User Commands (d - f) flex(1)
action Each pattern in a rule has a corresponding action, which can be any arbitrary C
statement. The pattern ends at the first nonescaped white space character; the
remainder of the line is its action. If the action is empty, then when the pattern is
matched, the input that matched it is discarded.
If the action contains a {, then the action scans till the balancing } is found, and
the action may cross multiple lines. Using a return statement in an action returns
from yylex().
An action consisting solely of a vertical bar (|) means same as the action for the
next rule.
flex variables that can be used within actions are:
yytext Is a string (char *) containing the current matched input. It
cannot be modified.
yyleng Is the length (int) of the current matched input. It cannot be
modified.
yyin Is a stream (FILE *) that the lex and flex commands reads from
the standard input file by default. It can be changed, but
because of the buffering flex uses, changing the stream makes
sense only before scanning begins. Once scanning terminates
because an End-of-File was found, void yyrestart (FILE
*new_file) can be called to point yyin at a new input file. Alter-
natively, yyin can be changed whenever a new or different
buffer is selected (see yy_switch_to_buffer()).
yyout Is a stream (FILE *) to which ECHO output is written (the
standard output file by default). It can be changed by the user.
YY_CURRENT_BUFFER
Returns the current buffer (YY_BUFFER_STATE) used for
scanner input.
flex macros and functions that can be used within actions are:
ECHO Copies the yytext variable to the scanner’s output.
BEGIN state
Changes the scanner state to be state. This affects which rules are
active. The state must be defined in a %s or %x definition. The ini-
tial state of the scanner is INITIAL or 0 (zero).
REJECT Directs the scanner to proceed immediately to the
next best pa
ttern
that matches the input (which may be a prefix of the current match).
The yytext and yyleng variables are reset appropriately. Note that
REJECT is a particularly expensive feature in terms of scanner per-
formance; if it is used in any of the scanner’s actions, it slows down
all the scanner’s pattern matching operations. REJECT cannot be
used if the command is invoked with either the -f or -F flag.
yymore() Indicates that the next matched text should be appended to the
currently matched text in the yytext variable (rather than replace it).
527188-021 Hewlett-Packard Company 3−153