lex library

The lex library contains the following subroutines:

Subroutine Description
main() Invokes the lexical analyzer by calling the yylex subroutine.
yywrap() Returns the value 1 when the end of input occurs.
yymore() Appends the next matched string to the current value of the yytext array rather than replacing the contents of the yytext array.
yyless(int n) Retains n initial characters in the yytext array and returns the remaining characters to the input stream.
yyreject() Allows the lexical analyzer to match multiple rules for the same input string. (The yyreject subroutine is called when the special action REJECT is used.)

Some of the lex subroutines can be substituted by user-supplied routines. For example, the lex command supports user-supplied versions of the main and yywrap subroutines. The library versions of these routines, provided as a base, are as follows:

main subroutine
#include <stdio.h>
#include <locale.h>
main() {
     setlocale(LC_ALL, "");
     yylex();
     exit(0);
}
yywrap subroutine
yywrap() {
       return(1);
}

The yymore, yyless, and yyreject subroutines are available only through the lex library. However, these subroutines are required only when used in lex command actions.