Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (k - l) lex(1)
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.
lex variable 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 command reads from the
standard input file by default. It can be changed, but because
of the buffering lex 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.
Alternatively, 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.
lex 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 pattern
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).
yyless(n) Returns all but the first n characters of the current token back to the
input stream, where they are rescanned when the scanner looks for
the next match. The yytext and yyleng variables are adjusted
accordingly.
527188-007 Hewlett-Packard Company 5−55