words in the input and call the routine special() whenever "frob" is seen:
.nf
- %{
- int word_count = 0;
- %}
+ int word_count = 0;
%%
frob special(); REJECT;
of the scanner's actions it will slow down
.I all
of the scanner's matching.
+.IP
+Note also that unlike the other special actions,
+.B REJECT
+is a
+.I branch;
+code immediately following it in the action will
+.I not
+be executed.
.IP -
.B yymore()
tells the scanner that the next time it matches a rule, the corresponding
is matched, but the previous "mega-" is still hanging around at the
beginning of
.B yytext
-so the ECHO for the "kludge" rule will actually write "mega-kludge".
+so the
+.B ECHO
+for the "kludge" rule will actually write "mega-kludge".
The presence of
.B yymore()
in the scanner's action entails a minor performance penalty in the
"foobarbar":
.nf
+ %%
foobar ECHO; yyless(3);
[a-z]+ ECHO;
.fi
An argument of 0 to
.B yyless
-will cause the current input string to be scanned again. Unless you've
+will cause the entire current input string to be scanned again. Unless you've
changed how the scanner will subsequently process its input (using
.B BEGIN,
for example), this will result in an endless loop.
.fi
.IP -
-.I yyterminate()
+.B yyterminate()
can be used in lieu of a return statement in an action. It terminates
the scanner and returns a 0 to the scanner's caller, indicating "all done".
+Subsequent calls to the scanner will immediately return unless preceded
+by a call to
+.B yyrestart()
+(see below).
By default,
-.I yyterminate()
+.B yyterminate()
is also called when an end-of-file is encountered. It is a macro and
may be redefined.
.SH THE GENERATED SCANNER
#define YY_DECL float lexscan( a, b ) float a, b;
.fi
-to give it the the scanning routine the name
+to give the scanning routine the name
.I lexscan,
returning a float, and taking two floats as arguments. Note that
if you give arguments to the scanning routine using a
.B yylex()
is called, it scans tokens from the global input file
.I yyin
-(default, stdin). It continues until it either reaches
+(which defaults to stdin). It continues until it either reaches
an end-of-file (at which point it returns the value 0) or
one of its actions executes a
.I return
statement.
-In the former case, the scanner may not be called again unless
-.B void yyrestart( FILE *input_file )
-is called, to point
+In the former case, when called again the scanner will immediately
+return unless
+.B yyrestart()
+is called to point
.I yyin
-at the new input_file. In the latter case (i.e., when an action
+at the new input file. (
+.B yyrestart()
+takes one argument, a
+.B FILE *
+pointer.)
+In the latter case (i.e., when an action
executes a return), the scanner may then be called again and it
will resume scanning where it left off.
.LP
either the
number of characters read or the constant YY_NULL (0 on Unix systems)
to indicate EOF. The default YY_INPUT reads from the
-global file-pointer "yyin" (which is by default
-.I stdin),
-so if you
+global file-pointer "yyin", so if you
just want to change the input file, you needn't redefine
-YY_INPUT - just point yyin at the input file.
+YY_INPUT - just point yyin at the input file (by assigning it to the
+file pointer returned by
+.B fopen(),
+for example).
.LP
-A sample redefinition of YY_INPUT (in the definitions section of the input
-file):
+A sample redefinition of YY_INPUT (in the definitions
+section of the input file):
.nf
%{
When the scanner receives an end-of-file indication from YY_INPUT,
it then checks the
.B yywrap()
-function. If it returns false (zero), then it is assumed that the
+function. If
+.B yywrap()
+returns false (zero), then it is assumed that the
function has gone ahead and set up
.I yyin
to point to another input file, and scanning continues. If it returns
The default
.B yywrap()
always returns 1. Presently, to redefine it you must first
-"#undef yywrap", as it is currently implemented as a macro. As noted
+"#undef yywrap", as it is currently implemented as a macro. As indicated
by the hedging in the previous sentence, it may be changed to
a true function in the near future.
.LP
output to the
.I yyout
global (default, stdout), which may be redefined by the user simply
-by assigning it to some other FILE*.
+by assigning it to some other
+.B FILE
+pointer.
.SH START CONDITIONS
.I flex
provides a mechanism for conditionally activating rules. Any rule
then
.I only
rules qualified with the start condition will be active.
-So a set of rules conditioned on the same exclusive start condition
+A set of rules contingent on the same exclusive start condition
describe a scanner which is independent of any of the other rules in the
.I flex
input. Because of this,
which scan portions of the input that are syntactically different
from the rest (e.g., comments).
.LP
+The default rule (to
+.B ECHO
+any unmatched character) remains active in exclusive start conditions.
+### you are here
+.LP
.B BEGIN(0)
returns to the original state where only the rules with
no start conditions are active. This state can also be
be executed), or the action must finish with a
.I return
or
-.I yyterminate()
+.B yyterminate()
statement. <<EOF>> rules may not be used with other
patterns; they may only be qualified with a list of start
conditions. If an unqualified <<EOF>> rule is given, it
.IP -
.B output()
is not supported.
-Output from the ECHO macro is done to the file-pointer
+Output from the
+.B ECHO
+macro is done to the file-pointer
"yyout" (default
.I stdout).
.IP
specifies that yywrap() is a function and this is unlikely to change; so
.I flex users are warned
that
-.I yywrap()
+.B yywrap()
is likely to be changed to a function in the near future.
.IP -
The precedence of the