]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/lex/lex.1
contrib/tzdata: import tzdata 2023d
[FreeBSD/FreeBSD.git] / usr.bin / lex / lex.1
1 .\"
2 .TH FLEX 1 "May 6, 2017" "Version 2.6.4"
3 .SH NAME
4 flex, lex \- fast lexical analyzer generator
5 .SH SYNOPSIS
6 .B flex
7 .B [\-bcdfhilnpstvwBFILTV78+? \-C[aefFmr] \-ooutput \-Pprefix \-Sskeleton]
8 .B [\-\-help \-\-version]
9 .I [filename ...]
10 .SH OVERVIEW
11 This manual describes
12 .I flex,
13 a tool for generating programs that perform pattern-matching on text.
14 The manual includes both tutorial and reference sections:
15 .nf
16
17     Description
18         a brief overview of the tool
19
20     Some Simple Examples
21
22     Format Of The Input File
23
24     Patterns
25         the extended regular expressions used by flex
26
27     How The Input Is Matched
28         the rules for determining what has been matched
29
30     Actions
31         how to specify what to do when a pattern is matched
32
33     The Generated Scanner
34         details regarding the scanner that flex produces;
35         how to control the input source
36
37     Start Conditions
38         introducing context into your scanners, and
39         managing "mini-scanners"
40
41     Multiple Input Buffers
42         how to manipulate multiple input sources; how to
43         scan from strings instead of files
44
45     End-of-file Rules
46         special rules for matching the end of the input
47
48     Miscellaneous Macros
49         a summary of macros available to the actions
50
51     Values Available To The User
52         a summary of values available to the actions
53
54     Interfacing With Yacc
55         connecting flex scanners together with yacc parsers
56
57     Options
58         flex command-line options, and the "%option"
59         directive
60
61     Performance Considerations
62         how to make your scanner go as fast as possible
63
64     Generating C++ Scanners
65         the (experimental) facility for generating C++
66         scanner classes
67
68     Incompatibilities With Lex And POSIX
69         how flex differs from AT&T lex and the POSIX lex
70         standard
71
72     Diagnostics
73         those error messages produced by flex (or scanners
74         it generates) whose meanings might not be apparent
75
76     Files
77         files used by flex
78
79     Deficiencies / Bugs
80         known problems with flex
81
82     See Also
83         other documentation, related tools
84
85     Author
86         includes contact information
87
88 .fi
89 .SH DESCRIPTION
90 .I flex
91 is a tool for generating
92 .I scanners:
93 programs which recognize lexical patterns in text.
94 .I flex
95 reads
96 the given input files, or its standard input if no file names are given,
97 for a description of a scanner to generate.
98 The description is in the form of pairs
99 of regular expressions and C code, called
100 .I rules.
101 .I flex
102 generates as output a C source file,
103 .B lex.yy.c,
104 which defines a routine
105 .B yylex().
106 This file is compiled and linked with the
107 .B \-ll
108 library to produce an executable.
109 When the executable is run,
110 it analyzes its input for occurrences
111 of the regular expressions.
112 Whenever it finds one, it executes
113 the corresponding C code.
114 .SH SOME SIMPLE EXAMPLES
115 First some simple examples to get the flavor of how one uses
116 .I flex.
117 The following
118 .I flex
119 input specifies a scanner which whenever it encounters the string
120 "username" will replace it with the user's login name:
121 .nf
122
123     %%
124     username    printf( "%s", getlogin() );
125
126 .fi
127 By default, any text not matched by a
128 .I flex
129 scanner
130 is copied to the output, so the net effect of this scanner is
131 to copy its input file to its output with each occurrence
132 of "username" expanded.
133 In this input, there is just one rule.
134 "username" is the
135 .I pattern
136 and the "printf" is the
137 .I action.
138 The "%%" marks the beginning of the rules.
139 .PP
140 Here's another simple example:
141 .nf
142
143     %{
144             int num_lines = 0, num_chars = 0;
145     %}
146
147     %%
148     \\n      ++num_lines; ++num_chars;
149     .       ++num_chars;
150
151     %%
152     main()
153             {
154             yylex();
155             printf( "# of lines = %d, # of chars = %d\\n",
156                     num_lines, num_chars );
157             }
158
159 .fi
160 This scanner counts the number of characters and the number
161 of lines in its input (it produces no output other than the
162 final report on the counts).
163 The first line
164 declares two globals, "num_lines" and "num_chars", which are accessible
165 both inside
166 .B yylex()
167 and in the
168 .B main()
169 routine declared after the second "%%".
170 There are two rules, one
171 which matches a newline ("\\n") and increments both the line count and
172 the character count, and one which matches any character other than
173 a newline (indicated by the "." regular expression).
174 .PP
175 A somewhat more complicated example:
176 .nf
177
178     /* scanner for a toy Pascal-like language */
179
180     %{
181     /* need this for the call to atof() below */
182     #include <math.h>
183     %}
184
185     DIGIT    [0-9]
186     ID       [a-z][a-z0-9]*
187
188     %%
189
190     {DIGIT}+    {
191                 printf( "An integer: %s (%d)\\n", yytext,
192                         atoi( yytext ) );
193                 }
194
195     {DIGIT}+"."{DIGIT}*        {
196                 printf( "A float: %s (%g)\\n", yytext,
197                         atof( yytext ) );
198                 }
199
200     if|then|begin|end|procedure|function        {
201                 printf( "A keyword: %s\\n", yytext );
202                 }
203
204     {ID}        printf( "An identifier: %s\\n", yytext );
205
206     "+"|"-"|"*"|"/"   printf( "An operator: %s\\n", yytext );
207
208     "{"[^}\\n]*"}"     /* eat up one-line comments */
209
210     [ \\t\\n]+          /* eat up whitespace */
211
212     .           printf( "Unrecognized character: %s\\n", yytext );
213
214     %%
215
216     main( argc, argv )
217     int argc;
218     char **argv;
219         {
220         ++argv, --argc;  /* skip over program name */
221         if ( argc > 0 )
222                 yyin = fopen( argv[0], "r" );
223         else
224                 yyin = stdin;
225
226         yylex();
227         }
228
229 .fi
230 This is the beginnings of a simple scanner for a language like
231 Pascal.
232 It identifies different types of
233 .I tokens
234 and reports on what it has seen.
235 .PP
236 The details of this example will be explained in the following
237 sections.
238 .SH FORMAT OF THE INPUT FILE
239 The
240 .I flex
241 input file consists of three sections, separated by a line with just
242 .B %%
243 in it:
244 .nf
245
246     definitions
247     %%
248     rules
249     %%
250     user code
251
252 .fi
253 The
254 .I definitions
255 section contains declarations of simple
256 .I name
257 definitions to simplify the scanner specification, and declarations of
258 .I start conditions,
259 which are explained in a later section.
260 .PP
261 Name definitions have the form:
262 .nf
263
264     name definition
265
266 .fi
267 The "name" is a word beginning with a letter or an underscore ('_')
268 followed by zero or more letters, digits, '_', or '-' (dash).
269 The definition is taken to begin at the first non-white-space character
270 following the name and continuing to the end of the line.
271 The definition can subsequently be referred to using "{name}", which
272 will expand to "(definition)".
273 For example,
274 .nf
275
276     DIGIT    [0-9]
277     ID       [a-z][a-z0-9]*
278
279 .fi
280 defines "DIGIT" to be a regular expression which matches a
281 single digit, and
282 "ID" to be a regular expression which matches a letter
283 followed by zero-or-more letters-or-digits.
284 A subsequent reference to
285 .nf
286
287     {DIGIT}+"."{DIGIT}*
288
289 .fi
290 is identical to
291 .nf
292
293     ([0-9])+"."([0-9])*
294
295 .fi
296 and matches one-or-more digits followed by a '.' followed
297 by zero-or-more digits.
298 .PP
299 The
300 .I rules
301 section of the
302 .I flex
303 input contains a series of rules of the form:
304 .nf
305
306     pattern   action
307
308 .fi
309 where the pattern must be unindented and the action must begin
310 on the same line.
311 .PP
312 See below for a further description of patterns and actions.
313 .PP
314 Finally, the user code section is simply copied to
315 .B lex.yy.c
316 verbatim.
317 It is used for companion routines which call or are called
318 by the scanner.
319 The presence of this section is optional;
320 if it is missing, the second
321 .B %%
322 in the input file may be skipped, too.
323 .PP
324 In the definitions and rules sections, any
325 .I indented
326 text or text enclosed in
327 .B %{
328 and
329 .B %}
330 is copied verbatim to the output (with the %{}'s removed).
331 The %{}'s must appear unindented on lines by themselves.
332 .PP
333 In the rules section,
334 any indented or %{} text appearing before the
335 first rule may be used to declare variables
336 which are local to the scanning routine and (after the declarations)
337 code which is to be executed whenever the scanning routine is entered.
338 Other indented or %{} text in the rule section is still copied to the output,
339 but its meaning is not well-defined and it may well cause compile-time
340 errors (this feature is present for
341 .I POSIX
342 compliance; see below for other such features).
343 .PP
344 In the definitions section (but not in the rules section),
345 an unindented comment (i.e., a line
346 beginning with "/*") is also copied verbatim to the output up
347 to the next "*/".
348 .SH PATTERNS
349 The patterns in the input are written using an extended set of regular
350 expressions.
351 These are:
352 .nf
353
354     x          match the character 'x'
355     .          any character (byte) except newline
356     [xyz]      a "character class"; in this case, the pattern
357                  matches either an 'x', a 'y', or a 'z'
358     [abj-oZ]   a "character class" with a range in it; matches
359                  an 'a', a 'b', any letter from 'j' through 'o',
360                  or a 'Z'
361     [^A-Z]     a "negated character class", i.e., any character
362                  but those in the class.  In this case, any
363                  character EXCEPT an uppercase letter.
364     [^A-Z\\n]   any character EXCEPT an uppercase letter or
365                  a newline
366     r*         zero or more r's, where r is any regular expression
367     r+         one or more r's
368     r?         zero or one r's (that is, "an optional r")
369     r{2,5}     anywhere from two to five r's
370     r{2,}      two or more r's
371     r{4}       exactly 4 r's
372     {name}     the expansion of the "name" definition
373                (see above)
374     "[xyz]\\"foo"
375                the literal string: [xyz]"foo
376     \\X         if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
377                  then the ANSI-C interpretation of \\x.
378                  Otherwise, a literal 'X' (used to escape
379                  operators such as '*')
380     \\0         a NUL character (ASCII code 0)
381     \\123       the character with octal value 123
382     \\x2a       the character with hexadecimal value 2a
383     (r)        match an r; parentheses are used to override
384                  precedence (see below)
385
386
387     rs         the regular expression r followed by the
388                  regular expression s; called "concatenation"
389
390
391     r|s        either an r or an s
392
393
394     r/s        an r but only if it is followed by an s.  The
395                  text matched by s is included when determining
396                  whether this rule is the "longest match",
397                  but is then returned to the input before
398                  the action is executed.  So the action only
399                  sees the text matched by r.  This type
400                  of pattern is called trailing context".
401                  (There are some combinations of r/s that flex
402                  cannot match correctly; see notes in the
403                  Deficiencies / Bugs section below regarding
404                  "dangerous trailing context".)
405     ^r         an r, but only at the beginning of a line (i.e.,
406                  when just starting to scan, or right after a
407                  newline has been scanned).
408     r$         an r, but only at the end of a line (i.e., just
409                  before a newline).  Equivalent to "r/\\n".
410
411                Note that flex's notion of "newline" is exactly
412                whatever the C compiler used to compile flex
413                interprets '\\n' as; in particular, on some DOS
414                systems you must either filter out \\r's in the
415                input yourself, or explicitly use r/\\r\\n for "r$".
416
417
418     <s>r       an r, but only in start condition s (see
419                  below for discussion of start conditions)
420     <s1,s2,s3>r
421                same, but in any of start conditions s1,
422                  s2, or s3
423     <*>r       an r in any start condition, even an exclusive one.
424
425
426     <<EOF>>    an end-of-file
427     <s1,s2><<EOF>>
428                an end-of-file when in start condition s1 or s2
429
430 .fi
431 Note that inside of a character class, all regular expression operators
432 lose their special meaning except escape ('\\') and the character class
433 operators, '-', ']', and, at the beginning of the class, '^'.
434 .PP
435 The regular expressions listed above are grouped according to
436 precedence, from highest precedence at the top to lowest at the bottom.
437 Those grouped together have equal precedence.
438 For example,
439 .nf
440
441     foo|bar*
442
443 .fi
444 is the same as
445 .nf
446
447     (foo)|(ba(r*))
448
449 .fi
450 since the '*' operator has higher precedence than concatenation,
451 and concatenation higher than alternation ('|').
452 This pattern
453 therefore matches
454 .I either
455 the string "foo"
456 .I or
457 the string "ba" followed by zero-or-more r's.
458 To match "foo" or zero-or-more "bar"'s, use:
459 .nf
460
461     foo|(bar)*
462
463 .fi
464 and to match zero-or-more "foo"'s-or-"bar"'s:
465 .nf
466
467     (foo|bar)*
468
469 .fi
470 .PP
471 In addition to characters and ranges of characters, character classes
472 can also contain character class
473 .I expressions.
474 These are expressions enclosed inside
475 .B [:
476 and
477 .B :]
478 delimiters (which themselves must appear between the '[' and ']' of the
479 character class; other elements may occur inside the character class, too).
480 The valid expressions are:
481 .nf
482
483     [:alnum:] [:alpha:] [:blank:]
484     [:cntrl:] [:digit:] [:graph:]
485     [:lower:] [:print:] [:punct:]
486     [:space:] [:upper:] [:xdigit:]
487
488 .fi
489 These expressions all designate a set of characters equivalent to
490 the corresponding standard C
491 .B isXXX
492 function.
493 For example,
494 .B [:alnum:]
495 designates those characters for which
496 .B isalnum()
497 returns true - i.e., any alphabetic or numeric.
498 Some systems don't provide
499 .B isblank(),
500 so flex defines
501 .B [:blank:]
502 as a blank or a tab.
503 .PP
504 For example, the following character classes are all equivalent:
505 .nf
506
507     [[:alnum:]]
508     [[:alpha:][:digit:]]
509     [[:alpha:]0-9]
510     [a-zA-Z0-9]
511
512 .fi
513 If your scanner is case-insensitive (the
514 .B \-i
515 flag), then
516 .B [:upper:]
517 and
518 .B [:lower:]
519 are equivalent to
520 .B [:alpha:].
521 .PP
522 Some notes on patterns:
523 .IP -
524 A negated character class such as the example "[^A-Z]"
525 above
526 .I will match a newline
527 unless "\\n" (or an equivalent escape sequence) is one of the
528 characters explicitly present in the negated character class
529 (e.g., "[^A-Z\\n]").
530 This is unlike how many other regular
531 expression tools treat negated character classes, but unfortunately
532 the inconsistency is historically entrenched.
533 Matching newlines means that a pattern like [^"]* can match the entire
534 input unless there's another quote in the input.
535 .IP -
536 A rule can have at most one instance of trailing context (the '/' operator
537 or the '$' operator).
538 The start condition, '^', and "<<EOF>>" patterns
539 can only occur at the beginning of a pattern, and, as well as with '/' and '$',
540 cannot be grouped inside parentheses.
541 A '^' which does not occur at
542 the beginning of a rule or a '$' which does not occur at the end of
543 a rule loses its special properties and is treated as a normal character.
544 .IP
545 The following are illegal:
546 .nf
547
548     foo/bar$
549     <sc1>foo<sc2>bar
550
551 .fi
552 Note that the first of these, can be written "foo/bar\\n".
553 .IP
554 The following will result in '$' or '^' being treated as a normal character:
555 .nf
556
557     foo|(bar$)
558     foo|^bar
559
560 .fi
561 If what's wanted is a "foo" or a bar-followed-by-a-newline, the following
562 could be used (the special '|' action is explained below):
563 .nf
564
565     foo      |
566     bar$     /* action goes here */
567
568 .fi
569 A similar trick will work for matching a foo or a
570 bar-at-the-beginning-of-a-line.
571 .SH HOW THE INPUT IS MATCHED
572 When the generated scanner is run, it analyzes its input looking
573 for strings which match any of its patterns.
574 If it finds more than
575 one match, it takes the one matching the most text (for trailing
576 context rules, this includes the length of the trailing part, even
577 though it will then be returned to the input).
578 If it finds two
579 or more matches of the same length, the
580 rule listed first in the
581 .I flex
582 input file is chosen.
583 .PP
584 Once the match is determined, the text corresponding to the match
585 (called the
586 .I token)
587 is made available in the global character pointer
588 .B yytext,
589 and its length in the global integer
590 .B yyleng.
591 The
592 .I action
593 corresponding to the matched pattern is then executed (a more
594 detailed description of actions follows), and then the remaining
595 input is scanned for another match.
596 .PP
597 If no match is found, then the
598 .I default rule
599 is executed: the next character in the input is considered matched and
600 copied to the standard output.
601 Thus, the simplest legal
602 .I flex
603 input is:
604 .nf
605
606     %%
607
608 .fi
609 which generates a scanner that simply copies its input (one character
610 at a time) to its output.
611 .PP
612 Note that
613 .B yytext
614 can be defined in two different ways: either as a character
615 .I pointer
616 or as a character
617 .I array.
618 You can control which definition
619 .I flex
620 uses by including one of the special directives
621 .B %pointer
622 or
623 .B %array
624 in the first (definitions) section of your flex input.
625 The default is
626 .B %pointer,
627 unless you use the
628 .B -l
629 lex compatibility option, in which case
630 .B yytext
631 will be an array.
632 The advantage of using
633 .B %pointer
634 is substantially faster scanning and no buffer overflow when matching
635 very large tokens (unless you run out of dynamic memory).
636 The disadvantage
637 is that you are restricted in how your actions can modify
638 .B yytext
639 (see the next section), and calls to the
640 .B unput()
641 function destroys the present contents of
642 .B yytext,
643 which can be a considerable porting headache when moving between different
644 .I lex
645 versions.
646 .PP
647 The advantage of
648 .B %array
649 is that you can then modify
650 .B yytext
651 to your heart's content, and calls to
652 .B unput()
653 do not destroy
654 .B yytext
655 (see below).
656 Furthermore, existing
657 .I lex
658 programs sometimes access
659 .B yytext
660 externally using declarations of the form:
661 .nf
662     extern char yytext[];
663 .fi
664 This definition is erroneous when used with
665 .B %pointer,
666 but correct for
667 .B %array.
668 .PP
669 .B %array
670 defines
671 .B yytext
672 to be an array of
673 .B YYLMAX
674 characters, which defaults to a fairly large value.
675 You can change
676 the size by simply #define'ing
677 .B YYLMAX
678 to a different value in the first section of your
679 .I flex
680 input.
681 As mentioned above, with
682 .B %pointer
683 yytext grows dynamically to accommodate large tokens.
684 While this means your
685 .B %pointer
686 scanner can accommodate very large tokens (such as matching entire blocks
687 of comments), bear in mind that each time the scanner must resize
688 .B yytext
689 it also must rescan the entire token from the beginning, so matching such
690 tokens can prove slow.
691 .B yytext
692 presently does
693 .I not
694 dynamically grow if a call to
695 .B unput()
696 results in too much text being pushed back; instead, a run-time error results.
697 .PP
698 Also note that you cannot use
699 .B %array
700 with C++ scanner classes
701 (the
702 .B c++
703 option; see below).
704 .SH ACTIONS
705 Each pattern in a rule has a corresponding action, which can be any
706 arbitrary C statement.
707 The pattern ends at the first non-escaped
708 whitespace character; the remainder of the line is its action.
709 If the
710 action is empty, then when the pattern is matched the input token
711 is simply discarded.
712 For example, here is the specification for a program
713 which deletes all occurrences of "zap me" from its input:
714 .nf
715
716     %%
717     "zap me"
718
719 .fi
720 (It will copy all other characters in the input to the output since
721 they will be matched by the default rule.)
722 .PP
723 Here is a program which compresses multiple blanks and tabs down to
724 a single blank, and throws away whitespace found at the end of a line:
725 .nf
726
727     %%
728     [ \\t]+        putchar( ' ' );
729     [ \\t]+$       /* ignore this token */
730
731 .fi
732 .PP
733 If the action contains a '{', then the action spans till the balancing '}'
734 is found, and the action may cross multiple lines.
735 .I flex
736 knows about C strings and comments and won't be fooled by braces found
737 within them, but also allows actions to begin with
738 .B %{
739 and will consider the action to be all the text up to the next
740 .B %}
741 (regardless of ordinary braces inside the action).
742 .PP
743 An action consisting solely of a vertical bar ('|') means "same as
744 the action for the next rule."  See below for an illustration.
745 .PP
746 Actions can include arbitrary C code, including
747 .B return
748 statements to return a value to whatever routine called
749 .B yylex().
750 Each time
751 .B yylex()
752 is called it continues processing tokens from where it last left
753 off until it either reaches
754 the end of the file or executes a return.
755 .PP
756 Actions are free to modify
757 .B yytext
758 except for lengthening it (adding
759 characters to its end--these will overwrite later characters in the
760 input stream).
761 This however does not apply when using
762 .B %array
763 (see above); in that case,
764 .B yytext
765 may be freely modified in any way.
766 .PP
767 Actions are free to modify
768 .B yyleng
769 except they should not do so if the action also includes use of
770 .B yymore()
771 (see below).
772 .PP
773 There are a number of special directives which can be included within
774 an action:
775 .IP -
776 .B ECHO
777 copies yytext to the scanner's output.
778 .IP -
779 .B BEGIN
780 followed by the name of a start condition places the scanner in the
781 corresponding start condition (see below).
782 .IP -
783 .B REJECT
784 directs the scanner to proceed on to the "second best" rule which matched the
785 input (or a prefix of the input).
786 The rule is chosen as described
787 above in "How the Input is Matched", and
788 .B yytext
789 and
790 .B yyleng
791 set up appropriately.
792 It may either be one which matched as much text
793 as the originally chosen rule but came later in the
794 .I flex
795 input file, or one which matched less text.
796 For example, the following will both count the
797 words in the input and call the routine special() whenever "frob" is seen:
798 .nf
799
800             int word_count = 0;
801     %%
802
803     frob        special(); REJECT;
804     [^ \\t\\n]+   ++word_count;
805
806 .fi
807 Without the
808 .B REJECT,
809 any "frob"'s in the input would not be counted as words, since the
810 scanner normally executes only one action per token.
811 Multiple
812 .B REJECT's
813 are allowed, each one finding the next best choice to the currently
814 active rule.
815 For example, when the following scanner scans the token
816 "abcd", it will write "abcdabcaba" to the output:
817 .nf
818
819     %%
820     a        |
821     ab       |
822     abc      |
823     abcd     ECHO; REJECT;
824     .|\\n     /* eat up any unmatched character */
825
826 .fi
827 (The first three rules share the fourth's action since they use
828 the special '|' action.)
829 .B REJECT
830 is a particularly expensive feature in terms of scanner performance;
831 if it is used in
832 .I any
833 of the scanner's actions it will slow down
834 .I all
835 of the scanner's matching.
836 Furthermore,
837 .B REJECT
838 cannot be used with the
839 .I -Cf
840 or
841 .I -CF
842 options (see below).
843 .IP
844 Note also that unlike the other special actions,
845 .B REJECT
846 is a
847 .I branch;
848 code immediately following it in the action will
849 .I not
850 be executed.
851 .IP -
852 .B yymore()
853 tells the scanner that the next time it matches a rule, the corresponding
854 token should be
855 .I appended
856 onto the current value of
857 .B yytext
858 rather than replacing it.
859 For example, given the input "mega-kludge"
860 the following will write "mega-mega-kludge" to the output:
861 .nf
862
863     %%
864     mega-    ECHO; yymore();
865     kludge   ECHO;
866
867 .fi
868 First "mega-" is matched and echoed to the output.
869 Then "kludge"
870 is matched, but the previous "mega-" is still hanging around at the
871 beginning of
872 .B yytext
873 so the
874 .B ECHO
875 for the "kludge" rule will actually write "mega-kludge".
876 .PP
877 Two notes regarding use of
878 .B yymore().
879 First,
880 .B yymore()
881 depends on the value of
882 .I yyleng
883 correctly reflecting the size of the current token, so you must not
884 modify
885 .I yyleng
886 if you are using
887 .B yymore().
888 Second, the presence of
889 .B yymore()
890 in the scanner's action entails a minor performance penalty in the
891 scanner's matching speed.
892 .IP -
893 .B yyless(n)
894 returns all but the first
895 .I n
896 characters of the current token back to the input stream, where they
897 will be rescanned when the scanner looks for the next match.
898 .B yytext
899 and
900 .B yyleng
901 are adjusted appropriately (e.g.,
902 .B yyleng
903 will now be equal to
904 .I n
905 ).
906 For example, on the input "foobar" the following will write out
907 "foobarbar":
908 .nf
909
910     %%
911     foobar    ECHO; yyless(3);
912     [a-z]+    ECHO;
913
914 .fi
915 An argument of 0 to
916 .B yyless
917 will cause the entire current input string to be scanned again.
918 Unless you've
919 changed how the scanner will subsequently process its input (using
920 .B BEGIN,
921 for example), this will result in an endless loop.
922 .PP
923 Note that
924 .B yyless
925 is a macro and can only be used in the flex input file, not from
926 other source files.
927 .IP -
928 .B unput(c)
929 puts the character
930 .I c
931 back onto the input stream.
932 It will be the next character scanned.
933 The following action will take the current token and cause it
934 to be rescanned enclosed in parentheses.
935 .nf
936
937     {
938     int i;
939     /* Copy yytext because unput() trashes yytext */
940     char *yycopy = strdup( yytext );
941     unput( ')' );
942     for ( i = yyleng - 1; i >= 0; --i )
943         unput( yycopy[i] );
944     unput( '(' );
945     free( yycopy );
946     }
947
948 .fi
949 Note that since each
950 .B unput()
951 puts the given character back at the
952 .I beginning
953 of the input stream, pushing back strings must be done back-to-front.
954 .PP
955 An important potential problem when using
956 .B unput()
957 is that if you are using
958 .B %pointer
959 (the default), a call to
960 .B unput()
961 .I destroys
962 the contents of
963 .I yytext,
964 starting with its rightmost character and devouring one character to
965 the left with each call.
966 If you need the value of yytext preserved
967 after a call to
968 .B unput()
969 (as in the above example),
970 you must either first copy it elsewhere, or build your scanner using
971 .B %array
972 instead (see How The Input Is Matched).
973 .PP
974 Finally, note that you cannot put back
975 .B EOF
976 to attempt to mark the input stream with an end-of-file.
977 .IP -
978 .B input()
979 reads the next character from the input stream.
980 For example,
981 the following is one way to eat up C comments:
982 .nf
983
984     %%
985     "/*"        {
986                 int c;
987
988                 for ( ; ; )
989                     {
990                     while ( (c = input()) != '*' &&
991                             c != EOF )
992                         ;    /* eat up text of comment */
993
994                     if ( c == '*' )
995                         {
996                         while ( (c = input()) == '*' )
997                             ;
998                         if ( c == '/' )
999                             break;    /* found the end */
1000                         }
1001
1002                     if ( c == EOF )
1003                         {
1004                         error( "EOF in comment" );
1005                         break;
1006                         }
1007                     }
1008                 }
1009
1010 .fi
1011 (Note that if the scanner is compiled using
1012 .B C++,
1013 then
1014 .B input()
1015 is instead referred to as
1016 .B yyinput(),
1017 in order to avoid a name clash with the
1018 .B C++
1019 stream by the name of
1020 .I input.)
1021 .IP -
1022 .B YY_FLUSH_BUFFER
1023 flushes the scanner's internal buffer
1024 so that the next time the scanner attempts to match a token, it will
1025 first refill the buffer using
1026 .B YY_INPUT
1027 (see The Generated Scanner, below).
1028 This action is a special case
1029 of the more general
1030 .B yy_flush_buffer()
1031 function, described below in the section Multiple Input Buffers.
1032 .IP -
1033 .B yyterminate()
1034 can be used in lieu of a return statement in an action.
1035 It terminates
1036 the scanner and returns a 0 to the scanner's caller, indicating "all done".
1037 By default,
1038 .B yyterminate()
1039 is also called when an end-of-file is encountered.
1040 It is a macro and may be redefined.
1041 .SH THE GENERATED SCANNER
1042 The output of
1043 .I flex
1044 is the file
1045 .B lex.yy.c,
1046 which contains the scanning routine
1047 .B yylex(),
1048 a number of tables used by it for matching tokens, and a number
1049 of auxiliary routines and macros.
1050 By default,
1051 .B yylex()
1052 is declared as follows:
1053 .nf
1054
1055     int yylex()
1056         {
1057         ... various definitions and the actions in here ...
1058         }
1059
1060 .fi
1061 (If your environment supports function prototypes, then it will
1062 be "int yylex( void )".)  This definition may be changed by defining
1063 the "YY_DECL" macro.
1064 For example, you could use:
1065 .nf
1066
1067     #define YY_DECL float lexscan( a, b ) float a, b;
1068
1069 .fi
1070 to give the scanning routine the name
1071 .I lexscan,
1072 returning a float, and taking two floats as arguments.
1073 Note that
1074 if you give arguments to the scanning routine using a
1075 K&R-style/non-prototyped function declaration, you must terminate
1076 the definition with a semi-colon (;).
1077 .PP
1078 Whenever
1079 .B yylex()
1080 is called, it scans tokens from the global input file
1081 .I yyin
1082 (which defaults to stdin).
1083 It continues until it either reaches
1084 an end-of-file (at which point it returns the value 0) or
1085 one of its actions executes a
1086 .I return
1087 statement.
1088 .PP
1089 If the scanner reaches an end-of-file, subsequent calls are undefined
1090 unless either
1091 .I yyin
1092 is pointed at a new input file (in which case scanning continues from
1093 that file), or
1094 .B yyrestart()
1095 is called.
1096 .B yyrestart()
1097 takes one argument, a
1098 .B FILE *
1099 pointer (which can be nil, if you've set up
1100 .B YY_INPUT
1101 to scan from a source other than
1102 .I yyin),
1103 and initializes
1104 .I yyin
1105 for scanning from that file.
1106 Essentially there is no difference between
1107 just assigning
1108 .I yyin
1109 to a new input file or using
1110 .B yyrestart()
1111 to do so; the latter is available for compatibility with previous versions
1112 of
1113 .I flex,
1114 and because it can be used to switch input files in the middle of scanning.
1115 It can also be used to throw away the current input buffer, by calling
1116 it with an argument of
1117 .I yyin;
1118 but better is to use
1119 .B YY_FLUSH_BUFFER
1120 (see above).
1121 Note that
1122 .B yyrestart()
1123 does
1124 .I not
1125 reset the start condition to
1126 .B INITIAL
1127 (see Start Conditions, below).
1128 .PP
1129 If
1130 .B yylex()
1131 stops scanning due to executing a
1132 .I return
1133 statement in one of the actions, the scanner may then be called again and it
1134 will resume scanning where it left off.
1135 .PP
1136 By default (and for purposes of efficiency), the scanner uses
1137 block-reads rather than simple
1138 .I getc()
1139 calls to read characters from
1140 .I yyin.
1141 The nature of how it gets its input can be controlled by defining the
1142 .B YY_INPUT
1143 macro.
1144 YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)".
1145 Its action is to place up to
1146 .I max_size
1147 characters in the character array
1148 .I buf
1149 and return in the integer variable
1150 .I result
1151 either the
1152 number of characters read or the constant YY_NULL (0 on Unix systems)
1153 to indicate EOF.
1154 The default YY_INPUT reads from the
1155 global file-pointer "yyin".
1156 .PP
1157 A sample definition of YY_INPUT (in the definitions
1158 section of the input file):
1159 .nf
1160
1161     %{
1162     #define YY_INPUT(buf,result,max_size) \\
1163         { \\
1164         int c = getchar(); \\
1165         result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\
1166         }
1167     %}
1168
1169 .fi
1170 This definition will change the input processing to occur
1171 one character at a time.
1172 .PP
1173 When the scanner receives an end-of-file indication from YY_INPUT,
1174 it then checks the
1175 .B yywrap()
1176 function.
1177 If
1178 .B yywrap()
1179 returns false (zero), then it is assumed that the
1180 function has gone ahead and set up
1181 .I yyin
1182 to point to another input file, and scanning continues.
1183 If it returns
1184 true (non-zero), then the scanner terminates, returning 0 to its
1185 caller.
1186 Note that in either case, the start condition remains unchanged;
1187 it does
1188 .I not
1189 revert to
1190 .B INITIAL.
1191 .PP
1192 If you do not supply your own version of
1193 .B yywrap(),
1194 then you must either use
1195 .B %option noyywrap
1196 (in which case the scanner behaves as though
1197 .B yywrap()
1198 returned 1), or you must link with
1199 .B \-ll
1200 to obtain the default version of the routine, which always returns 1.
1201 .PP
1202 Three routines are available for scanning from in-memory buffers rather
1203 than files:
1204 .B yy_scan_string(), yy_scan_bytes(),
1205 and
1206 .B yy_scan_buffer().
1207 See the discussion of them below in the section Multiple Input Buffers.
1208 .PP
1209 The scanner writes its
1210 .B ECHO
1211 output to the
1212 .I yyout
1213 global (default, stdout), which may be redefined by the user simply
1214 by assigning it to some other
1215 .B FILE
1216 pointer.
1217 .SH START CONDITIONS
1218 .I flex
1219 provides a mechanism for conditionally activating rules.
1220 Any rule
1221 whose pattern is prefixed with "<sc>" will only be active when
1222 the scanner is in the start condition named "sc".
1223 For example,
1224 .nf
1225
1226     <STRING>[^"]*        { /* eat up the string body ... */
1227                 ...
1228                 }
1229
1230 .fi
1231 will be active only when the scanner is in the "STRING" start
1232 condition, and
1233 .nf
1234
1235     <INITIAL,STRING,QUOTE>\\.        { /* handle an escape ... */
1236                 ...
1237                 }
1238
1239 .fi
1240 will be active only when the current start condition is
1241 either "INITIAL", "STRING", or "QUOTE".
1242 .PP
1243 Start conditions
1244 are declared in the definitions (first) section of the input
1245 using unindented lines beginning with either
1246 .B %s
1247 or
1248 .B %x
1249 followed by a list of names.
1250 The former declares
1251 .I inclusive
1252 start conditions, the latter
1253 .I exclusive
1254 start conditions.
1255 A start condition is activated using the
1256 .B BEGIN
1257 action.
1258 Until the next
1259 .B BEGIN
1260 action is executed, rules with the given start
1261 condition will be active and
1262 rules with other start conditions will be inactive.
1263 If the start condition is
1264 .I inclusive,
1265 then rules with no start conditions at all will also be active.
1266 If it is
1267 .I exclusive,
1268 then
1269 .I only
1270 rules qualified with the start condition will be active.
1271 A set of rules contingent on the same exclusive start condition
1272 describe a scanner which is independent of any of the other rules in the
1273 .I flex
1274 input.
1275 Because of this,
1276 exclusive start conditions make it easy to specify "mini-scanners"
1277 which scan portions of the input that are syntactically different
1278 from the rest (e.g., comments).
1279 .PP
1280 If the distinction between inclusive and exclusive start conditions
1281 is still a little vague, here's a simple example illustrating the
1282 connection between the two.
1283 The set of rules:
1284 .nf
1285
1286     %s example
1287     %%
1288
1289     <example>foo   do_something();
1290
1291     bar            something_else();
1292
1293 .fi
1294 is equivalent to
1295 .nf
1296
1297     %x example
1298     %%
1299
1300     <example>foo   do_something();
1301
1302     <INITIAL,example>bar    something_else();
1303
1304 .fi
1305 Without the
1306 .B <INITIAL,example>
1307 qualifier, the
1308 .I bar
1309 pattern in the second example wouldn't be active (i.e., couldn't match)
1310 when in start condition
1311 .B example.
1312 If we just used
1313 .B <example>
1314 to qualify
1315 .I bar,
1316 though, then it would only be active in
1317 .B example
1318 and not in
1319 .B INITIAL,
1320 while in the first example it's active in both, because in the first
1321 example the
1322 .B example
1323 start condition is an
1324 .I inclusive
1325 .B (%s)
1326 start condition.
1327 .PP
1328 Also note that the special start-condition specifier
1329 .B <*>
1330 matches every start condition.
1331 Thus, the above example could also have been written;
1332 .nf
1333
1334     %x example
1335     %%
1336
1337     <example>foo   do_something();
1338
1339     <*>bar    something_else();
1340
1341 .fi
1342 .PP
1343 The default rule (to
1344 .B ECHO
1345 any unmatched character) remains active in start conditions.
1346 It
1347 is equivalent to:
1348 .nf
1349
1350     <*>.|\\n     ECHO;
1351
1352 .fi
1353 .PP
1354 .B BEGIN(0)
1355 returns to the original state where only the rules with
1356 no start conditions are active.
1357 This state can also be
1358 referred to as the start-condition "INITIAL", so
1359 .B BEGIN(INITIAL)
1360 is equivalent to
1361 .B BEGIN(0).
1362 (The parentheses around the start condition name are not required but
1363 are considered good style.)
1364 .PP
1365 .B BEGIN
1366 actions can also be given as indented code at the beginning
1367 of the rules section.
1368 For example, the following will cause
1369 the scanner to enter the "SPECIAL" start condition whenever
1370 .B yylex()
1371 is called and the global variable
1372 .I enter_special
1373 is true:
1374 .nf
1375
1376             int enter_special;
1377
1378     %x SPECIAL
1379     %%
1380             if ( enter_special )
1381                 BEGIN(SPECIAL);
1382
1383     <SPECIAL>blahblahblah
1384     ...more rules follow...
1385
1386 .fi
1387 .PP
1388 To illustrate the uses of start conditions,
1389 here is a scanner which provides two different interpretations
1390 of a string like "123.456".
1391 By default it will treat it as
1392 three tokens, the integer "123", a dot ('.'), and the integer "456".
1393 But if the string is preceded earlier in the line by the string
1394 "expect-floats"
1395 it will treat it as a single token, the floating-point number
1396 123.456:
1397 .nf
1398
1399     %{
1400     #include <math.h>
1401     %}
1402     %s expect
1403
1404     %%
1405     expect-floats        BEGIN(expect);
1406
1407     <expect>[0-9]+"."[0-9]+      {
1408                 printf( "found a float, = %f\\n",
1409                         atof( yytext ) );
1410                 }
1411     <expect>\\n           {
1412                 /* that's the end of the line, so
1413                  * we need another "expect-number"
1414                  * before we'll recognize any more
1415                  * numbers
1416                  */
1417                 BEGIN(INITIAL);
1418                 }
1419
1420     [0-9]+      {
1421                 printf( "found an integer, = %d\\n",
1422                         atoi( yytext ) );
1423                 }
1424
1425     "."         printf( "found a dot\\n" );
1426
1427 .fi
1428 Here is a scanner which recognizes (and discards) C comments while
1429 maintaining a count of the current input line.
1430 .nf
1431
1432     %x comment
1433     %%
1434             int line_num = 1;
1435
1436     "/*"         BEGIN(comment);
1437
1438     <comment>[^*\\n]*        /* eat anything that's not a '*' */
1439     <comment>"*"+[^*/\\n]*   /* eat up '*'s not followed by '/'s */
1440     <comment>\\n             ++line_num;
1441     <comment>"*"+"/"        BEGIN(INITIAL);
1442
1443 .fi
1444 This scanner goes to a bit of trouble to match as much
1445 text as possible with each rule.
1446 In general, when attempting to write
1447 a high-speed scanner try to match as much possible in each rule, as
1448 it's a big win.
1449 .PP
1450 Note that start-conditions names are really integer values and
1451 can be stored as such.
1452 Thus, the above could be extended in the
1453 following fashion:
1454 .nf
1455
1456     %x comment foo
1457     %%
1458             int line_num = 1;
1459             int comment_caller;
1460
1461     "/*"         {
1462                  comment_caller = INITIAL;
1463                  BEGIN(comment);
1464                  }
1465
1466     ...
1467
1468     <foo>"/*"    {
1469                  comment_caller = foo;
1470                  BEGIN(comment);
1471                  }
1472
1473     <comment>[^*\\n]*        /* eat anything that's not a '*' */
1474     <comment>"*"+[^*/\\n]*   /* eat up '*'s not followed by '/'s */
1475     <comment>\\n             ++line_num;
1476     <comment>"*"+"/"        BEGIN(comment_caller);
1477
1478 .fi
1479 Furthermore, you can access the current start condition using
1480 the integer-valued
1481 .B YY_START
1482 macro.
1483 For example, the above assignments to
1484 .I comment_caller
1485 could instead be written
1486 .nf
1487
1488     comment_caller = YY_START;
1489
1490 .fi
1491 Flex provides
1492 .B YYSTATE
1493 as an alias for
1494 .B YY_START
1495 (since that is what's used by AT&T
1496 .I lex).
1497 .PP
1498 Note that start conditions do not have their own name-space; %s's and %x's
1499 declare names in the same fashion as #define's.
1500 .PP
1501 Finally, here's an example of how to match C-style quoted strings using
1502 exclusive start conditions, including expanded escape sequences (but
1503 not including checking for a string that's too long):
1504 .nf
1505
1506     %x str
1507
1508     %%
1509             char string_buf[MAX_STR_CONST];
1510             char *string_buf_ptr;
1511
1512
1513     \\"      string_buf_ptr = string_buf; BEGIN(str);
1514
1515     <str>\\"        { /* saw closing quote - all done */
1516             BEGIN(INITIAL);
1517             *string_buf_ptr = '\\0';
1518             /* return string constant token type and
1519              * value to parser
1520              */
1521             }
1522
1523     <str>\\n        {
1524             /* error - unterminated string constant */
1525             /* generate error message */
1526             }
1527
1528     <str>\\\\[0-7]{1,3} {
1529             /* octal escape sequence */
1530             int result;
1531
1532             (void) sscanf( yytext + 1, "%o", &result );
1533
1534             if ( result > 0xff )
1535                     /* error, constant is out-of-bounds */
1536
1537             *string_buf_ptr++ = result;
1538             }
1539
1540     <str>\\\\[0-9]+ {
1541             /* generate error - bad escape sequence; something
1542              * like '\\48' or '\\0777777'
1543              */
1544             }
1545
1546     <str>\\\\n  *string_buf_ptr++ = '\\n';
1547     <str>\\\\t  *string_buf_ptr++ = '\\t';
1548     <str>\\\\r  *string_buf_ptr++ = '\\r';
1549     <str>\\\\b  *string_buf_ptr++ = '\\b';
1550     <str>\\\\f  *string_buf_ptr++ = '\\f';
1551
1552     <str>\\\\(.|\\n)  *string_buf_ptr++ = yytext[1];
1553
1554     <str>[^\\\\\\n\\"]+        {
1555             char *yptr = yytext;
1556
1557             while ( *yptr )
1558                     *string_buf_ptr++ = *yptr++;
1559             }
1560
1561 .fi
1562 .PP
1563 Often, such as in some of the examples above, you wind up writing a
1564 whole bunch of rules all preceded by the same start condition(s).
1565 Flex makes this a little easier and cleaner by introducing a notion of
1566 start condition
1567 .I scope.
1568 A start condition scope is begun with:
1569 .nf
1570
1571     <SCs>{
1572
1573 .fi
1574 where
1575 .I SCs
1576 is a list of one or more start conditions.
1577 Inside the start condition
1578 scope, every rule automatically has the prefix
1579 .I <SCs>
1580 applied to it, until a
1581 .I '}'
1582 which matches the initial
1583 .I '{'.
1584 So, for example,
1585 .nf
1586
1587     <ESC>{
1588         "\\\\n"   return '\\n';
1589         "\\\\r"   return '\\r';
1590         "\\\\f"   return '\\f';
1591         "\\\\0"   return '\\0';
1592     }
1593
1594 .fi
1595 is equivalent to:
1596 .nf
1597
1598     <ESC>"\\\\n"  return '\\n';
1599     <ESC>"\\\\r"  return '\\r';
1600     <ESC>"\\\\f"  return '\\f';
1601     <ESC>"\\\\0"  return '\\0';
1602
1603 .fi
1604 Start condition scopes may be nested.
1605 .PP
1606 Three routines are available for manipulating stacks of start conditions:
1607 .TP
1608 .B void yy_push_state(int new_state)
1609 pushes the current start condition onto the top of the start condition
1610 stack and switches to
1611 .I new_state
1612 as though you had used
1613 .B BEGIN new_state
1614 (recall that start condition names are also integers).
1615 .TP
1616 .B void yy_pop_state()
1617 pops the top of the stack and switches to it via
1618 .B BEGIN.
1619 .TP
1620 .B int yy_top_state()
1621 returns the top of the stack without altering the stack's contents.
1622 .PP
1623 The start condition stack grows dynamically and so has no built-in
1624 size limitation.
1625 If memory is exhausted, program execution aborts.
1626 .PP
1627 To use start condition stacks, your scanner must include a
1628 .B %option stack
1629 directive (see Options below).
1630 .SH MULTIPLE INPUT BUFFERS
1631 Some scanners (such as those which support "include" files)
1632 require reading from several input streams.
1633 As
1634 .I flex
1635 scanners do a large amount of buffering, one cannot control
1636 where the next input will be read from by simply writing a
1637 .B YY_INPUT
1638 which is sensitive to the scanning context.
1639 .B YY_INPUT
1640 is only called when the scanner reaches the end of its buffer, which
1641 may be a long time after scanning a statement such as an "include"
1642 which requires switching the input source.
1643 .PP
1644 To negotiate these sorts of problems,
1645 .I flex
1646 provides a mechanism for creating and switching between multiple
1647 input buffers.
1648 An input buffer is created by using:
1649 .nf
1650
1651     YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
1652
1653 .fi
1654 which takes a
1655 .I FILE
1656 pointer and a size and creates a buffer associated with the given
1657 file and large enough to hold
1658 .I size
1659 characters (when in doubt, use
1660 .B YY_BUF_SIZE
1661 for the size).
1662 It returns a
1663 .B YY_BUFFER_STATE
1664 handle, which may then be passed to other routines (see below).
1665 The
1666 .B YY_BUFFER_STATE
1667 type is a pointer to an opaque
1668 .B struct yy_buffer_state
1669 structure, so you may safely initialize YY_BUFFER_STATE variables to
1670 .B ((YY_BUFFER_STATE) 0)
1671 if you wish, and also refer to the opaque structure in order to
1672 correctly declare input buffers in source files other than that
1673 of your scanner.
1674 Note that the
1675 .I FILE
1676 pointer in the call to
1677 .B yy_create_buffer
1678 is only used as the value of
1679 .I yyin
1680 seen by
1681 .B YY_INPUT;
1682 if you redefine
1683 .B YY_INPUT
1684 so it no longer uses
1685 .I yyin,
1686 then you can safely pass a nil
1687 .I FILE
1688 pointer to
1689 .B yy_create_buffer.
1690 You select a particular buffer to scan from using:
1691 .nf
1692
1693     void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
1694
1695 .fi
1696 switches the scanner's input buffer so subsequent tokens will
1697 come from
1698 .I new_buffer.
1699 Note that
1700 .B yy_switch_to_buffer()
1701 may be used by yywrap() to set things up for continued scanning, instead
1702 of opening a new file and pointing
1703 .I yyin
1704 at it.
1705 Note also that switching input sources via either
1706 .B yy_switch_to_buffer()
1707 or
1708 .B yywrap()
1709 does
1710 .I not
1711 change the start condition.
1712 .nf
1713
1714     void yy_delete_buffer( YY_BUFFER_STATE buffer )
1715
1716 .fi
1717 is used to reclaim the storage associated with a buffer.
1718 (
1719 .B buffer
1720 can be nil, in which case the routine does nothing.)
1721 You can also clear the current contents of a buffer using:
1722 .nf
1723
1724     void yy_flush_buffer( YY_BUFFER_STATE buffer )
1725
1726 .fi
1727 This function discards the buffer's contents,
1728 so the next time the scanner attempts to match a token from the
1729 buffer, it will first fill the buffer anew using
1730 .B YY_INPUT.
1731 .PP
1732 .B yy_new_buffer()
1733 is an alias for
1734 .B yy_create_buffer(),
1735 provided for compatibility with the C++ use of
1736 .I new
1737 and
1738 .I delete
1739 for creating and destroying dynamic objects.
1740 .PP
1741 Finally, the
1742 .B YY_CURRENT_BUFFER
1743 macro returns a
1744 .B YY_BUFFER_STATE
1745 handle to the current buffer.
1746 .PP
1747 Here is an example of using these features for writing a scanner
1748 which expands include files (the
1749 .B <<EOF>>
1750 feature is discussed below):
1751 .nf
1752
1753     /* the "incl" state is used for picking up the name
1754      * of an include file
1755      */
1756     %x incl
1757
1758     %{
1759     #define MAX_INCLUDE_DEPTH 10
1760     YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
1761     int include_stack_ptr = 0;
1762     %}
1763
1764     %%
1765     include             BEGIN(incl);
1766
1767     [a-z]+              ECHO;
1768     [^a-z\\n]*\\n?        ECHO;
1769
1770     <incl>[ \\t]*      /* eat the whitespace */
1771     <incl>[^ \\t\\n]+   { /* got the include file name */
1772             if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
1773                 {
1774                 fprintf( stderr, "Includes nested too deeply" );
1775                 exit( 1 );
1776                 }
1777
1778             include_stack[include_stack_ptr++] =
1779                 YY_CURRENT_BUFFER;
1780
1781             yyin = fopen( yytext, "r" );
1782
1783             if ( ! yyin )
1784                 error( ... );
1785
1786             yy_switch_to_buffer(
1787                 yy_create_buffer( yyin, YY_BUF_SIZE ) );
1788
1789             BEGIN(INITIAL);
1790             }
1791
1792     <<EOF>> {
1793             if ( --include_stack_ptr < 0 )
1794                 {
1795                 yyterminate();
1796                 }
1797
1798             else
1799                 {
1800                 yy_delete_buffer( YY_CURRENT_BUFFER );
1801                 yy_switch_to_buffer(
1802                      include_stack[include_stack_ptr] );
1803                 }
1804             }
1805
1806 .fi
1807 Three routines are available for setting up input buffers for
1808 scanning in-memory strings instead of files.
1809 All of them create
1810 a new input buffer for scanning the string, and return a corresponding
1811 .B YY_BUFFER_STATE
1812 handle (which you should delete with
1813 .B yy_delete_buffer()
1814 when done with it).
1815 They also switch to the new buffer using
1816 .B yy_switch_to_buffer(),
1817 so the next call to
1818 .B yylex()
1819 will start scanning the string.
1820 .TP
1821 .B yy_scan_string(const char *str)
1822 scans a NUL-terminated string.
1823 .TP
1824 .B yy_scan_bytes(const char *bytes, int len)
1825 scans
1826 .I len
1827 bytes (including possibly NUL's)
1828 starting at location
1829 .I bytes.
1830 .PP
1831 Note that both of these functions create and scan a
1832 .I copy
1833 of the string or bytes.
1834 (This may be desirable, since
1835 .B yylex()
1836 modifies the contents of the buffer it is scanning.)  You can avoid the
1837 copy by using:
1838 .TP
1839 .B yy_scan_buffer(char *base, yy_size_t size)
1840 which scans in place the buffer starting at
1841 .I base,
1842 consisting of
1843 .I size
1844 bytes, the last two bytes of which
1845 .I must
1846 be
1847 .B YY_END_OF_BUFFER_CHAR
1848 (ASCII NUL).
1849 These last two bytes are not scanned; thus, scanning
1850 consists of
1851 .B base[0]
1852 through
1853 .B base[size-2],
1854 inclusive.
1855 .IP
1856 If you fail to set up
1857 .I base
1858 in this manner (i.e., forget the final two
1859 .B YY_END_OF_BUFFER_CHAR
1860 bytes), then
1861 .B yy_scan_buffer()
1862 returns a nil pointer instead of creating a new input buffer.
1863 .IP
1864 The type
1865 .B yy_size_t
1866 is an integral type to which you can cast an integer expression
1867 reflecting the size of the buffer.
1868 .SH END-OF-FILE RULES
1869 The special rule "<<EOF>>" indicates
1870 actions which are to be taken when an end-of-file is
1871 encountered and yywrap() returns non-zero (i.e., indicates
1872 no further files to process).
1873 The action must finish
1874 by doing one of four things:
1875 .IP -
1876 assigning
1877 .I yyin
1878 to a new input file (in previous versions of flex, after doing the
1879 assignment you had to call the special action
1880 .B YY_NEW_FILE;
1881 this is no longer necessary);
1882 .IP -
1883 executing a
1884 .I return
1885 statement;
1886 .IP -
1887 executing the special
1888 .B yyterminate()
1889 action;
1890 .IP -
1891 or, switching to a new buffer using
1892 .B yy_switch_to_buffer()
1893 as shown in the example above.
1894 .PP
1895 <<EOF>> rules may not be used with other
1896 patterns; they may only be qualified with a list of start
1897 conditions.
1898 If an unqualified <<EOF>> rule is given, it
1899 applies to
1900 .I all
1901 start conditions which do not already have <<EOF>> actions.
1902 To
1903 specify an <<EOF>> rule for only the initial start condition, use
1904 .nf
1905
1906     <INITIAL><<EOF>>
1907
1908 .fi
1909 .PP
1910 These rules are useful for catching things like unclosed comments.
1911 An example:
1912 .nf
1913
1914     %x quote
1915     %%
1916
1917     ...other rules for dealing with quotes...
1918
1919     <quote><<EOF>>   {
1920              error( "unterminated quote" );
1921              yyterminate();
1922              }
1923     <<EOF>>  {
1924              if ( *++filelist )
1925                  yyin = fopen( *filelist, "r" );
1926              else
1927                 yyterminate();
1928              }
1929
1930 .fi
1931 .SH MISCELLANEOUS MACROS
1932 The macro
1933 .B YY_USER_ACTION
1934 can be defined to provide an action
1935 which is always executed prior to the matched rule's action.
1936 For example,
1937 it could be #define'd to call a routine to convert yytext to lower-case.
1938 When
1939 .B YY_USER_ACTION
1940 is invoked, the variable
1941 .I yy_act
1942 gives the number of the matched rule (rules are numbered starting with 1).
1943 Suppose you want to profile how often each of your rules is matched.
1944 The following would do the trick:
1945 .nf
1946
1947     #define YY_USER_ACTION ++ctr[yy_act]
1948
1949 .fi
1950 where
1951 .I ctr
1952 is an array to hold the counts for the different rules.
1953 Note that the macro
1954 .B YY_NUM_RULES
1955 gives the total number of rules (including the default rule, even if
1956 you use
1957 .B \-s),
1958 so a correct declaration for
1959 .I ctr
1960 is:
1961 .nf
1962
1963     int ctr[YY_NUM_RULES];
1964
1965 .fi
1966 .PP
1967 The macro
1968 .B YY_USER_INIT
1969 may be defined to provide an action which is always executed before
1970 the first scan (and before the scanner's internal initializations are done).
1971 For example, it could be used to call a routine to read
1972 in a data table or open a logging file.
1973 .PP
1974 The macro
1975 .B yy_set_interactive(is_interactive)
1976 can be used to control whether the current buffer is considered
1977 .I interactive.
1978 An interactive buffer is processed more slowly,
1979 but must be used when the scanner's input source is indeed
1980 interactive to avoid problems due to waiting to fill buffers
1981 (see the discussion of the
1982 .B \-I
1983 flag below).
1984 A non-zero value
1985 in the macro invocation marks the buffer as interactive, a zero
1986 value as non-interactive.
1987 Note that use of this macro overrides
1988 .B %option interactive ,
1989 .B %option always-interactive
1990 or
1991 .B %option never-interactive
1992 (see Options below).
1993 .B yy_set_interactive()
1994 must be invoked prior to beginning to scan the buffer that is
1995 (or is not) to be considered interactive.
1996 .PP
1997 The macro
1998 .B yy_set_bol(at_bol)
1999 can be used to control whether the current buffer's scanning
2000 context for the next token match is done as though at the
2001 beginning of a line.
2002 A non-zero macro argument makes rules anchored with
2003  '^' active, while a zero argument makes '^' rules inactive.
2004 .PP
2005 The macro
2006 .B YY_AT_BOL()
2007 returns true if the next token scanned from the current buffer
2008 will have '^' rules active, false otherwise.
2009 .PP
2010 In the generated scanner, the actions are all gathered in one large
2011 switch statement and separated using
2012 .B YY_BREAK,
2013 which may be redefined.
2014 By default, it is simply a "break", to separate
2015 each rule's action from the following rule's.
2016 Redefining
2017 .B YY_BREAK
2018 allows, for example, C++ users to
2019 #define YY_BREAK to do nothing (while being very careful that every
2020 rule ends with a "break" or a "return"!) to avoid suffering from
2021 unreachable statement warnings where because a rule's action ends with
2022 "return", the
2023 .B YY_BREAK
2024 is inaccessible.
2025 .SH VALUES AVAILABLE TO THE USER
2026 This section summarizes the various values available to the user
2027 in the rule actions.
2028 .IP -
2029 .B char *yytext
2030 holds the text of the current token.
2031 It may be modified but not lengthened
2032 (you cannot append characters to the end).
2033 .IP
2034 If the special directive
2035 .B %array
2036 appears in the first section of the scanner description, then
2037 .B yytext
2038 is instead declared
2039 .B char yytext[YYLMAX],
2040 where
2041 .B YYLMAX
2042 is a macro definition that you can redefine in the first section
2043 if you don't like the default value (generally 8KB).
2044 Using
2045 .B %array
2046 results in somewhat slower scanners, but the value of
2047 .B yytext
2048 becomes immune to calls to
2049 .I input()
2050 and
2051 .I unput(),
2052 which potentially destroy its value when
2053 .B yytext
2054 is a character pointer.
2055 The opposite of
2056 .B %array
2057 is
2058 .B %pointer,
2059 which is the default.
2060 .IP
2061 You cannot use
2062 .B %array
2063 when generating C++ scanner classes
2064 (the
2065 .B \-+
2066 flag).
2067 .IP -
2068 .B int yyleng
2069 holds the length of the current token.
2070 .IP -
2071 .B FILE *yyin
2072 is the file which by default
2073 .I flex
2074 reads from.
2075 It may be redefined but doing so only makes sense before
2076 scanning begins or after an EOF has been encountered.
2077 Changing it in the midst of scanning will have unexpected results since
2078 .I flex
2079 buffers its input; use
2080 .B yyrestart()
2081 instead.
2082 Once scanning terminates because an end-of-file
2083 has been seen, you can assign
2084 .I yyin
2085 at the new input file and then call the scanner again to continue scanning.
2086 .IP -
2087 .B void yyrestart( FILE *new_file )
2088 may be called to point
2089 .I yyin
2090 at the new input file.
2091 The switch-over to the new file is immediate
2092 (any previously buffered-up input is lost).
2093 Note that calling
2094 .B yyrestart()
2095 with
2096 .I yyin
2097 as an argument thus throws away the current input buffer and continues
2098 scanning the same input file.
2099 .IP -
2100 .B FILE *yyout
2101 is the file to which
2102 .B ECHO
2103 actions are done.
2104 It can be reassigned by the user.
2105 .IP -
2106 .B YY_CURRENT_BUFFER
2107 returns a
2108 .B YY_BUFFER_STATE
2109 handle to the current buffer.
2110 .IP -
2111 .B YY_START
2112 returns an integer value corresponding to the current start
2113 condition.
2114 You can subsequently use this value with
2115 .B BEGIN
2116 to return to that start condition.
2117 .SH INTERFACING WITH YACC
2118 One of the main uses of
2119 .I flex
2120 is as a companion to the
2121 .I yacc
2122 parser-generator.
2123 .I yacc
2124 parsers expect to call a routine named
2125 .B yylex()
2126 to find the next input token.
2127 The routine is supposed to
2128 return the type of the next token as well as putting any associated
2129 value in the global
2130 .B yylval.
2131 To use
2132 .I flex
2133 with
2134 .I yacc,
2135 one specifies the
2136 .B \-d
2137 option to
2138 .I yacc
2139 to instruct it to generate the file
2140 .B y.tab.h
2141 containing definitions of all the
2142 .B %tokens
2143 appearing in the
2144 .I yacc
2145 input.
2146 This file is then included in the
2147 .I flex
2148 scanner.
2149 For example, if one of the tokens is "TOK_NUMBER",
2150 part of the scanner might look like:
2151 .nf
2152
2153     %{
2154     #include "y.tab.h"
2155     %}
2156
2157     %%
2158
2159     [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
2160
2161 .fi
2162 .SH OPTIONS
2163 .I flex
2164 has the following options:
2165 .TP
2166 .B \-b, --backup
2167 Generate backing-up information to
2168 .I lex.backup.
2169 This is a list of scanner states which require backing up
2170 and the input characters on which they do so.
2171 By adding rules one
2172 can remove backing-up states.
2173 If
2174 .I all
2175 backing-up states are eliminated and
2176 .B \-Cf
2177 or
2178 .B \-CF
2179 is used, the generated scanner will run faster (see the
2180 .B \-p
2181 flag).
2182 Only users who wish to squeeze every last cycle out of their
2183 scanners need worry about this option.
2184 (See the section on Performance Considerations below.)
2185 .TP
2186 .B \-c
2187 is a do-nothing, deprecated option included for POSIX compliance.
2188 .TP
2189 .B \-d, \-\-debug
2190 makes the generated scanner run in
2191 .I debug
2192 mode.
2193 Whenever a pattern is recognized and the global
2194 .B yy_flex_debug
2195 is non-zero (which is the default),
2196 the scanner will write to
2197 .I stderr
2198 a line of the form:
2199 .nf
2200
2201     --accepting rule at line 53 ("the matched text")
2202
2203 .fi
2204 The line number refers to the location of the rule in the file
2205 defining the scanner (i.e., the file that was fed to flex).
2206 Messages are also generated when the scanner backs up, accepts the
2207 default rule, reaches the end of its input buffer (or encounters
2208 a NUL; at this point, the two look the same as far as the scanner's concerned),
2209 or reaches an end-of-file.
2210 .TP
2211 .B \-f, \-\-full
2212 specifies
2213 .I fast scanner.
2214 No table compression is done and stdio is bypassed.
2215 The result is large but fast.
2216 This option is equivalent to
2217 .B \-Cfr
2218 (see below).
2219 .TP
2220 .B \-h, \-\-help
2221 generates a "help" summary of
2222 .I flex's
2223 options to
2224 .I stdout
2225 and then exits.
2226 .B \-?
2227 and
2228 .B \-\-help
2229 are synonyms for
2230 .B \-h.
2231 .TP
2232 .B \-i, \-\-case-insensitive
2233 instructs
2234 .I flex
2235 to generate a
2236 .I case-insensitive
2237 scanner.
2238 The case of letters given in the
2239 .I flex
2240 input patterns will
2241 be ignored, and tokens in the input will be matched regardless of case.
2242 The matched text given in
2243 .I yytext
2244 will have the preserved case (i.e., it will not be folded).
2245 .TP
2246 .B \-l, \-\-lex\-compat
2247 turns on maximum compatibility with the original AT&T
2248 .I lex
2249 implementation.
2250 Note that this does not mean
2251 .I full
2252 compatibility.
2253 Use of this option costs a considerable amount of
2254 performance, and it cannot be used with the
2255 .B \-+, -f, -F, -Cf,
2256 or
2257 .B -CF
2258 options.
2259 For details on the compatibilities it provides, see the section
2260 "Incompatibilities With Lex And POSIX" below.
2261 This option also results
2262 in the name
2263 .B YY_FLEX_LEX_COMPAT
2264 being #define'd in the generated scanner.
2265 .TP
2266 .B \-n
2267 is another do-nothing, deprecated option included only for
2268 POSIX compliance.
2269 .TP
2270 .B \-p, \-\-perf\-report
2271 generates a performance report to stderr.
2272 The report consists of comments regarding features of the
2273 .I flex
2274 input file which will cause a serious loss of performance in the resulting
2275 scanner.
2276 If you give the flag twice, you will also get comments regarding
2277 features that lead to minor performance losses.
2278 .IP
2279 Note that the use of
2280 .B REJECT,
2281 .B %option yylineno,
2282 and variable trailing context (see the Deficiencies / Bugs section below)
2283 entails a substantial performance penalty; use of
2284 .I yymore(),
2285 the
2286 .B ^
2287 operator,
2288 and the
2289 .B \-I
2290 flag entail minor performance penalties.
2291 .TP
2292 .B \-s, \-\-no\-default
2293 causes the
2294 .I default rule
2295 (that unmatched scanner input is echoed to
2296 .I stdout)
2297 to be suppressed.
2298 If the scanner encounters input that does not
2299 match any of its rules, it aborts with an error.
2300 This option is
2301 useful for finding holes in a scanner's rule set.
2302 .TP
2303 .B \-t, \-\-stdout
2304 instructs
2305 .I flex
2306 to write the scanner it generates to standard output instead
2307 of
2308 .B lex.yy.c.
2309 .TP
2310 .B \-v, \-\-verbose
2311 specifies that
2312 .I flex
2313 should write to
2314 .I stderr
2315 a summary of statistics regarding the scanner it generates.
2316 Most of the statistics are meaningless to the casual
2317 .I flex
2318 user, but the first line identifies the version of
2319 .I flex
2320 (same as reported by
2321 .B \-V),
2322 and the next line the flags used when generating the scanner, including
2323 those that are on by default.
2324 .TP
2325 .B \-w, \-\-nowarn
2326 suppresses warning messages.
2327 .TP
2328 .B \-B, \-\-batch
2329 instructs
2330 .I flex
2331 to generate a
2332 .I batch
2333 scanner, the opposite of
2334 .I interactive
2335 scanners generated by
2336 .B \-I
2337 (see below).
2338 In general, you use
2339 .B \-B
2340 when you are
2341 .I certain
2342 that your scanner will never be used interactively, and you want to
2343 squeeze a
2344 .I little
2345 more performance out of it.
2346 If your goal is instead to squeeze out a
2347 .I lot
2348 more performance, you should be using the
2349 .B \-Cf
2350 or
2351 .B \-CF
2352 options (discussed below), which turn on
2353 .B \-B
2354 automatically anyway.
2355 .TP
2356 .B \-F, \-\-fast
2357 specifies that the
2358 .I fast
2359 scanner table representation should be used (and stdio
2360 bypassed).
2361 This representation is about as fast as the full table representation
2362 .B (-f),
2363 and for some sets of patterns will be considerably smaller (and for
2364 others, larger).
2365 In general, if the pattern set contains both "keywords"
2366 and a catch-all, "identifier" rule, such as in the set:
2367 .nf
2368
2369     "case"    return TOK_CASE;
2370     "switch"  return TOK_SWITCH;
2371     ...
2372     "default" return TOK_DEFAULT;
2373     [a-z]+    return TOK_ID;
2374
2375 .fi
2376 then you're better off using the full table representation.
2377 If only
2378 the "identifier" rule is present and you then use a hash table or some such
2379 to detect the keywords, you're better off using
2380 .B -F.
2381 .IP
2382 This option is equivalent to
2383 .B \-CFr
2384 (see below).
2385 It cannot be used with
2386 .B \-+.
2387 .TP
2388 .B \-I, \-\-interactive
2389 instructs
2390 .I flex
2391 to generate an
2392 .I interactive
2393 scanner.
2394 An interactive scanner is one that only looks ahead to decide
2395 what token has been matched if it absolutely must.
2396 It turns out that
2397 always looking one extra character ahead, even if the scanner has already
2398 seen enough text to disambiguate the current token, is a bit faster than
2399 only looking ahead when necessary.
2400 But scanners that always look ahead
2401 give dreadful interactive performance; for example, when a user types
2402 a newline, it is not recognized as a newline token until they enter
2403 .I another
2404 token, which often means typing in another whole line.
2405 .IP
2406 .I Flex
2407 scanners default to
2408 .I interactive
2409 unless you use the
2410 .B \-Cf
2411 or
2412 .B \-CF
2413 table-compression options (see below).
2414 That's because if you're looking
2415 for high-performance you should be using one of these options, so if you
2416 didn't,
2417 .I flex
2418 assumes you'd rather trade off a bit of run-time performance for intuitive
2419 interactive behavior.
2420 Note also that you
2421 .I cannot
2422 use
2423 .B \-I
2424 in conjunction with
2425 .B \-Cf
2426 or
2427 .B \-CF.
2428 Thus, this option is not really needed; it is on by default for all those
2429 cases in which it is allowed.
2430 .IP
2431 Note that if
2432 .B isatty()
2433 returns false for the scanner input, flex will revert to batch mode, even if
2434 .B \-I
2435 was specified.
2436 To force interactive mode no matter what, use
2437 .B %option always-interactive
2438 (see Options below).
2439 .IP
2440 You can force a scanner to
2441 .I not
2442 be interactive by using
2443 .B \-B
2444 (see above).
2445 .TP
2446 .B \-L, \-\-noline
2447 instructs
2448 .I flex
2449 not to generate
2450 .B #line
2451 directives.
2452 Without this option,
2453 .I flex
2454 peppers the generated scanner
2455 with #line directives so error messages in the actions will be correctly
2456 located with respect to either the original
2457 .I flex
2458 input file (if the errors are due to code in the input file), or
2459 .B lex.yy.c
2460 (if the errors are
2461 .I flex's
2462 fault -- you should report these sorts of errors to the email address
2463 given below).
2464 .TP
2465 .B \-T, \-\-trace
2466 makes
2467 .I flex
2468 run in
2469 .I trace
2470 mode.
2471 It will generate a lot of messages to
2472 .I stderr
2473 concerning
2474 the form of the input and the resultant non-deterministic and deterministic
2475 finite automata.
2476 This option is mostly for use in maintaining
2477 .I flex.
2478 .TP
2479 .B \-V, \-\-version
2480 prints the version number to
2481 .I stdout
2482 and exits.
2483 .B \-\-version
2484 is a synonym for
2485 .B \-V.
2486 .TP
2487 .B \-7, \-\-7bit
2488 instructs
2489 .I flex
2490 to generate a 7-bit scanner, i.e., one which can only recognize 7-bit
2491 characters in its input.
2492 The advantage of using
2493 .B \-7
2494 is that the scanner's tables can be up to half the size of those generated
2495 using the
2496 .B \-8
2497 option (see below).
2498 The disadvantage is that such scanners often hang
2499 or crash if their input contains an 8-bit character.
2500 .IP
2501 Note, however, that unless you generate your scanner using the
2502 .B \-Cf
2503 or
2504 .B \-CF
2505 table compression options, use of
2506 .B \-7
2507 will save only a small amount of table space, and make your scanner
2508 considerably less portable.
2509 .I Flex's
2510 default behavior is to generate an 8-bit scanner unless you use the
2511 .B \-Cf
2512 or
2513 .B \-CF,
2514 in which case
2515 .I flex
2516 defaults to generating 7-bit scanners unless your site was always
2517 configured to generate 8-bit scanners (as will often be the case
2518 with non-USA sites).
2519 You can tell whether flex generated a 7-bit
2520 or an 8-bit scanner by inspecting the flag summary in the
2521 .B \-v
2522 output as described above.
2523 .IP
2524 Note that if you use
2525 .B \-Cfe
2526 or
2527 .B \-CFe
2528 (those table compression options, but also using equivalence classes as
2529 discussed see below), flex still defaults to generating an 8-bit
2530 scanner, since usually with these compression options full 8-bit tables
2531 are not much more expensive than 7-bit tables.
2532 .TP
2533 .B \-8, \-\-8bit
2534 instructs
2535 .I flex
2536 to generate an 8-bit scanner, i.e., one which can recognize 8-bit
2537 characters.
2538 This flag is only needed for scanners generated using
2539 .B \-Cf
2540 or
2541 .B \-CF,
2542 as otherwise flex defaults to generating an 8-bit scanner anyway.
2543 .IP
2544 See the discussion of
2545 .B \-7
2546 above for flex's default behavior and the tradeoffs between 7-bit
2547 and 8-bit scanners.
2548 .TP
2549 .B \-+, \-\-c++
2550 specifies that you want flex to generate a C++
2551 scanner class.
2552 See the section on Generating C++ Scanners below for
2553 details.
2554 .TP
2555 .B \-C[aefFmr]
2556 controls the degree of table compression and, more generally, trade-offs
2557 between small scanners and fast scanners.
2558 .IP
2559 .B \-Ca, \-\-align
2560 ("align") instructs flex to trade off larger tables in the
2561 generated scanner for faster performance because the elements of
2562 the tables are better aligned for memory access and computation.
2563 On some
2564 RISC architectures, fetching and manipulating longwords is more efficient
2565 than with smaller-sized units such as shortwords.
2566 This option can
2567 double the size of the tables used by your scanner.
2568 .IP
2569 .B \-Ce, \-\-ecs
2570 directs
2571 .I flex
2572 to construct
2573 .I equivalence classes,
2574 i.e., sets of characters
2575 which have identical lexical properties (for example, if the only
2576 appearance of digits in the
2577 .I flex
2578 input is in the character class
2579 "[0-9]" then the digits '0', '1', ..., '9' will all be put
2580 in the same equivalence class).
2581 Equivalence classes usually give
2582 dramatic reductions in the final table/object file sizes (typically
2583 a factor of 2-5) and are pretty cheap performance-wise (one array
2584 look-up per character scanned).
2585 .IP
2586 .B \-Cf
2587 specifies that the
2588 .I full
2589 scanner tables should be generated -
2590 .I flex
2591 should not compress the
2592 tables by taking advantages of similar transition functions for
2593 different states.
2594 .IP
2595 .B \-CF
2596 specifies that the alternative fast scanner representation (described
2597 above under the
2598 .B \-F
2599 flag)
2600 should be used.
2601 This option cannot be used with
2602 .B \-+.
2603 .IP
2604 .B \-Cm, \-\-meta-ecs
2605 directs
2606 .I flex
2607 to construct
2608 .I meta-equivalence classes,
2609 which are sets of equivalence classes (or characters, if equivalence
2610 classes are not being used) that are commonly used together.
2611 Meta-equivalence
2612 classes are often a big win when using compressed tables, but they
2613 have a moderate performance impact (one or two "if" tests and one
2614 array look-up per character scanned).
2615 .IP
2616 .B \-Cr, \-\-read
2617 causes the generated scanner to
2618 .I bypass
2619 use of the standard I/O library (stdio) for input.
2620 Instead of calling
2621 .B fread()
2622 or
2623 .B getc(),
2624 the scanner will use the
2625 .B read()
2626 system call, resulting in a performance gain which varies from system
2627 to system, but in general is probably negligible unless you are also using
2628 .B \-Cf
2629 or
2630 .B \-CF.
2631 Using
2632 .B \-Cr
2633 can cause strange behavior if, for example, you read from
2634 .I yyin
2635 using stdio prior to calling the scanner (because the scanner will miss
2636 whatever text your previous reads left in the stdio input buffer).
2637 .IP
2638 .B \-Cr
2639 has no effect if you define
2640 .B YY_INPUT
2641 (see The Generated Scanner above).
2642 .IP
2643 A lone
2644 .B \-C
2645 specifies that the scanner tables should be compressed but neither
2646 equivalence classes nor meta-equivalence classes should be used.
2647 .IP
2648 The options
2649 .B \-Cf
2650 or
2651 .B \-CF
2652 and
2653 .B \-Cm
2654 do not make sense together - there is no opportunity for meta-equivalence
2655 classes if the table is not being compressed.
2656 Otherwise the options
2657 may be freely mixed, and are cumulative.
2658 .IP
2659 The default setting is
2660 .B \-Cem,
2661 which specifies that
2662 .I flex
2663 should generate equivalence classes
2664 and meta-equivalence classes.
2665 This setting provides the highest degree of table compression.
2666 You can trade off
2667 faster-executing scanners at the cost of larger tables with
2668 the following generally being true:
2669 .nf
2670
2671     slowest & smallest
2672           -Cem
2673           -Cm
2674           -Ce
2675           -C
2676           -C{f,F}e
2677           -C{f,F}
2678           -C{f,F}a
2679     fastest & largest
2680
2681 .fi
2682 Note that scanners with the smallest tables are usually generated and
2683 compiled the quickest, so
2684 during development you will usually want to use the default, maximal
2685 compression.
2686 .IP
2687 .B \-Cfe
2688 is often a good compromise between speed and size for production
2689 scanners.
2690 .TP
2691 .B \-ooutput, \-\-outputfile=FILE
2692 directs flex to write the scanner to the file
2693 .B output
2694 instead of
2695 .B lex.yy.c.
2696 If you combine
2697 .B \-o
2698 with the
2699 .B \-t
2700 option, then the scanner is written to
2701 .I stdout
2702 but its
2703 .B #line
2704 directives (see the
2705 .B \\-L
2706 option above) refer to the file
2707 .B output.
2708 .TP
2709 .B \-Pprefix, \-\-prefix=STRING
2710 changes the default
2711 .I "yy"
2712 prefix used by
2713 .I flex
2714 for all globally-visible variable and function names to instead be
2715 .I prefix.
2716 For example,
2717 .B \-Pfoo
2718 changes the name of
2719 .B yytext
2720 to
2721 .B footext.
2722 It also changes the name of the default output file from
2723 .B lex.yy.c
2724 to
2725 .B lex.foo.c.
2726 Here are all of the names affected:
2727 .nf
2728
2729     yy_create_buffer
2730     yy_delete_buffer
2731     yy_flex_debug
2732     yy_init_buffer
2733     yy_flush_buffer
2734     yy_load_buffer_state
2735     yy_switch_to_buffer
2736     yyin
2737     yyleng
2738     yylex
2739     yylineno
2740     yyout
2741     yyrestart
2742     yytext
2743     yywrap
2744
2745 .fi
2746 (If you are using a C++ scanner, then only
2747 .B yywrap
2748 and
2749 .B yyFlexLexer
2750 are affected.)
2751 Within your scanner itself, you can still refer to the global variables
2752 and functions using either version of their name; but externally, they
2753 have the modified name.
2754 .IP
2755 This option lets you easily link together multiple
2756 .I flex
2757 programs into the same executable.
2758 Note, though, that using this option also renames
2759 .B yywrap(),
2760 so you now
2761 .I must
2762 either
2763 provide your own (appropriately-named) version of the routine for your
2764 scanner, or use
2765 .B %option noyywrap,
2766 as linking with
2767 .B \-ll
2768 no longer provides one for you by default.
2769 .TP
2770 .B \-Sskeleton_file, \-\-skel=FILE
2771 overrides the default skeleton file from which
2772 .I flex
2773 constructs its scanners.
2774 You'll never need this option unless you are doing
2775 .I flex
2776 maintenance or development.
2777 .TP
2778 .B \-X, \-\-posix\-compat
2779 maximal compatibility with POSIX lex.
2780 .TP
2781 .B \-\-yylineno
2782 track line count in yylineno.
2783 .TP
2784 .B \-\-yyclass=NAME
2785 name of C++ class.
2786 .TP
2787 .B \-\-header\-file=FILE
2788 create a C header file in addition to the scanner.
2789 .TP
2790 .B \-\-tables\-file[=FILE]
2791 write tables to FILE.
2792 .TP
2793 .B \\-Dmacro[=defn]
2794 #define macro defn (default defn is '1').
2795 .TP
2796 .B \-R,  \-\-reentrant
2797 generate a reentrant C scanner
2798 .TP
2799 .B \-\-bison\-bridge
2800 scanner for bison pure parser.
2801 .TP
2802 .B \-\-bison\-locations
2803 include yylloc support.
2804 .TP
2805 .B \-\-stdinit
2806 initialize yyin/yyout to stdin/stdout.
2807 .TP
2808 .B \-\-noansi\-definitions old\-style function definitions.
2809 .TP
2810 .B \-\-noansi\-prototypes
2811 empty parameter list in prototypes.
2812 .TP
2813 .B \-\-nounistd
2814 do not include <unistd.h>.
2815 .TP
2816 .B \-\-noFUNCTION
2817 do not generate a particular FUNCTION.
2818 .PP
2819 .I flex
2820 also provides a mechanism for controlling options within the
2821 scanner specification itself, rather than from the flex command-line.
2822 This is done by including
2823 .B %option
2824 directives in the first section of the scanner specification.
2825 You can specify multiple options with a single
2826 .B %option
2827 directive, and multiple directives in the first section of your flex input
2828 file.
2829 .PP
2830 Most options are given simply as names, optionally preceded by the
2831 word "no" (with no intervening whitespace) to negate their meaning.
2832 A number are equivalent to flex flags or their negation:
2833 .nf
2834
2835     7bit            -7 option
2836     8bit            -8 option
2837     align           -Ca option
2838     backup          -b option
2839     batch           -B option
2840     c++             -+ option
2841
2842     caseful or
2843     case-sensitive  opposite of -i (default)
2844
2845     case-insensitive or
2846     caseless        -i option
2847
2848     debug           -d option
2849     default         opposite of -s option
2850     ecs             -Ce option
2851     fast            -F option
2852     full            -f option
2853     interactive     -I option
2854     lex-compat      -l option
2855     meta-ecs        -Cm option
2856     perf-report     -p option
2857     read            -Cr option
2858     stdout          -t option
2859     verbose         -v option
2860     warn            opposite of -w option
2861                     (use "%option nowarn" for -w)
2862
2863     array           equivalent to "%array"
2864     pointer         equivalent to "%pointer" (default)
2865
2866 .fi
2867 Some
2868 .B %option's
2869 provide features otherwise not available:
2870 .TP
2871 .B always-interactive
2872 instructs flex to generate a scanner which always considers its input
2873 "interactive".
2874 Normally, on each new input file the scanner calls
2875 .B isatty()
2876 in an attempt to determine whether
2877 the scanner's input source is interactive and thus should be read a
2878 character at a time.
2879 When this option is used, however, then no
2880 such call is made.
2881 .TP
2882 .B main
2883 directs flex to provide a default
2884 .B main()
2885 program for the scanner, which simply calls
2886 .B yylex().
2887 This option implies
2888 .B noyywrap
2889 (see below).
2890 .TP
2891 .B never-interactive
2892 instructs flex to generate a scanner which never considers its input
2893 "interactive" (again, no call made to
2894 .B isatty()).
2895 This is the opposite of
2896 .B always-interactive.
2897 .TP
2898 .B stack
2899 enables the use of start condition stacks (see Start Conditions above).
2900 .TP
2901 .B stdinit
2902 if set (i.e.,
2903 .B %option stdinit)
2904 initializes
2905 .I yyin
2906 and
2907 .I yyout
2908 to
2909 .I stdin
2910 and
2911 .I stdout,
2912 instead of the default of
2913 .I nil.
2914 Some existing
2915 .I lex
2916 programs depend on this behavior, even though it is not compliant with
2917 ANSI C, which does not require
2918 .I stdin
2919 and
2920 .I stdout
2921 to be compile-time constant.
2922 .TP
2923 .B yylineno
2924 directs
2925 .I flex
2926 to generate a scanner that maintains the number of the current line
2927 read from its input in the global variable
2928 .B yylineno.
2929 This option is implied by
2930 .B %option lex-compat.
2931 .TP
2932 .B yywrap
2933 if unset (i.e.,
2934 .B %option noyywrap),
2935 makes the scanner not call
2936 .B yywrap()
2937 upon an end-of-file, but simply assume that there are no more
2938 files to scan (until the user points
2939 .I yyin
2940 at a new file and calls
2941 .B yylex()
2942 again).
2943 .PP
2944 .I flex
2945 scans your rule actions to determine whether you use the
2946 .B REJECT
2947 or
2948 .B yymore()
2949 features.
2950 The
2951 .B reject
2952 and
2953 .B yymore
2954 options are available to override its decision as to whether you use the
2955 options, either by setting them (e.g.,
2956 .B %option reject)
2957 to indicate the feature is indeed used, or
2958 unsetting them to indicate it actually is not used
2959 (e.g.,
2960 .B %option noyymore).
2961 .PP
2962 Three options take string-delimited values, offset with '=':
2963 .nf
2964
2965     %option outfile="ABC"
2966
2967 .fi
2968 is equivalent to
2969 .B -oABC,
2970 and
2971 .nf
2972
2973     %option prefix="XYZ"
2974
2975 .fi
2976 is equivalent to
2977 .B -PXYZ.
2978 Finally,
2979 .nf
2980
2981     %option yyclass="foo"
2982
2983 .fi
2984 only applies when generating a C++ scanner (
2985 .B \-+
2986 option).
2987 It informs
2988 .I flex
2989 that you have derived
2990 .B foo
2991 as a subclass of
2992 .B yyFlexLexer,
2993 so
2994 .I flex
2995 will place your actions in the member function
2996 .B foo::yylex()
2997 instead of
2998 .B yyFlexLexer::yylex().
2999 It also generates a
3000 .B yyFlexLexer::yylex()
3001 member function that emits a run-time error (by invoking
3002 .B yyFlexLexer::LexerError())
3003 if called.
3004 See Generating C++ Scanners, below, for additional information.
3005 .PP
3006 A number of options are available for lint purists who want to suppress
3007 the appearance of unneeded routines in the generated scanner.
3008 Each of the following, if unset
3009 (e.g.,
3010 .B %option nounput
3011 ), results in the corresponding routine not appearing in
3012 the generated scanner:
3013 .nf
3014
3015     input, unput
3016     yy_push_state, yy_pop_state, yy_top_state
3017     yy_scan_buffer, yy_scan_bytes, yy_scan_string
3018
3019 .fi
3020 (though
3021 .B yy_push_state()
3022 and friends won't appear anyway unless you use
3023 .B %option stack).
3024 .SH PERFORMANCE CONSIDERATIONS
3025 The main design goal of
3026 .I flex
3027 is that it generate high-performance scanners.
3028 It has been optimized
3029 for dealing well with large sets of rules.
3030 Aside from the effects on scanner speed of the table compression
3031 .B \-C
3032 options outlined above,
3033 there are a number of options/actions which degrade performance.
3034 These are, from most expensive to least:
3035 .nf
3036
3037     REJECT
3038     %option yylineno
3039     arbitrary trailing context
3040
3041     pattern sets that require backing up
3042     %array
3043     %option interactive
3044     %option always-interactive
3045
3046     '^' beginning-of-line operator
3047     yymore()
3048
3049 .fi
3050 with the first three all being quite expensive and the last two
3051 being quite cheap.
3052 Note also that
3053 .B unput()
3054 is implemented as a routine call that potentially does quite a bit of
3055 work, while
3056 .B yyless()
3057 is a quite-cheap macro; so if just putting back some excess text you
3058 scanned, use
3059 .B yyless().
3060 .PP
3061 .B REJECT
3062 should be avoided at all costs when performance is important.
3063 It is a particularly expensive option.
3064 .PP
3065 Getting rid of backing up is messy and often may be an enormous
3066 amount of work for a complicated scanner.
3067 In principal, one begins by using the
3068 .B \-b
3069 flag to generate a
3070 .I lex.backup
3071 file.
3072 For example, on the input
3073 .nf
3074
3075     %%
3076     foo        return TOK_KEYWORD;
3077     foobar     return TOK_KEYWORD;
3078
3079 .fi
3080 the file looks like:
3081 .nf
3082
3083     State #6 is non-accepting -
3084      associated rule line numbers:
3085            2       3
3086      out-transitions: [ o ]
3087      jam-transitions: EOF [ \\001-n  p-\\177 ]
3088
3089     State #8 is non-accepting -
3090      associated rule line numbers:
3091            3
3092      out-transitions: [ a ]
3093      jam-transitions: EOF [ \\001-`  b-\\177 ]
3094
3095     State #9 is non-accepting -
3096      associated rule line numbers:
3097            3
3098      out-transitions: [ r ]
3099      jam-transitions: EOF [ \\001-q  s-\\177 ]
3100
3101     Compressed tables always back up.
3102
3103 .fi
3104 The first few lines tell us that there's a scanner state in
3105 which it can make a transition on an 'o' but not on any other
3106 character, and that in that state the currently scanned text does not match
3107 any rule.
3108 The state occurs when trying to match the rules found
3109 at lines 2 and 3 in the input file.
3110 If the scanner is in that state and then reads
3111 something other than an 'o', it will have to back up to find
3112 a rule which is matched.
3113 With a bit of headscratching one can see that this must be the
3114 state it's in when it has seen "fo".
3115 When this has happened,
3116 if anything other than another 'o' is seen, the scanner will
3117 have to back up to simply match the 'f' (by the default rule).
3118 .PP
3119 The comment regarding State #8 indicates there's a problem
3120 when "foob" has been scanned.
3121 Indeed, on any character other
3122 than an 'a', the scanner will have to back up to accept "foo".
3123 Similarly, the comment for State #9 concerns when "fooba" has
3124 been scanned and an 'r' does not follow.
3125 .PP
3126 The final comment reminds us that there's no point going to
3127 all the trouble of removing backing up from the rules unless
3128 we're using
3129 .B \-Cf
3130 or
3131 .B \-CF,
3132 since there's no performance gain doing so with compressed scanners.
3133 .PP
3134 The way to remove the backing up is to add "error" rules:
3135 .nf
3136
3137     %%
3138     foo         return TOK_KEYWORD;
3139     foobar      return TOK_KEYWORD;
3140
3141     fooba       |
3142     foob        |
3143     fo          {
3144                 /* false alarm, not really a keyword */
3145                 return TOK_ID;
3146                 }
3147
3148 .fi
3149 .PP
3150 Eliminating backing up among a list of keywords can also be
3151 done using a "catch-all" rule:
3152 .nf
3153
3154     %%
3155     foo         return TOK_KEYWORD;
3156     foobar      return TOK_KEYWORD;
3157
3158     [a-z]+      return TOK_ID;
3159
3160 .fi
3161 This is usually the best solution when appropriate.
3162 .PP
3163 Backing up messages tend to cascade.
3164 With a complicated set of rules it's not uncommon to get hundreds
3165 of messages.
3166 If one can decipher them, though, it often
3167 only takes a dozen or so rules to eliminate the backing up (though
3168 it's easy to make a mistake and have an error rule accidentally match
3169 a valid token.
3170 A possible future
3171 .I flex
3172 feature will be to automatically add rules to eliminate backing up).
3173 .PP
3174 It's important to keep in mind that you gain the benefits of eliminating
3175 backing up only if you eliminate
3176 .I every
3177 instance of backing up.
3178 Leaving just one means you gain nothing.
3179 .PP
3180 .I Variable
3181 trailing context (where both the leading and trailing parts do not have
3182 a fixed length) entails almost the same performance loss as
3183 .B REJECT
3184 (i.e., substantial).
3185 So when possible a rule like:
3186 .nf
3187
3188     %%
3189     mouse|rat/(cat|dog)   run();
3190
3191 .fi
3192 is better written:
3193 .nf
3194
3195     %%
3196     mouse/cat|dog         run();
3197     rat/cat|dog           run();
3198
3199 .fi
3200 or as
3201 .nf
3202
3203     %%
3204     mouse|rat/cat         run();
3205     mouse|rat/dog         run();
3206
3207 .fi
3208 Note that here the special '|' action does
3209 .I not
3210 provide any savings, and can even make things worse (see
3211 Deficiencies / Bugs below).
3212 .LP
3213 Another area where the user can increase a scanner's performance
3214 (and one that's easier to implement) arises from the fact that
3215 the longer the tokens matched, the faster the scanner will run.
3216 This is because with long tokens the processing of most input
3217 characters takes place in the (short) inner scanning loop, and
3218 does not often have to go through the additional work of setting up
3219 the scanning environment (e.g.,
3220 .B yytext)
3221 for the action.
3222 Recall the scanner for C comments:
3223 .nf
3224
3225     %x comment
3226     %%
3227             int line_num = 1;
3228
3229     "/*"         BEGIN(comment);
3230
3231     <comment>[^*\\n]*
3232     <comment>"*"+[^*/\\n]*
3233     <comment>\\n             ++line_num;
3234     <comment>"*"+"/"        BEGIN(INITIAL);
3235
3236 .fi
3237 This could be sped up by writing it as:
3238 .nf
3239
3240     %x comment
3241     %%
3242             int line_num = 1;
3243
3244     "/*"         BEGIN(comment);
3245
3246     <comment>[^*\\n]*
3247     <comment>[^*\\n]*\\n      ++line_num;
3248     <comment>"*"+[^*/\\n]*
3249     <comment>"*"+[^*/\\n]*\\n ++line_num;
3250     <comment>"*"+"/"        BEGIN(INITIAL);
3251
3252 .fi
3253 Now instead of each newline requiring the processing of another
3254 action, recognizing the newlines is "distributed" over the other rules
3255 to keep the matched text as long as possible.
3256 Note that
3257 .I adding
3258 rules does
3259 .I not
3260 slow down the scanner!  The speed of the scanner is independent
3261 of the number of rules or (modulo the considerations given at the
3262 beginning of this section) how complicated the rules are with
3263 regard to operators such as '*' and '|'.
3264 .PP
3265 A final example in speeding up a scanner: suppose you want to scan
3266 through a file containing identifiers and keywords, one per line
3267 and with no other extraneous characters, and recognize all the
3268 keywords.
3269 A natural first approach is:
3270 .nf
3271
3272     %%
3273     asm      |
3274     auto     |
3275     break    |
3276     ... etc ...
3277     volatile |
3278     while    /* it's a keyword */
3279
3280     .|\\n     /* it's not a keyword */
3281
3282 .fi
3283 To eliminate the back-tracking, introduce a catch-all rule:
3284 .nf
3285
3286     %%
3287     asm      |
3288     auto     |
3289     break    |
3290     ... etc ...
3291     volatile |
3292     while    /* it's a keyword */
3293
3294     [a-z]+   |
3295     .|\\n     /* it's not a keyword */
3296
3297 .fi
3298 Now, if it's guaranteed that there's exactly one word per line,
3299 then we can reduce the total number of matches by a half by
3300 merging in the recognition of newlines with that of the other
3301 tokens:
3302 .nf
3303
3304     %%
3305     asm\\n    |
3306     auto\\n   |
3307     break\\n  |
3308     ... etc ...
3309     volatile\\n |
3310     while\\n  /* it's a keyword */
3311
3312     [a-z]+\\n |
3313     .|\\n     /* it's not a keyword */
3314
3315 .fi
3316 One has to be careful here, as we have now reintroduced backing up
3317 into the scanner.
3318 In particular, while
3319 .I we
3320 know that there will never be any characters in the input stream
3321 other than letters or newlines,
3322 .I flex
3323 can't figure this out, and it will plan for possibly needing to back up
3324 when it has scanned a token like "auto" and then the next character
3325 is something other than a newline or a letter.
3326 Previously it would
3327 then just match the "auto" rule and be done, but now it has no "auto"
3328 rule, only an "auto\\n" rule.
3329 To eliminate the possibility of backing up,
3330 we could either duplicate all rules but without final newlines, or,
3331 since we never expect to encounter such an input and therefore don't
3332 how it's classified, we can introduce one more catch-all rule, this
3333 one which doesn't include a newline:
3334 .nf
3335
3336     %%
3337     asm\\n    |
3338     auto\\n   |
3339     break\\n  |
3340     ... etc ...
3341     volatile\\n |
3342     while\\n  /* it's a keyword */
3343
3344     [a-z]+\\n |
3345     [a-z]+   |
3346     .|\\n     /* it's not a keyword */
3347
3348 .fi
3349 Compiled with
3350 .B \-Cf,
3351 this is about as fast as one can get a
3352 .I flex
3353 scanner to go for this particular problem.
3354 .PP
3355 A final note:
3356 .I flex
3357 is slow when matching NUL's, particularly when a token contains
3358 multiple NUL's.
3359 It's best to write rules which match
3360 .I short
3361 amounts of text if it's anticipated that the text will often include NUL's.
3362 .PP
3363 Another final note regarding performance: as mentioned above in the section
3364 How the Input is Matched, dynamically resizing
3365 .B yytext
3366 to accommodate huge tokens is a slow process because it presently requires that
3367 the (huge) token be rescanned from the beginning.
3368 Thus if performance is
3369 vital, you should attempt to match "large" quantities of text but not
3370 "huge" quantities, where the cutoff between the two is at about 8K
3371 characters/token.
3372 .SH GENERATING C++ SCANNERS
3373 .I flex
3374 provides two different ways to generate scanners for use with C++.
3375 The first way is to simply compile a scanner generated by
3376 .I flex
3377 using a C++ compiler instead of a C compiler.
3378 You should not encounter
3379 any compilations errors (please report any you find to the email address
3380 given in the Author section below).
3381 You can then use C++ code in your rule actions instead of C code.
3382 Note that the default input source for your scanner remains
3383 .I yyin,
3384 and default echoing is still done to
3385 .I yyout.
3386 Both of these remain
3387 .I FILE *
3388 variables and not C++
3389 .I streams.
3390 .PP
3391 You can also use
3392 .I flex
3393 to generate a C++ scanner class, using the
3394 .B \-+
3395 option (or, equivalently,
3396 .B %option c++),
3397 which is automatically specified if the name of the flex
3398 executable ends in a '+', such as
3399 .I flex++.
3400 When using this option, flex defaults to generating the scanner to the file
3401 .B lex.yy.cc
3402 instead of
3403 .B lex.yy.c.
3404 The generated scanner includes the header file
3405 .I FlexLexer.h,
3406 which defines the interface to two C++ classes.
3407 .PP
3408 The first class,
3409 .B FlexLexer,
3410 provides an abstract base class defining the general scanner class
3411 interface.
3412 It provides the following member functions:
3413 .TP
3414 .B const char* YYText()
3415 returns the text of the most recently matched token, the equivalent of
3416 .B yytext.
3417 .TP
3418 .B int YYLeng()
3419 returns the length of the most recently matched token, the equivalent of
3420 .B yyleng.
3421 .TP
3422 .B int lineno() const
3423 returns the current input line number
3424 (see
3425 .B %option yylineno),
3426 or
3427 .B 1
3428 if
3429 .B %option yylineno
3430 was not used.
3431 .TP
3432 .B void set_debug( int flag )
3433 sets the debugging flag for the scanner, equivalent to assigning to
3434 .B yy_flex_debug
3435 (see the Options section above).
3436 Note that you must build the scanner using
3437 .B %option debug
3438 to include debugging information in it.
3439 .TP
3440 .B int debug() const
3441 returns the current setting of the debugging flag.
3442 .PP
3443 Also provided are member functions equivalent to
3444 .B yy_switch_to_buffer(),
3445 .B yy_create_buffer()
3446 (though the first argument is an
3447 .B std::istream*
3448 object pointer and not a
3449 .B FILE*),
3450 .B yy_flush_buffer(),
3451 .B yy_delete_buffer(),
3452 and
3453 .B yyrestart()
3454 (again, the first argument is a
3455 .B std::istream*
3456 object pointer).
3457 .PP
3458 The second class defined in
3459 .I FlexLexer.h
3460 is
3461 .B yyFlexLexer,
3462 which is derived from
3463 .B FlexLexer.
3464 It defines the following additional member functions:
3465 .TP
3466 .B
3467 yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 )
3468 constructs a
3469 .B yyFlexLexer
3470 object using the given streams for input and output.
3471 If not specified, the streams default to
3472 .B cin
3473 and
3474 .B cout,
3475 respectively.
3476 .TP
3477 .B virtual int yylex()
3478 performs the same role is
3479 .B yylex()
3480 does for ordinary flex scanners: it scans the input stream, consuming
3481 tokens, until a rule's action returns a value.
3482 If you derive a subclass
3483 .B S
3484 from
3485 .B yyFlexLexer
3486 and want to access the member functions and variables of
3487 .B S
3488 inside
3489 .B yylex(),
3490 then you need to use
3491 .B %option yyclass="S"
3492 to inform
3493 .I flex
3494 that you will be using that subclass instead of
3495 .B yyFlexLexer.
3496 In this case, rather than generating
3497 .B yyFlexLexer::yylex(),
3498 .I flex
3499 generates
3500 .B S::yylex()
3501 (and also generates a dummy
3502 .B yyFlexLexer::yylex()
3503 that calls
3504 .B yyFlexLexer::LexerError()
3505 if called).
3506 .TP
3507 .B
3508 virtual void switch_streams(std::istream* new_in = 0,
3509 .B
3510 std::ostream* new_out = 0)
3511 reassigns
3512 .B yyin
3513 to
3514 .B new_in
3515 (if non-nil)
3516 and
3517 .B yyout
3518 to
3519 .B new_out
3520 (ditto), deleting the previous input buffer if
3521 .B yyin
3522 is reassigned.
3523 .TP
3524 .B
3525 int yylex( std::istream* new_in, std::ostream* new_out = 0 )
3526 first switches the input streams via
3527 .B switch_streams( new_in, new_out )
3528 and then returns the value of
3529 .B yylex().
3530 .PP
3531 In addition,
3532 .B yyFlexLexer
3533 defines the following protected virtual functions which you can redefine
3534 in derived classes to tailor the scanner:
3535 .TP
3536 .B
3537 virtual int LexerInput( char* buf, int max_size )
3538 reads up to
3539 .B max_size
3540 characters into
3541 .B buf
3542 and returns the number of characters read.
3543 To indicate end-of-input, return 0 characters.
3544 Note that "interactive" scanners (see the
3545 .B \-B
3546 and
3547 .B \-I
3548 flags) define the macro
3549 .B YY_INTERACTIVE.
3550 If you redefine
3551 .B LexerInput()
3552 and need to take different actions depending on whether or not
3553 the scanner might be scanning an interactive input source, you can
3554 test for the presence of this name via
3555 .B #ifdef.
3556 .TP
3557 .B
3558 virtual void LexerOutput( const char* buf, int size )
3559 writes out
3560 .B size
3561 characters from the buffer
3562 .B buf,
3563 which, while NUL-terminated, may also contain "internal" NUL's if
3564 the scanner's rules can match text with NUL's in them.
3565 .TP
3566 .B
3567 virtual void LexerError( const char* msg )
3568 reports a fatal error message.
3569 The default version of this function writes the message to the stream
3570 .B cerr
3571 and exits.
3572 .PP
3573 Note that a
3574 .B yyFlexLexer
3575 object contains its
3576 .I entire
3577 scanning state.
3578 Thus you can use such objects to create reentrant scanners.
3579 You can instantiate multiple instances of the same
3580 .B yyFlexLexer
3581 class, and you can also combine multiple C++ scanner classes together
3582 in the same program using the
3583 .B \-P
3584 option discussed above.
3585 .PP
3586 Finally, note that the
3587 .B %array
3588 feature is not available to C++ scanner classes; you must use
3589 .B %pointer
3590 (the default).
3591 .PP
3592 Here is an example of a simple C++ scanner:
3593 .nf
3594
3595         // An example of using the flex C++ scanner class.
3596
3597     %{
3598     int mylineno = 0;
3599     %}
3600
3601     string  \\"[^\\n"]+\\"
3602
3603     ws      [ \\t]+
3604
3605     alpha   [A-Za-z]
3606     dig     [0-9]
3607     name    ({alpha}|{dig}|\\$)({alpha}|{dig}|[_.\\-/$])*
3608     num1    [-+]?{dig}+\\.?([eE][-+]?{dig}+)?
3609     num2    [-+]?{dig}*\\.{dig}+([eE][-+]?{dig}+)?
3610     number  {num1}|{num2}
3611
3612     %%
3613
3614     {ws}    /* skip blanks and tabs */
3615
3616     "/*"    {
3617             int c;
3618
3619             while((c = yyinput()) != 0)
3620                 {
3621                 if(c == '\\n')
3622                     ++mylineno;
3623
3624                 else if(c == '*')
3625                     {
3626                     if((c = yyinput()) == '/')
3627                         break;
3628                     else
3629                         unput(c);
3630                     }
3631                 }
3632             }
3633
3634     {number}  cout << "number " << YYText() << '\\n';
3635
3636     \\n        mylineno++;
3637
3638     {name}    cout << "name " << YYText() << '\\n';
3639
3640     {string}  cout << "string " << YYText() << '\\n';
3641
3642     %%
3643
3644     int main( int /* argc */, char** /* argv */ )
3645         {
3646         FlexLexer* lexer = new yyFlexLexer;
3647         while(lexer->yylex() != 0)
3648             ;
3649         return 0;
3650         }
3651 .fi
3652 If you want to create multiple (different) lexer classes, you use the
3653 .B \-P
3654 flag (or the
3655 .B prefix=
3656 option) to rename each
3657 .B yyFlexLexer
3658 to some other
3659 .B xxFlexLexer.
3660 You then can include
3661 .B <FlexLexer.h>
3662 in your other sources once per lexer class, first renaming
3663 .B yyFlexLexer
3664 as follows:
3665 .nf
3666
3667     #undef yyFlexLexer
3668     #define yyFlexLexer xxFlexLexer
3669     #include <FlexLexer.h>
3670
3671     #undef yyFlexLexer
3672     #define yyFlexLexer zzFlexLexer
3673     #include <FlexLexer.h>
3674
3675 .fi
3676 if, for example, you used
3677 .B %option prefix="xx"
3678 for one of your scanners and
3679 .B %option prefix="zz"
3680 for the other.
3681 .PP
3682 IMPORTANT: the present form of the scanning class is
3683 .I experimental
3684 and may change considerably between major releases.
3685 .SH INCOMPATIBILITIES WITH LEX AND POSIX
3686 .I flex
3687 is a rewrite of the AT&T Unix
3688 .I lex
3689 tool (the two implementations do not share any code, though),
3690 with some extensions and incompatibilities, both of which
3691 are of concern to those who wish to write scanners acceptable
3692 to either implementation.
3693 Flex is fully compliant with the POSIX
3694 .I lex
3695 specification, except that when using
3696 .B %pointer
3697 (the default), a call to
3698 .B unput()
3699 destroys the contents of
3700 .B yytext,
3701 which is counter to the POSIX specification.
3702 .PP
3703 In this section we discuss all of the known areas of incompatibility
3704 between flex, AT&T lex, and the POSIX specification.
3705 .PP
3706 .I flex's
3707 .B \-l
3708 option turns on maximum compatibility with the original AT&T
3709 .I lex
3710 implementation, at the cost of a major loss in the generated scanner's
3711 performance.
3712 We note below which incompatibilities can be overcome
3713 using the
3714 .B \-l
3715 option.
3716 .PP
3717 .I flex
3718 is fully compatible with
3719 .I lex
3720 with the following exceptions:
3721 .IP -
3722 The undocumented
3723 .I lex
3724 scanner internal variable
3725 .B yylineno
3726 is not supported unless
3727 .B \-l
3728 or
3729 .B %option yylineno
3730 is used.
3731 .IP
3732 .B yylineno
3733 should be maintained on a per-buffer basis, rather than a per-scanner
3734 (single global variable) basis.
3735 .IP
3736 .B yylineno
3737 is not part of the POSIX specification.
3738 .IP -
3739 The
3740 .B input()
3741 routine is not redefinable, though it may be called to read characters
3742 following whatever has been matched by a rule.
3743 If
3744 .B input()
3745 encounters an end-of-file the normal
3746 .B yywrap()
3747 processing is done.
3748 A ``real'' end-of-file is returned by
3749 .B input()
3750 as
3751 .I EOF.
3752 .IP
3753 Input is instead controlled by defining the
3754 .B YY_INPUT
3755 macro.
3756 .IP
3757 The
3758 .I flex
3759 restriction that
3760 .B input()
3761 cannot be redefined is in accordance with the POSIX specification,
3762 which simply does not specify any way of controlling the
3763 scanner's input other than by making an initial assignment to
3764 .I yyin.
3765 .IP -
3766 The
3767 .B unput()
3768 routine is not redefinable.
3769 This restriction is in accordance with POSIX.
3770 .IP -
3771 .I flex
3772 scanners are not as reentrant as
3773 .I lex
3774 scanners.
3775 In particular, if you have an interactive scanner and
3776 an interrupt handler which long-jumps out of the scanner, and
3777 the scanner is subsequently called again, you may get the following
3778 message:
3779 .nf
3780
3781     fatal flex scanner internal error--end of buffer missed
3782
3783 .fi
3784 To reenter the scanner, first use
3785 .nf
3786
3787     yyrestart( yyin );
3788
3789 .fi
3790 Note that this call will throw away any buffered input; usually this
3791 isn't a problem with an interactive scanner.
3792 .IP
3793 Also note that flex C++ scanner classes
3794 .I are
3795 reentrant, so if using C++ is an option for you, you should use
3796 them instead.
3797 See "Generating C++ Scanners" above for details.
3798 .IP -
3799 .B output()
3800 is not supported.
3801 Output from the
3802 .B ECHO
3803 macro is done to the file-pointer
3804 .I yyout
3805 (default
3806 .I stdout).
3807 .IP
3808 .B output()
3809 is not part of the POSIX specification.
3810 .IP -
3811 .I lex
3812 does not support exclusive start conditions (%x), though they
3813 are in the POSIX specification.
3814 .IP -
3815 When definitions are expanded,
3816 .I flex
3817 encloses them in parentheses.
3818 With lex, the following:
3819 .nf
3820
3821     NAME    [A-Z][A-Z0-9]*
3822     %%
3823     foo{NAME}?      printf( "Found it\\n" );
3824     %%
3825
3826 .fi
3827 will not match the string "foo" because when the macro
3828 is expanded the rule is equivalent to "foo[A-Z][A-Z0-9]*?"
3829 and the precedence is such that the '?' is associated with
3830 "[A-Z0-9]*".
3831 With
3832 .I flex,
3833 the rule will be expanded to
3834 "foo([A-Z][A-Z0-9]*)?" and so the string "foo" will match.
3835 .IP
3836 Note that if the definition begins with
3837 .B ^
3838 or ends with
3839 .B $
3840 then it is
3841 .I not
3842 expanded with parentheses, to allow these operators to appear in
3843 definitions without losing their special meanings.
3844 But the
3845 .B <s>, /,
3846 and
3847 .B <<EOF>>
3848 operators cannot be used in a
3849 .I flex
3850 definition.
3851 .IP
3852 Using
3853 .B \-l
3854 results in the
3855 .I lex
3856 behavior of no parentheses around the definition.
3857 .IP
3858 The POSIX specification is that the definition be enclosed in parentheses.
3859 .IP -
3860 Some implementations of
3861 .I lex
3862 allow a rule's action to begin on a separate line, if the rule's pattern
3863 has trailing whitespace:
3864 .nf
3865
3866     %%
3867     foo|bar<space here>
3868       { foobar_action(); }
3869
3870 .fi
3871 .I flex
3872 does not support this feature.
3873 .IP -
3874 The
3875 .I lex
3876 .B %r
3877 (generate a Ratfor scanner) option is not supported.
3878 It is not part
3879 of the POSIX specification.
3880 .IP -
3881 After a call to
3882 .B unput(),
3883 .I yytext
3884 is undefined until the next token is matched, unless the scanner
3885 was built using
3886 .B %array.
3887 This is not the case with
3888 .I lex
3889 or the POSIX specification.
3890 The
3891 .B \-l
3892 option does away with this incompatibility.
3893 .IP -
3894 The precedence of the
3895 .B {}
3896 (numeric range) operator is different.
3897 .I lex
3898 interprets "abc{1,3}" as "match one, two, or
3899 three occurrences of 'abc'", whereas
3900 .I flex
3901 interprets it as "match 'ab'
3902 followed by one, two, or three occurrences of 'c'".
3903 The latter is in agreement with the POSIX specification.
3904 .IP -
3905 The precedence of the
3906 .B ^
3907 operator is different.
3908 .I lex
3909 interprets "^foo|bar" as "match either 'foo' at the beginning of a line,
3910 or 'bar' anywhere", whereas
3911 .I flex
3912 interprets it as "match either 'foo' or 'bar' if they come at the beginning
3913 of a line".
3914 The latter is in agreement with the POSIX specification.
3915 .IP -
3916 The special table-size declarations such as
3917 .B %a
3918 supported by
3919 .I lex
3920 are not required by
3921 .I flex
3922 scanners;
3923 .I flex
3924 ignores them.
3925 .IP -
3926 The name
3927 .B FLEX_SCANNER
3928 is #define'd so scanners may be written for use with either
3929 .I flex
3930 or
3931 .I lex.
3932 Scanners also include
3933 .B YY_FLEX_MAJOR_VERSION
3934 and
3935 .B YY_FLEX_MINOR_VERSION
3936 indicating which version of
3937 .I flex
3938 generated the scanner
3939 (for example, for the 2.5 release, these defines would be 2 and 5
3940 respectively).
3941 .PP
3942 The following
3943 .I flex
3944 features are not included in
3945 .I lex
3946 or the POSIX specification:
3947 .nf
3948
3949     C++ scanners
3950     %option
3951     start condition scopes
3952     start condition stacks
3953     interactive/non-interactive scanners
3954     yy_scan_string() and friends
3955     yyterminate()
3956     yy_set_interactive()
3957     yy_set_bol()
3958     YY_AT_BOL()
3959     <<EOF>>
3960     <*>
3961     YY_DECL
3962     YY_START
3963     YY_USER_ACTION
3964     YY_USER_INIT
3965     #line directives
3966     %{}'s around actions
3967     multiple actions on a line
3968
3969 .fi
3970 plus almost all of the flex flags.
3971 The last feature in the list refers to the fact that with
3972 .I flex
3973 you can put multiple actions on the same line, separated with
3974 semi-colons, while with
3975 .I lex,
3976 the following
3977 .nf
3978
3979     foo    handle_foo(); ++num_foos_seen;
3980
3981 .fi
3982 is (rather surprisingly) truncated to
3983 .nf
3984
3985     foo    handle_foo();
3986
3987 .fi
3988 .I flex
3989 does not truncate the action.
3990 Actions that are not enclosed in
3991 braces are simply terminated at the end of the line.
3992 .SH DIAGNOSTICS
3993 .I warning, rule cannot be matched
3994 indicates that the given rule
3995 cannot be matched because it follows other rules that will
3996 always match the same text as it.
3997 For example, in the following "foo" cannot be matched because it comes after
3998 an identifier "catch-all" rule:
3999 .nf
4000
4001     [a-z]+    got_identifier();
4002     foo       got_foo();
4003
4004 .fi
4005 Using
4006 .B REJECT
4007 in a scanner suppresses this warning.
4008 .PP
4009 .I warning,
4010 .B \-s
4011 .I
4012 option given but default rule can be matched
4013 means that it is possible (perhaps only in a particular start condition)
4014 that the default rule (match any single character) is the only one
4015 that will match a particular input.
4016 Since
4017 .B \-s
4018 was given, presumably this is not intended.
4019 .PP
4020 .I reject_used_but_not_detected undefined
4021 or
4022 .I yymore_used_but_not_detected undefined -
4023 These errors can occur at compile time.
4024 They indicate that the scanner uses
4025 .B REJECT
4026 or
4027 .B yymore()
4028 but that
4029 .I flex
4030 failed to notice the fact, meaning that
4031 .I flex
4032 scanned the first two sections looking for occurrences of these actions
4033 and failed to find any, but somehow you snuck some in (via a #include
4034 file, for example).
4035 Use
4036 .B %option reject
4037 or
4038 .B %option yymore
4039 to indicate to flex that you really do use these features.
4040 .PP
4041 .I flex scanner jammed -
4042 a scanner compiled with
4043 .B \-s
4044 has encountered an input string which wasn't matched by
4045 any of its rules.
4046 This error can also occur due to internal problems.
4047 .PP
4048 .I token too large, exceeds YYLMAX -
4049 your scanner uses
4050 .B %array
4051 and one of its rules matched a string longer than the
4052 .B YYLMAX
4053 constant (8K bytes by default).
4054 You can increase the value by
4055 #define'ing
4056 .B YYLMAX
4057 in the definitions section of your
4058 .I flex
4059 input.
4060 .PP
4061 .I scanner requires \-8 flag to
4062 .I use the character 'x' -
4063 Your scanner specification includes recognizing the 8-bit character
4064 .I 'x'
4065 and you did not specify the \-8 flag, and your scanner defaulted to 7-bit
4066 because you used the
4067 .B \-Cf
4068 or
4069 .B \-CF
4070 table compression options.
4071 See the discussion of the
4072 .B \-7
4073 flag for details.
4074 .PP
4075 .I flex scanner push-back overflow -
4076 you used
4077 .B unput()
4078 to push back so much text that the scanner's buffer could not hold
4079 both the pushed-back text and the current token in
4080 .B yytext.
4081 Ideally the scanner should dynamically resize the buffer in this case, but at
4082 present it does not.
4083 .PP
4084 .I
4085 input buffer overflow, can't enlarge buffer because scanner uses REJECT -
4086 the scanner was working on matching an extremely large token and needed
4087 to expand the input buffer.
4088 This doesn't work with scanners that use
4089 .B
4090 REJECT.
4091 .PP
4092 .I
4093 fatal flex scanner internal error--end of buffer missed -
4094 This can occur in a scanner which is reentered after a long-jump
4095 has jumped out (or over) the scanner's activation frame.
4096 Before reentering the scanner, use:
4097 .nf
4098
4099     yyrestart( yyin );
4100
4101 .fi
4102 or, as noted above, switch to using the C++ scanner class.
4103 .PP
4104 .I too many start conditions in <> construct! -
4105 you listed more start conditions in a <> construct than exist (so
4106 you must have listed at least one of them twice).
4107 .SH FILES
4108 .TP
4109 .B \-ll
4110 library with which scanners must be linked.
4111 .TP
4112 .I lex.yy.c
4113 generated scanner (called
4114 .I lexyy.c
4115 on some systems).
4116 .TP
4117 .I lex.yy.cc
4118 generated C++ scanner class, when using
4119 .B -+.
4120 .TP
4121 .I <FlexLexer.h>
4122 header file defining the C++ scanner base class,
4123 .B FlexLexer,
4124 and its derived class,
4125 .B yyFlexLexer.
4126 .TP
4127 .I flex.skl
4128 skeleton scanner.
4129 This file is only used when building flex, not when flex executes.
4130 .TP
4131 .I lex.backup
4132 backing-up information for
4133 .B \-b
4134 flag (called
4135 .I lex.bck
4136 on some systems).
4137 .SH DEFICIENCIES / BUGS
4138 Some trailing context
4139 patterns cannot be properly matched and generate
4140 warning messages ("dangerous trailing context").
4141 These are patterns where the ending of the
4142 first part of the rule matches the beginning of the second
4143 part, such as "zx*/xy*", where the 'x*' matches the 'x' at
4144 the beginning of the trailing context.
4145 (Note that the POSIX draft
4146 states that the text matched by such patterns is undefined.)
4147 .PP
4148 For some trailing context rules, parts which are actually fixed-length are
4149 not recognized as such, leading to the above mentioned performance loss.
4150 In particular, parts using '|' or {n} (such as "foo{3}") are always
4151 considered variable-length.
4152 .PP
4153 Combining trailing context with the special '|' action can result in
4154 .I fixed
4155 trailing context being turned into the more expensive
4156 .I variable
4157 trailing context.
4158 For example, in the following:
4159 .nf
4160
4161     %%
4162     abc      |
4163     xyz/def
4164
4165 .fi
4166 .PP
4167 Use of
4168 .B unput()
4169 invalidates yytext and yyleng, unless the
4170 .B %array
4171 directive
4172 or the
4173 .B \-l
4174 option has been used.
4175 .PP
4176 Pattern-matching of NUL's is substantially slower than matching other
4177 characters.
4178 .PP
4179 Dynamic resizing of the input buffer is slow, as it entails rescanning
4180 all the text matched so far by the current (generally huge) token.
4181 .PP
4182 Due to both buffering of input and read-ahead, you cannot intermix
4183 calls to <stdio.h> routines, such as, for example,
4184 .B getchar(),
4185 with
4186 .I flex
4187 rules and expect it to work.
4188 Call
4189 .B input()
4190 instead.
4191 .PP
4192 The total table entries listed by the
4193 .B \-v
4194 flag excludes the number of table entries needed to determine
4195 what rule has been matched.
4196 The number of entries is equal
4197 to the number of DFA states if the scanner does not use
4198 .B REJECT,
4199 and somewhat greater than the number of states if it does.
4200 .PP
4201 .B REJECT
4202 cannot be used with the
4203 .B \-f
4204 or
4205 .B \-F
4206 options.
4207 .PP
4208 The
4209 .I flex
4210 internal algorithms need documentation.
4211 .SH SEE ALSO
4212 lex(1), yacc(1), sed(1), awk(1).
4213 .PP
4214 John Levine, Tony Mason, and Doug Brown,
4215 .I Lex & Yacc,
4216 O'Reilly and Associates.
4217 Be sure to get the 2nd edition.
4218 .PP
4219 M. E. Lesk and E. Schmidt,
4220 .I LEX \- Lexical Analyzer Generator
4221 .PP
4222 Alfred Aho, Ravi Sethi and Jeffrey Ullman,
4223 .I Compilers: Principles, Techniques and Tools,
4224 Addison-Wesley (1986).
4225 Describes the pattern-matching techniques used by
4226 .I flex
4227 (deterministic finite automata).
4228 .SH AUTHOR
4229 Vern Paxson, with the help of many ideas and much inspiration from
4230 Van Jacobson.
4231 Original version by Jef Poskanzer.
4232 The fast table
4233 representation is a partial implementation of a design done by Van
4234 Jacobson.
4235 The implementation was done by Kevin Gong and Vern Paxson.
4236 .PP
4237 Thanks to the many
4238 .I flex
4239 beta-testers, feedbackers, and contributors, especially Francois Pinard,
4240 Casey Leedom,
4241 Robert Abramovitz,
4242 Stan Adermann, Terry Allen, David Barker-Plummer, John Basrai,
4243 Neal Becker, Nelson H.F. Beebe, benson@odi.com,
4244 Karl Berry, Peter A. Bigot, Simon Blanchard,
4245 Keith Bostic, Frederic Brehm, Ian Brockbank, Kin Cho, Nick Christopher,
4246 Brian Clapper, J.T. Conklin,
4247 Jason Coughlin, Bill Cox, Nick Cropper, Dave Curtis, Scott David
4248 Daniels, Chris G. Demetriou, Theo de Raadt,
4249 Mike Donahue, Chuck Doucette, Tom Epperly, Leo Eskin,
4250 Chris Faylor, Chris Flatters, Jon Forrest, Jeffrey Friedl,
4251 Joe Gayda, Kaveh R. Ghazi, Wolfgang Glunz,
4252 Eric Goldman, Christopher M. Gould, Ulrich Grepel, Peer Griebel,
4253 Jan Hajic, Charles Hemphill, NORO Hideo,
4254 Jarkko Hietaniemi, Scott Hofmann,
4255 Jeff Honig, Dana Hudes, Eric Hughes, John Interrante,
4256 Ceriel Jacobs, Michal Jaegermann, Sakari Jalovaara, Jeffrey R. Jones,
4257 Henry Juengst, Klaus Kaempf, Jonathan I. Kamens, Terrence O Kane,
4258 Amir Katz, ken@ken.hilco.com, Kevin B. Kenny,
4259 Steve Kirsch, Winfried Koenig, Marq Kole, Ronald Lamprecht,
4260 Greg Lee, Rohan Lenard, Craig Leres, John Levine, Steve Liddle,
4261 David Loffredo, Mike Long,
4262 Mohamed el Lozy, Brian Madsen, Malte, Joe Marshall,
4263 Bengt Martensson, Chris Metcalf,
4264 Luke Mewburn, Jim Meyering, R. Alexander Milowski, Erik Naggum,
4265 G.T. Nicol, Landon Noll, James Nordby, Marc Nozell,
4266 Richard Ohnemus, Karsten Pahnke,
4267 Sven Panne, Roland Pesch, Walter Pelissero, Gaumond
4268 Pierre, Esmond Pitt, Jef Poskanzer, Joe Rahmeh, Jarmo Raiha,
4269 Frederic Raimbault, Pat Rankin, Rick Richardson,
4270 Kevin Rodgers, Kai Uwe Rommel, Jim Roskind, Alberto Santini,
4271 Andreas Scherer, Darrell Schiebel, Raf Schietekat,
4272 Doug Schmidt, Philippe Schnoebelen, Andreas Schwab,
4273 Larry Schwimmer, Alex Siegel, Eckehard Stolz, Jan-Erik Strvmquist,
4274 Mike Stump, Paul Stuart, Dave Tallman, Ian Lance Taylor,
4275 Chris Thewalt, Richard M. Timoney, Jodi Tsai,
4276 Paul Tuinenga, Gary Weik, Frank Whaley, Gerhard Wilhelms, Kent Williams, Ken
4277 Yap, Ron Zellar, Nathan Zelle, David Zuhn,
4278 and those whose names have slipped my marginal
4279 mail-archiving skills but whose contributions are appreciated all the
4280 same.
4281 .PP
4282 Thanks to Keith Bostic, Jon Forrest, Noah Friedman,
4283 John Gilmore, Craig Leres, John Levine, Bob Mulcahy, G.T.
4284 Nicol, Francois Pinard, Rich Salz, and Richard Stallman for help with various
4285 distribution headaches.
4286 .PP
4287 Thanks to Esmond Pitt and Earle Horton for 8-bit character support; to
4288 Benson Margulies and Fred Burke for C++ support; to Kent Williams and Tom
4289 Epperly for C++ class support; to Ove Ewerlid for support of NUL's; and to
4290 Eric Hughes for support of multiple buffers.
4291 .PP
4292 This work was primarily done when I was with the Real Time Systems Group
4293 at the Lawrence Berkeley Laboratory in Berkeley, CA.
4294 Many thanks to all there for the support I received.
4295 .PP
4296 Send comments to vern@ee.lbl.gov.