home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / flex-2.4.6 / flexdoc.1 < prev    next >
Encoding:
Text File  |  1994-07-23  |  78.1 KB  |  3,046 lines  |  [TEXT/KAHL]

  1. .TH FLEXDOC 1 "November 1993" "Version 2.4"
  2. .SH NAME
  3. flexdoc \- documentation for flex, fast lexical analyzer generator
  4. .SH SYNOPSIS
  5. .B flex
  6. .B [\-bcdfhilnpstvwBFILTV78+ \-C[aefFmr] \-Pprefix \-Sskeleton]
  7. .I [filename ...]
  8. .SH DESCRIPTION
  9. .I flex
  10. is a tool for generating
  11. .I scanners:
  12. programs which recognized lexical patterns in text.
  13. .I flex
  14. reads
  15. the given input files, or its standard input if no file names are given,
  16. for a description of a scanner to generate.  The description is in
  17. the form of pairs
  18. of regular expressions and C code, called
  19. .I rules.  flex
  20. generates as output a C source file,
  21. .B lex.yy.c,
  22. which defines a routine
  23. .B yylex().
  24. This file is compiled and linked with the
  25. .B \-lfl
  26. library to produce an executable.  When the executable is run,
  27. it analyzes its input for occurrences
  28. of the regular expressions.  Whenever it finds one, it executes
  29. the corresponding C code.
  30. .SH SOME SIMPLE EXAMPLES
  31. .PP
  32. First some simple examples to get the flavor of how one uses
  33. .I flex.
  34. The following
  35. .I flex
  36. input specifies a scanner which whenever it encounters the string
  37. "username" will replace it with the user's login name:
  38. .nf
  39.  
  40.     %%
  41.     username    printf( "%s", getlogin() );
  42.  
  43. .fi
  44. By default, any text not matched by a
  45. .I flex
  46. scanner
  47. is copied to the output, so the net effect of this scanner is
  48. to copy its input file to its output with each occurrence
  49. of "username" expanded.
  50. In this input, there is just one rule.  "username" is the
  51. .I pattern
  52. and the "printf" is the
  53. .I action.
  54. The "%%" marks the beginning of the rules.
  55. .PP
  56. Here's another simple example:
  57. .nf
  58.  
  59.             int num_lines = 0, num_chars = 0;
  60.  
  61.     %%
  62.     \\n      ++num_lines; ++num_chars;
  63.     .       ++num_chars;
  64.  
  65.     %%
  66.     main()
  67.             {
  68.             yylex();
  69.             printf( "# of lines = %d, # of chars = %d\\n",
  70.                     num_lines, num_chars );
  71.             }
  72.  
  73. .fi
  74. This scanner counts the number of characters and the number
  75. of lines in its input (it produces no output other than the
  76. final report on the counts).  The first line
  77. declares two globals, "num_lines" and "num_chars", which are accessible
  78. both inside
  79. .B yylex()
  80. and in the
  81. .B main()
  82. routine declared after the second "%%".  There are two rules, one
  83. which matches a newline ("\\n") and increments both the line count and
  84. the character count, and one which matches any character other than
  85. a newline (indicated by the "." regular expression).
  86. .PP
  87. A somewhat more complicated example:
  88. .nf
  89.  
  90.     /* scanner for a toy Pascal-like language */
  91.  
  92.     %{
  93.     /* need this for the call to atof() below */
  94.     #include <math.h>
  95.     %}
  96.  
  97.     DIGIT    [0-9]
  98.     ID       [a-z][a-z0-9]*
  99.  
  100.     %%
  101.  
  102.     {DIGIT}+    {
  103.                 printf( "An integer: %s (%d)\\n", yytext,
  104.                         atoi( yytext ) );
  105.                 }
  106.  
  107.     {DIGIT}+"."{DIGIT}*        {
  108.                 printf( "A float: %s (%g)\\n", yytext,
  109.                         atof( yytext ) );
  110.                 }
  111.  
  112.     if|then|begin|end|procedure|function        {
  113.                 printf( "A keyword: %s\\n", yytext );
  114.                 }
  115.  
  116.     {ID}        printf( "An identifier: %s\\n", yytext );
  117.  
  118.     "+"|"-"|"*"|"/"   printf( "An operator: %s\\n", yytext );
  119.  
  120.     "{"[^}\\n]*"}"     /* eat up one-line comments */
  121.  
  122.     [ \\t\\n]+          /* eat up whitespace */
  123.  
  124.     .           printf( "Unrecognized character: %s\\n", yytext );
  125.  
  126.     %%
  127.  
  128.     main( argc, argv )
  129.     int argc;
  130.     char **argv;
  131.         {
  132.         ++argv, --argc;  /* skip over program name */
  133.         if ( argc > 0 )
  134.                 yyin = fopen( argv[0], "r" );
  135.         else
  136.                 yyin = stdin;
  137.         
  138.         yylex();
  139.         }
  140.  
  141. .fi
  142. This is the beginnings of a simple scanner for a language like
  143. Pascal.  It identifies different types of
  144. .I tokens
  145. and reports on what it has seen.
  146. .PP
  147. The details of this example will be explained in the following
  148. sections.
  149. .SH FORMAT OF THE INPUT FILE
  150. The
  151. .I flex
  152. input file consists of three sections, separated by a line with just
  153. .B %%
  154. in it:
  155. .nf
  156.  
  157.     definitions
  158.     %%
  159.     rules
  160.     %%
  161.     user code
  162.  
  163. .fi
  164. The
  165. .I definitions
  166. section contains declarations of simple
  167. .I name
  168. definitions to simplify the scanner specification, and declarations of
  169. .I start conditions,
  170. which are explained in a later section.
  171. .PP
  172. Name definitions have the form:
  173. .nf
  174.  
  175.     name definition
  176.  
  177. .fi
  178. The "name" is a word beginning with a letter or an underscore ('_')
  179. followed by zero or more letters, digits, '_', or '-' (dash).
  180. The definition is taken to begin at the first non-white-space character
  181. following the name and continuing to the end of the line.
  182. The definition can subsequently be referred to using "{name}", which
  183. will expand to "(definition)".  For example,
  184. .nf
  185.  
  186.     DIGIT    [0-9]
  187.     ID       [a-z][a-z0-9]*
  188.  
  189. .fi
  190. defines "DIGIT" to be a regular expression which matches a
  191. single digit, and
  192. "ID" to be a regular expression which matches a letter
  193. followed by zero-or-more letters-or-digits.
  194. A subsequent reference to
  195. .nf
  196.  
  197.     {DIGIT}+"."{DIGIT}*
  198.  
  199. .fi
  200. is identical to
  201. .nf
  202.  
  203.     ([0-9])+"."([0-9])*
  204.  
  205. .fi
  206. and matches one-or-more digits followed by a '.' followed
  207. by zero-or-more digits.
  208. .PP
  209. The
  210. .I rules
  211. section of the
  212. .I flex
  213. input contains a series of rules of the form:
  214. .nf
  215.  
  216.     pattern   action
  217.  
  218. .fi
  219. where the pattern must be unindented and the action must begin
  220. on the same line.
  221. .PP
  222. See below for a further description of patterns and actions.
  223. .PP
  224. Finally, the user code section is simply copied to
  225. .B lex.yy.c
  226. verbatim.
  227. It is used for companion routines which call or are called
  228. by the scanner.  The presence of this section is optional;
  229. if it is missing, the second
  230. .B %%
  231. in the input file may be skipped, too.
  232. .PP
  233. In the definitions and rules sections, any
  234. .I indented
  235. text or text enclosed in
  236. .B %{
  237. and
  238. .B %}
  239. is copied verbatim to the output (with the %{}'s removed).
  240. The %{}'s must appear unindented on lines by themselves.
  241. .PP
  242. In the rules section,
  243. any indented or %{} text appearing before the
  244. first rule may be used to declare variables
  245. which are local to the scanning routine and (after the declarations)
  246. code which is to be executed whenever the scanning routine is entered.
  247. Other indented or %{} text in the rule section is still copied to the output,
  248. but its meaning is not well-defined and it may well cause compile-time
  249. errors (this feature is present for
  250. .I POSIX
  251. compliance; see below for other such features).
  252. .PP
  253. In the definitions section (but not in the rules section),
  254. an unindented comment (i.e., a line
  255. beginning with "/*") is also copied verbatim to the output up
  256. to the next "*/".
  257. .SH PATTERNS
  258. The patterns in the input are written using an extended set of regular
  259. expressions.  These are:
  260. .nf
  261.  
  262.     x          match the character 'x'
  263.     .          any character except newline
  264.     [xyz]      a "character class"; in this case, the pattern
  265.                  matches either an 'x', a 'y', or a 'z'
  266.     [abj-oZ]   a "character class" with a range in it; matches
  267.                  an 'a', a 'b', any letter from 'j' through 'o',
  268.                  or a 'Z'
  269.     [^A-Z]     a "negated character class", i.e., any character
  270.                  but those in the class.  In this case, any
  271.                  character EXCEPT an uppercase letter.
  272.     [^A-Z\\n]   any character EXCEPT an uppercase letter or
  273.                  a newline
  274.     r*         zero or more r's, where r is any regular expression
  275.     r+         one or more r's
  276.     r?         zero or one r's (that is, "an optional r")
  277.     r{2,5}     anywhere from two to five r's
  278.     r{2,}      two or more r's
  279.     r{4}       exactly 4 r's
  280.     {name}     the expansion of the "name" definition
  281.                (see above)
  282.     "[xyz]\\"foo"
  283.                the literal string: [xyz]"foo
  284.     \\X         if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
  285.                  then the ANSI-C interpretation of \\x.
  286.                  Otherwise, a literal 'X' (used to escape
  287.                  operators such as '*')
  288.     \\123       the character with octal value 123
  289.     \\x2a       the character with hexadecimal value 2a
  290.     (r)        match an r; parentheses are used to override
  291.                  precedence (see below)
  292.  
  293.  
  294.     rs         the regular expression r followed by the
  295.                  regular expression s; called "concatenation"
  296.  
  297.  
  298.     r|s        either an r or an s
  299.  
  300.  
  301.     r/s        an r but only if it is followed by an s.  The
  302.                  s is not part of the matched text.  This type
  303.                  of pattern is called as "trailing context".
  304.     ^r         an r, but only at the beginning of a line
  305.     r$         an r, but only at the end of a line.  Equivalent
  306.                  to "r/\\n".
  307.  
  308.  
  309.     <s>r       an r, but only in start condition s (see
  310.                below for discussion of start conditions)
  311.     <s1,s2,s3>r
  312.                same, but in any of start conditions s1,
  313.                s2, or s3
  314.     <*>r       an r in any start condition, even an exclusive one.
  315.  
  316.  
  317.     <<EOF>>    an end-of-file
  318.     <s1,s2><<EOF>>
  319.                an end-of-file when in start condition s1 or s2
  320.  
  321. .fi
  322. Note that inside of a character class, all regular expression operators
  323. lose their special meaning except escape ('\\') and the character class
  324. operators, '-', ']', and, at the beginning of the class, '^'.
  325. .PP
  326. The regular expressions listed above are grouped according to
  327. precedence, from highest precedence at the top to lowest at the bottom.
  328. Those grouped together have equal precedence.  For example,
  329. .nf
  330.  
  331.     foo|bar*
  332.  
  333. .fi
  334. is the same as
  335. .nf
  336.  
  337.     (foo)|(ba(r*))
  338.  
  339. .fi
  340. since the '*' operator has higher precedence than concatenation,
  341. and concatenation higher than alternation ('|').  This pattern
  342. therefore matches
  343. .I either
  344. the string "foo"
  345. .I or
  346. the string "ba" followed by zero-or-more r's.
  347. To match "foo" or zero-or-more "bar"'s, use:
  348. .nf
  349.  
  350.     foo|(bar)*
  351.  
  352. .fi
  353. and to match zero-or-more "foo"'s-or-"bar"'s:
  354. .nf
  355.  
  356.     (foo|bar)*
  357.  
  358. .fi
  359. .PP
  360. Some notes on patterns:
  361. .IP -
  362. A negated character class such as the example "[^A-Z]"
  363. above
  364. .I will match a newline
  365. unless "\\n" (or an equivalent escape sequence) is one of the
  366. characters explicitly present in the negated character class
  367. (e.g., "[^A-Z\\n]").  This is unlike how many other regular
  368. expression tools treat negated character classes, but unfortunately
  369. the inconsistency is historically entrenched.
  370. Matching newlines means that a pattern like [^"]* can match the entire
  371. input unless there's another quote in the input.
  372. .IP -
  373. A rule can have at most one instance of trailing context (the '/' operator
  374. or the '$' operator).  The start condition, '^', and "<<EOF>>" patterns
  375. can only occur at the beginning of a pattern, and, as well as with '/' and '$',
  376. cannot be grouped inside parentheses.  A '^' which does not occur at
  377. the beginning of a rule or a '$' which does not occur at the end of
  378. a rule loses its special properties and is treated as a normal character.
  379. .IP
  380. The following are illegal:
  381. .nf
  382.  
  383.     foo/bar$
  384.     <sc1>foo<sc2>bar
  385.  
  386. .fi
  387. Note that the first of these, can be written "foo/bar\\n".
  388. .IP
  389. The following will result in '$' or '^' being treated as a normal character:
  390. .nf
  391.  
  392.     foo|(bar$)
  393.     foo|^bar
  394.  
  395. .fi
  396. If what's wanted is a "foo" or a bar-followed-by-a-newline, the following
  397. could be used (the special '|' action is explained below):
  398. .nf
  399.  
  400.     foo      |
  401.     bar$     /* action goes here */
  402.  
  403. .fi
  404. A similar trick will work for matching a foo or a
  405. bar-at-the-beginning-of-a-line.
  406. .SH HOW THE INPUT IS MATCHED
  407. When the generated scanner is run, it analyzes its input looking
  408. for strings which match any of its patterns.  If it finds more than
  409. one match, it takes the one matching the most text (for trailing
  410. context rules, this includes the length of the trailing part, even
  411. though it will then be returned to the input).  If it finds two
  412. or more matches of the same length, the
  413. rule listed first in the
  414. .I flex
  415. input file is chosen.
  416. .PP
  417. Once the match is determined, the text corresponding to the match
  418. (called the
  419. .I token)
  420. is made available in the global character pointer
  421. .B yytext,
  422. and its length in the global integer
  423. .B yyleng.
  424. The
  425. .I action
  426. corresponding to the matched pattern is then executed (a more
  427. detailed description of actions follows), and then the remaining
  428. input is scanned for another match.
  429. .PP
  430. If no match is found, then the
  431. .I default rule
  432. is executed: the next character in the input is considered matched and
  433. copied to the standard output.  Thus, the simplest legal
  434. .I flex
  435. input is:
  436. .nf
  437.  
  438.     %%
  439.  
  440. .fi
  441. which generates a scanner that simply copies its input (one character
  442. at a time) to its output.
  443. .PP
  444. Note that
  445. .B yytext
  446. can be defined in two different ways: either as a character
  447. .I pointer
  448. or as a character
  449. .I array.
  450. You can control which definition
  451. .I flex
  452. uses by including one of the special directives
  453. .B %pointer
  454. or
  455. .B %array
  456. in the first (definitions) section of your flex input.  The default is
  457. .B %pointer,
  458. unless you use the
  459. .B -l
  460. lex compatibility option, in which case
  461. .B yytext
  462. will be an array.
  463. The advantage of using
  464. .B %pointer
  465. is substantially faster scanning and no buffer overflow when matching
  466. very large tokens (unless you run out of dynamic memory).  The disadvantage
  467. is that you are restricted in how your actions can modify
  468. .B yytext
  469. (see the next section), and calls to the
  470. .B input()
  471. and
  472. .B unput()
  473. functions destroy the present contents of
  474. .B yytext,
  475. which can be a considerable porting headache when moving between different
  476. .I lex
  477. versions.
  478. .PP
  479. The advantage of
  480. .B %array
  481. is that you can then modify
  482. .B yytext
  483. to your heart's content, and calls to
  484. .B input()
  485. and
  486. .B unput()
  487. do not destroy
  488. .B yytext
  489. (see below).  Furthermore, existing
  490. .I lex
  491. programs sometimes access
  492. .B yytext
  493. externally using declarations of the form:
  494. .nf
  495.     extern char yytext[];
  496. .fi
  497. This definition is erroneous when used with
  498. .B %pointer,
  499. but correct for
  500. .B %array.
  501. .PP
  502. .B %array
  503. defines
  504. .B yytext
  505. to be an array of
  506. .B YYLMAX
  507. characters, which defaults to a fairly large value.  You can change
  508. the size by simply #define'ing
  509. .B YYLMAX
  510. to a different value in the first section of your
  511. .I flex
  512. input.  As mentioned above, with
  513. .B %pointer
  514. yytext grows dynamically to accomodate large tokens.  While this means your
  515. .B %pointer
  516. scanner can accomodate very large tokens (such as matching entire blocks
  517. of comments), bear in mind that each time the scanner must resize
  518. .B yytext
  519. it also must rescan the entire token from the beginning, so matching such
  520. tokens can prove slow.
  521. .B yytext
  522. presently does
  523. .I not
  524. dynamically grow if a call to
  525. .B unput()
  526. results in too much text being pushed back; instead, a run-time error results.
  527. .PP
  528. Also note that you cannot use
  529. .B %array
  530. with C++ scanner classes
  531. (the
  532. .B \-+
  533. option; see below).
  534. .SH ACTIONS
  535. Each pattern in a rule has a corresponding action, which can be any
  536. arbitrary C statement.  The pattern ends at the first non-escaped
  537. whitespace character; the remainder of the line is its action.  If the
  538. action is empty, then when the pattern is matched the input token
  539. is simply discarded.  For example, here is the specification for a program
  540. which deletes all occurrences of "zap me" from its input:
  541. .nf
  542.  
  543.     %%
  544.     "zap me"
  545.  
  546. .fi
  547. (It will copy all other characters in the input to the output since
  548. they will be matched by the default rule.)
  549. .PP
  550. Here is a program which compresses multiple blanks and tabs down to
  551. a single blank, and throws away whitespace found at the end of a line:
  552. .nf
  553.  
  554.     %%
  555.     [ \\t]+        putchar( ' ' );
  556.     [ \\t]+$       /* ignore this token */
  557.  
  558. .fi
  559. .PP
  560. If the action contains a '{', then the action spans till the balancing '}'
  561. is found, and the action may cross multiple lines.
  562. .I flex 
  563. knows about C strings and comments and won't be fooled by braces found
  564. within them, but also allows actions to begin with
  565. .B %{
  566. and will consider the action to be all the text up to the next
  567. .B %}
  568. (regardless of ordinary braces inside the action).
  569. .PP
  570. An action consisting solely of a vertical bar ('|') means "same as
  571. the action for the next rule."  See below for an illustration.
  572. .PP
  573. Actions can include arbitrary C code, including
  574. .B return
  575. statements to return a value to whatever routine called
  576. .B yylex().
  577. Each time
  578. .B yylex()
  579. is called it continues processing tokens from where it last left
  580. off until it either reaches
  581. the end of the file or executes a return.
  582. .PP
  583. Actions are free to modify
  584. .B yytext
  585. except for lengthening it (adding
  586. characters to its end--these will overwrite later characters in the
  587. input stream).  Modifying the final character of yytext may alter
  588. whether when scanning resumes rules anchored with '^' are active.
  589. Specifically, changing the final character of yytext to a newline will
  590. activate such rules on the next scan, and changing it to anything else
  591. will deactivate the rules.  Users should not rely on this behavior being
  592. present in future releases.  Finally, note that none of this paragraph
  593. applies when using
  594. .B %array
  595. (see above).
  596. .PP
  597. Actions are free to modify
  598. .B yyleng
  599. except they should not do so if the action also includes use of
  600. .B yymore()
  601. (see below).
  602. .PP
  603. There are a number of special directives which can be included within
  604. an action:
  605. .IP -
  606. .B ECHO
  607. copies yytext to the scanner's output.
  608. .IP -
  609. .B BEGIN
  610. followed by the name of a start condition places the scanner in the
  611. corresponding start condition (see below).
  612. .IP -
  613. .B REJECT
  614. directs the scanner to proceed on to the "second best" rule which matched the
  615. input (or a prefix of the input).  The rule is chosen as described
  616. above in "How the Input is Matched", and
  617. .B yytext
  618. and
  619. .B yyleng
  620. set up appropriately.
  621. It may either be one which matched as much text
  622. as the originally chosen rule but came later in the
  623. .I flex
  624. input file, or one which matched less text.
  625. For example, the following will both count the
  626. words in the input and call the routine special() whenever "frob" is seen:
  627. .nf
  628.  
  629.             int word_count = 0;
  630.     %%
  631.  
  632.     frob        special(); REJECT;
  633.     [^ \\t\\n]+   ++word_count;
  634.  
  635. .fi
  636. Without the
  637. .B REJECT,
  638. any "frob"'s in the input would not be counted as words, since the
  639. scanner normally executes only one action per token.
  640. Multiple
  641. .B REJECT's
  642. are allowed, each one finding the next best choice to the currently
  643. active rule.  For example, when the following scanner scans the token
  644. "abcd", it will write "abcdabcaba" to the output:
  645. .nf
  646.  
  647.     %%
  648.     a        |
  649.     ab       |
  650.     abc      |
  651.     abcd     ECHO; REJECT;
  652.     .|\\n     /* eat up any unmatched character */
  653.  
  654. .fi
  655. (The first three rules share the fourth's action since they use
  656. the special '|' action.)
  657. .B REJECT
  658. is a particularly expensive feature in terms scanner performance;
  659. if it is used in
  660. .I any
  661. of the scanner's actions it will slow down
  662. .I all
  663. of the scanner's matching.  Furthermore,
  664. .B REJECT
  665. cannot be used with the
  666. .I -Cf
  667. or
  668. .I -CF
  669. options (see below).
  670. .IP
  671. Note also that unlike the other special actions,
  672. .B REJECT
  673. is a
  674. .I branch;
  675. code immediately following it in the action will
  676. .I not
  677. be executed.
  678. .IP -
  679. .B yymore()
  680. tells the scanner that the next time it matches a rule, the corresponding
  681. token should be
  682. .I appended
  683. onto the current value of
  684. .B yytext
  685. rather than replacing it.  For example, given the input "mega-kludge"
  686. the following will write "mega-mega-kludge" to the output:
  687. .nf
  688.  
  689.     %%
  690.     mega-    ECHO; yymore();
  691.     kludge   ECHO;
  692.  
  693. .fi
  694. First "mega-" is matched and echoed to the output.  Then "kludge"
  695. is matched, but the previous "mega-" is still hanging around at the
  696. beginning of
  697. .B yytext
  698. so the
  699. .B ECHO
  700. for the "kludge" rule will actually write "mega-kludge".
  701. The presence of
  702. .B yymore()
  703. in the scanner's action entails a minor performance penalty in the
  704. scanner's matching speed.
  705. .IP -
  706. .B yyless(n)
  707. returns all but the first
  708. .I n
  709. characters of the current token back to the input stream, where they
  710. will be rescanned when the scanner looks for the next match.
  711. .B yytext
  712. and
  713. .B yyleng
  714. are adjusted appropriately (e.g.,
  715. .B yyleng
  716. will now be equal to
  717. .I n
  718. ).  For example, on the input "foobar" the following will write out
  719. "foobarbar":
  720. .nf
  721.  
  722.     %%
  723.     foobar    ECHO; yyless(3);
  724.     [a-z]+    ECHO;
  725.  
  726. .fi
  727. An argument of 0 to
  728. .B yyless
  729. will cause the entire current input string to be scanned again.  Unless you've
  730. changed how the scanner will subsequently process its input (using
  731. .B BEGIN,
  732. for example), this will result in an endless loop.
  733. .PP
  734. Note that
  735. .B yyless
  736. is a macro and can only be used in the flex input file, not from
  737. other source files.
  738. .IP -
  739. .B unput(c)
  740. puts the character
  741. .I c
  742. back onto the input stream.  It will be the next character scanned.
  743. The following action will take the current token and cause it
  744. to be rescanned enclosed in parentheses.
  745. .nf
  746.  
  747.     {
  748.     int i;
  749.     unput( ')' );
  750.     for ( i = yyleng - 1; i >= 0; --i )
  751.         unput( yytext[i] );
  752.     unput( '(' );
  753.     }
  754.  
  755. .fi
  756. Note that since each
  757. .B unput()
  758. puts the given character back at the
  759. .I beginning
  760. of the input stream, pushing back strings must be done back-to-front.
  761. Also note that you cannot put back
  762. .B EOF
  763. to attempt to mark the input stream with an end-of-file.
  764. .IP -
  765. .B input()
  766. reads the next character from the input stream.  For example,
  767. the following is one way to eat up C comments:
  768. .nf
  769.  
  770.     %%
  771.     "/*"        {
  772.                 register int c;
  773.  
  774.                 for ( ; ; )
  775.                     {
  776.                     while ( (c = input()) != '*' &&
  777.                             c != EOF )
  778.                         ;    /* eat up text of comment */
  779.  
  780.                     if ( c == '*' )
  781.                         {
  782.                         while ( (c = input()) == '*' )
  783.                             ;
  784.                         if ( c == '/' )
  785.                             break;    /* found the end */
  786.                         }
  787.  
  788.                     if ( c == EOF )
  789.                         {
  790.                         error( "EOF in comment" );
  791.                         break;
  792.                         }
  793.                     }
  794.                 }
  795.  
  796. .fi
  797. (Note that if the scanner is compiled using
  798. .B C++,
  799. then
  800. .B input()
  801. is instead referred to as
  802. .B yyinput(),
  803. in order to avoid a name clash with the
  804. .B C++
  805. stream by the name of
  806. .I input.)
  807. .IP -
  808. .B yyterminate()
  809. can be used in lieu of a return statement in an action.  It terminates
  810. the scanner and returns a 0 to the scanner's caller, indicating "all done".
  811. By default,
  812. .B yyterminate()
  813. is also called when an end-of-file is encountered.  It is a macro and
  814. may be redefined.
  815. .SH THE GENERATED SCANNER
  816. The output of
  817. .I flex
  818. is the file
  819. .B lex.yy.c,
  820. which contains the scanning routine
  821. .B yylex(),
  822. a number of tables used by it for matching tokens, and a number
  823. of auxiliary routines and macros.  By default,
  824. .B yylex()
  825. is declared as follows:
  826. .nf
  827.  
  828.     int yylex()
  829.         {
  830.         ... various definitions and the actions in here ...
  831.         }
  832.  
  833. .fi
  834. (If your environment supports function prototypes, then it will
  835. be "int yylex( void )".)  This definition may be changed by defining
  836. the "YY_DECL" macro.  For example, you could use:
  837. .nf
  838.  
  839.     #define YY_DECL float lexscan( a, b ) float a, b;
  840.  
  841. .fi
  842. to give the scanning routine the name
  843. .I lexscan,
  844. returning a float, and taking two floats as arguments.  Note that
  845. if you give arguments to the scanning routine using a
  846. K&R-style/non-prototyped function declaration, you must terminate
  847. the definition with a semi-colon (;).
  848. .PP
  849. Whenever
  850. .B yylex()
  851. is called, it scans tokens from the global input file
  852. .I yyin
  853. (which defaults to stdin).  It continues until it either reaches
  854. an end-of-file (at which point it returns the value 0) or
  855. one of its actions executes a
  856. .I return
  857. statement.
  858. .PP
  859. If the scanner reaches an end-of-file, subsequent calls are undefined
  860. unless either
  861. .I yyin
  862. is pointed at a new input file (in which case scanning continues from
  863. that file), or
  864. .B yyrestart()
  865. is called.
  866. .B yyrestart()
  867. takes one argument, a
  868. .B FILE *
  869. pointer, and initializes
  870. .I yyin
  871. for scanning from that file.  Essentially there is no difference between
  872. just assigning
  873. .I yyin
  874. to a new input file or using
  875. .B yyrestart()
  876. to do so; the latter is available for compatibility with previous versions
  877. of
  878. .I flex,
  879. and because it can be used to switch input files in the middle of scanning.
  880. It can also be used to throw away the current input buffer, by calling
  881. it with an argument of
  882. .I yyin.
  883. .PP
  884. If
  885. .B yylex()
  886. stops scanning due to executing a
  887. .I return
  888. statement in one of the actions, the scanner may then be called again and it
  889. will resume scanning where it left off.
  890. .PP
  891. By default (and for purposes of efficiency), the scanner uses
  892. block-reads rather than simple
  893. .I getc()
  894. calls to read characters from
  895. .I yyin.
  896. The nature of how it gets its input can be controlled by defining the
  897. .B YY_INPUT
  898. macro.
  899. YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)".  Its
  900. action is to place up to
  901. .I max_size
  902. characters in the character array
  903. .I buf
  904. and return in the integer variable
  905. .I result
  906. either the
  907. number of characters read or the constant YY_NULL (0 on Unix systems)
  908. to indicate EOF.  The default YY_INPUT reads from the
  909. global file-pointer "yyin".
  910. .PP
  911. A sample definition of YY_INPUT (in the definitions
  912. section of the input file):
  913. .nf
  914.  
  915.     %{
  916.     #define YY_INPUT(buf,result,max_size) \\
  917.         { \\
  918.         int c = getchar(); \\
  919.         result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\
  920.         }
  921.     %}
  922.  
  923. .fi
  924. This definition will change the input processing to occur
  925. one character at a time.
  926. .PP
  927. You also can add in things like keeping track of the
  928. input line number this way; but don't expect your scanner to
  929. go very fast.
  930. .PP
  931. When the scanner receives an end-of-file indication from YY_INPUT,
  932. it then checks the
  933. .B yywrap()
  934. function.  If
  935. .B yywrap()
  936. returns false (zero), then it is assumed that the
  937. function has gone ahead and set up
  938. .I yyin
  939. to point to another input file, and scanning continues.  If it returns
  940. true (non-zero), then the scanner terminates, returning 0 to its
  941. caller.
  942. .PP
  943. The default
  944. .B yywrap()
  945. always returns 1.
  946. .PP
  947. The scanner writes its
  948. .B ECHO
  949. output to the
  950. .I yyout
  951. global (default, stdout), which may be redefined by the user simply
  952. by assigning it to some other
  953. .B FILE
  954. pointer.
  955. .SH START CONDITIONS
  956. .I flex
  957. provides a mechanism for conditionally activating rules.  Any rule
  958. whose pattern is prefixed with "<sc>" will only be active when
  959. the scanner is in the start condition named "sc".  For example,
  960. .nf
  961.  
  962.     <STRING>[^"]*        { /* eat up the string body ... */
  963.                 ...
  964.                 }
  965.  
  966. .fi
  967. will be active only when the scanner is in the "STRING" start
  968. condition, and
  969. .nf
  970.  
  971.     <INITIAL,STRING,QUOTE>\\.        { /* handle an escape ... */
  972.                 ...
  973.                 }
  974.  
  975. .fi
  976. will be active only when the current start condition is
  977. either "INITIAL", "STRING", or "QUOTE".
  978. .PP
  979. Start conditions
  980. are declared in the definitions (first) section of the input
  981. using unindented lines beginning with either
  982. .B %s
  983. or
  984. .B %x
  985. followed by a list of names.
  986. The former declares
  987. .I inclusive
  988. start conditions, the latter
  989. .I exclusive
  990. start conditions.  A start condition is activated using the
  991. .B BEGIN
  992. action.  Until the next
  993. .B BEGIN
  994. action is executed, rules with the given start
  995. condition will be active and
  996. rules with other start conditions will be inactive.
  997. If the start condition is
  998. .I inclusive,
  999. then rules with no start conditions at all will also be active.
  1000. If it is
  1001. .I exclusive,
  1002. then
  1003. .I only
  1004. rules qualified with the start condition will be active.
  1005. A set of rules contingent on the same exclusive start condition
  1006. describe a scanner which is independent of any of the other rules in the
  1007. .I flex
  1008. input.  Because of this,
  1009. exclusive start conditions make it easy to specify "mini-scanners"
  1010. which scan portions of the input that are syntactically different
  1011. from the rest (e.g., comments).
  1012. .PP
  1013. If the distinction between inclusive and exclusive start conditions
  1014. is still a little vague, here's a simple example illustrating the
  1015. connection between the two.  The set of rules:
  1016. .nf
  1017.  
  1018.     %s example
  1019.     %%
  1020.     <example>foo           /* do something */
  1021.  
  1022. .fi
  1023. is equivalent to
  1024. .nf
  1025.  
  1026.     %x example
  1027.     %%
  1028.     <INITIAL,example>foo   /* do something */
  1029.  
  1030. .fi
  1031. .PP
  1032. Also note that the special start-condition specifier
  1033. .B <*>
  1034. matches every start condition.  Thus, the above example could also
  1035. have been written;
  1036. .nf
  1037.  
  1038.     %x example
  1039.     %%
  1040.     <*>foo   /* do something */
  1041.  
  1042. .fi
  1043. .PP
  1044. The default rule (to
  1045. .B ECHO
  1046. any unmatched character) remains active in start conditions.
  1047. .PP
  1048. .B BEGIN(0)
  1049. returns to the original state where only the rules with
  1050. no start conditions are active.  This state can also be
  1051. referred to as the start-condition "INITIAL", so
  1052. .B BEGIN(INITIAL)
  1053. is equivalent to
  1054. .B BEGIN(0).
  1055. (The parentheses around the start condition name are not required but
  1056. are considered good style.)
  1057. .PP
  1058. .B BEGIN
  1059. actions can also be given as indented code at the beginning
  1060. of the rules section.  For example, the following will cause
  1061. the scanner to enter the "SPECIAL" start condition whenever
  1062. .I yylex()
  1063. is called and the global variable
  1064. .I enter_special
  1065. is true:
  1066. .nf
  1067.  
  1068.             int enter_special;
  1069.  
  1070.     %x SPECIAL
  1071.     %%
  1072.             if ( enter_special )
  1073.                 BEGIN(SPECIAL);
  1074.  
  1075.     <SPECIAL>blahblahblah
  1076.     ...more rules follow...
  1077.  
  1078. .fi
  1079. .PP
  1080. To illustrate the uses of start conditions,
  1081. here is a scanner which provides two different interpretations
  1082. of a string like "123.456".  By default it will treat it as
  1083. as three tokens, the integer "123", a dot ('.'), and the integer "456".
  1084. But if the string is preceded earlier in the line by the string
  1085. "expect-floats"
  1086. it will treat it as a single token, the floating-point number
  1087. 123.456:
  1088. .nf
  1089.  
  1090.     %{
  1091.     #include <math.h>
  1092.     %}
  1093.     %s expect
  1094.  
  1095.     %%
  1096.     expect-floats        BEGIN(expect);
  1097.  
  1098.     <expect>[0-9]+"."[0-9]+      {
  1099.                 printf( "found a float, = %f\\n",
  1100.                         atof( yytext ) );
  1101.                 }
  1102.     <expect>\\n           {
  1103.                 /* that's the end of the line, so
  1104.                  * we need another "expect-number"
  1105.                  * before we'll recognize any more
  1106.                  * numbers
  1107.                  */
  1108.                 BEGIN(INITIAL);
  1109.                 }
  1110.  
  1111.     [0-9]+      {
  1112.                 printf( "found an integer, = %d\\n",
  1113.                         atoi( yytext ) );
  1114.                 }
  1115.  
  1116.     "."         printf( "found a dot\\n" );
  1117.  
  1118. .fi
  1119. Here is a scanner which recognizes (and discards) C comments while
  1120. maintaining a count of the current input line.
  1121. .nf
  1122.  
  1123.     %x comment
  1124.     %%
  1125.             int line_num = 1;
  1126.  
  1127.     "/*"         BEGIN(comment);
  1128.  
  1129.     <comment>[^*\\n]*        /* eat anything that's not a '*' */
  1130.     <comment>"*"+[^*/\\n]*   /* eat up '*'s not followed by '/'s */
  1131.     <comment>\\n             ++line_num;
  1132.     <comment>"*"+"/"        BEGIN(INITIAL);
  1133.  
  1134. .fi
  1135. This scanner goes to a bit of trouble to match as much
  1136. text as possible with each rule.  In general, when attempting to write
  1137. a high-speed scanner try to match as much possible in each rule, as
  1138. it's a big win.
  1139. .PP
  1140. Note that start-conditions names are really integer values and
  1141. can be stored as such.  Thus, the above could be extended in the
  1142. following fashion:
  1143. .nf
  1144.  
  1145.     %x comment foo
  1146.     %%
  1147.             int line_num = 1;
  1148.             int comment_caller;
  1149.  
  1150.     "/*"         {
  1151.                  comment_caller = INITIAL;
  1152.                  BEGIN(comment);
  1153.                  }
  1154.  
  1155.     ...
  1156.  
  1157.     <foo>"/*"    {
  1158.                  comment_caller = foo;
  1159.                  BEGIN(comment);
  1160.                  }
  1161.  
  1162.     <comment>[^*\\n]*        /* eat anything that's not a '*' */
  1163.     <comment>"*"+[^*/\\n]*   /* eat up '*'s not followed by '/'s */
  1164.     <comment>\\n             ++line_num;
  1165.     <comment>"*"+"/"        BEGIN(comment_caller);
  1166.  
  1167. .fi
  1168. Furthermore, you can access the current start condition using
  1169. the integer-valued
  1170. .B YY_START
  1171. macro.  For example, the above assignments to
  1172. .I comment_caller
  1173. could instead be written
  1174. .nf
  1175.  
  1176.     comment_caller = YY_START;
  1177. .fi
  1178. .PP
  1179. Note that start conditions do not have their own name-space; %s's and %x's
  1180. declare names in the same fashion as #define's.
  1181. .PP
  1182. Finally, here's an example of how to match C-style quoted strings using
  1183. exclusive start conditions, including expanded escape sequences (but
  1184. not including checking for a string that's too long):
  1185. .nf
  1186.  
  1187.     %x str
  1188.  
  1189.     %%
  1190.             char string_buf[MAX_STR_CONST];
  1191.             char *string_buf_ptr;
  1192.  
  1193.  
  1194.     \\"      string_buf_ptr = string_buf; BEGIN(str);
  1195.  
  1196.     <str>\\"        { /* saw closing quote - all done */
  1197.             BEGIN(INITIAL);
  1198.             *string_buf_ptr = '\\0';
  1199.             /* return string constant token type and
  1200.              * value to parser
  1201.              */
  1202.             }
  1203.  
  1204.     <str>\\n        {
  1205.             /* error - unterminated string constant */
  1206.             /* generate error message */
  1207.             }
  1208.  
  1209.     <str>\\\\[0-7]{1,3} {
  1210.             /* octal escape sequence */
  1211.             int result;
  1212.  
  1213.             (void) sscanf( yytext + 1, "%o", &result );
  1214.  
  1215.             if ( result > 0xff )
  1216.                     /* error, constant is out-of-bounds */
  1217.  
  1218.             *string_buf_ptr++ = result;
  1219.             }
  1220.  
  1221.     <str>\\\\[0-9]+ {
  1222.             /* generate error - bad escape sequence; something
  1223.              * like '\\48' or '\\0777777'
  1224.              */
  1225.             }
  1226.  
  1227.     <str>\\\\n  *string_buf_ptr++ = '\\n';
  1228.     <str>\\\\t  *string_buf_ptr++ = '\\t';
  1229.     <str>\\\\r  *string_buf_ptr++ = '\\r';
  1230.     <str>\\\\b  *string_buf_ptr++ = '\\b';
  1231.     <str>\\\\f  *string_buf_ptr++ = '\\f';
  1232.  
  1233.     <str>\\\\(.|\\n)  *string_buf_ptr++ = yytext[1];
  1234.  
  1235.     <str>[^\\\\\\n\\"]+        {
  1236.             char *yytext_ptr = yytext;
  1237.  
  1238.             while ( *yytext_ptr )
  1239.                     *string_buf_ptr++ = *yytext_ptr++;
  1240.             }
  1241.  
  1242. .fi
  1243. .SH MULTIPLE INPUT BUFFERS
  1244. Some scanners (such as those which support "include" files)
  1245. require reading from several input streams.  As
  1246. .I flex
  1247. scanners do a large amount of buffering, one cannot control
  1248. where the next input will be read from by simply writing a
  1249. .B YY_INPUT
  1250. which is sensitive to the scanning context.
  1251. .B YY_INPUT
  1252. is only called when the scanner reaches the end of its buffer, which
  1253. may be a long time after scanning a statement such as an "include"
  1254. which requires switching the input source.
  1255. .PP
  1256. To negotiate these sorts of problems,
  1257. .I flex
  1258. provides a mechanism for creating and switching between multiple
  1259. input buffers.  An input buffer is created by using:
  1260. .nf
  1261.  
  1262.     YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1263.  
  1264. .fi
  1265. which takes a
  1266. .I FILE
  1267. pointer and a size and creates a buffer associated with the given
  1268. file and large enough to hold
  1269. .I size
  1270. characters (when in doubt, use
  1271. .B YY_BUF_SIZE
  1272. for the size).  It returns a
  1273. .B YY_BUFFER_STATE
  1274. handle, which may then be passed to other routines:
  1275. .nf
  1276.  
  1277.     void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1278.  
  1279. .fi
  1280. switches the scanner's input buffer so subsequent tokens will
  1281. come from
  1282. .I new_buffer.
  1283. Note that
  1284. .B yy_switch_to_buffer()
  1285. may be used by yywrap() to set things up for continued scanning, instead
  1286. of opening a new file and pointing
  1287. .I yyin
  1288. at it.
  1289. .nf
  1290.  
  1291.     void yy_delete_buffer( YY_BUFFER_STATE buffer )
  1292.  
  1293. .fi
  1294. is used to reclaim the storage associated with a buffer.
  1295. .PP
  1296. .B yy_new_buffer()
  1297. is an alias for
  1298. .B yy_create_buffer(),
  1299. provided for compatibility with the C++ use of
  1300. .I new
  1301. and
  1302. .I delete
  1303. for creating and destroying dynamic objects.
  1304. .PP
  1305. Finally, the
  1306. .B YY_CURRENT_BUFFER
  1307. macro returns a
  1308. .B YY_BUFFER_STATE
  1309. handle to the current buffer.
  1310. .PP
  1311. Here is an example of using these features for writing a scanner
  1312. which expands include files (the
  1313. .B <<EOF>>
  1314. feature is discussed below):
  1315. .nf
  1316.  
  1317.     /* the "incl" state is used for picking up the name
  1318.      * of an include file
  1319.      */
  1320.     %x incl
  1321.  
  1322.     %{
  1323.     #define MAX_INCLUDE_DEPTH 10
  1324.     YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  1325.     int include_stack_ptr = 0;
  1326.     %}
  1327.  
  1328.     %%
  1329.     include             BEGIN(incl);
  1330.  
  1331.     [a-z]+              ECHO;
  1332.     [^a-z\\n]*\\n?        ECHO;
  1333.  
  1334.     <incl>[ \\t]*      /* eat the whitespace */
  1335.     <incl>[^ \\t\\n]+   { /* got the include file name */
  1336.             if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
  1337.                 {
  1338.                 fprintf( stderr, "Includes nested too deeply" );
  1339.                 exit( 1 );
  1340.                 }
  1341.  
  1342.             include_stack[include_stack_ptr++] =
  1343.                 YY_CURRENT_BUFFER;
  1344.  
  1345.             yyin = fopen( yytext, "r" );
  1346.  
  1347.             if ( ! yyin )
  1348.                 error( ... );
  1349.  
  1350.             yy_switch_to_buffer(
  1351.                 yy_create_buffer( yyin, YY_BUF_SIZE ) );
  1352.  
  1353.             BEGIN(INITIAL);
  1354.             }
  1355.  
  1356.     <<EOF>> {
  1357.             if ( --include_stack_ptr < 0 )
  1358.                 {
  1359.                 yyterminate();
  1360.                 }
  1361.  
  1362.             else
  1363.                 {
  1364.                 yy_delete_buffer( YY_CURRENT_BUFFER );
  1365.                 yy_switch_to_buffer(
  1366.                      include_stack[include_stack_ptr] );
  1367.                 }
  1368.             }
  1369.  
  1370. .fi
  1371. .SH END-OF-FILE RULES
  1372. The special rule "<<EOF>>" indicates
  1373. actions which are to be taken when an end-of-file is
  1374. encountered and yywrap() returns non-zero (i.e., indicates
  1375. no further files to process).  The action must finish
  1376. by doing one of four things:
  1377. .IP -
  1378. assigning
  1379. .I yyin
  1380. to a new input file (in previous versions of flex, after doing the
  1381. assignment you had to call the special action
  1382. .B YY_NEW_FILE;
  1383. this is no longer necessary);
  1384. .IP -
  1385. executing a
  1386. .I return
  1387. statement;
  1388. .IP -
  1389. executing the special
  1390. .B yyterminate()
  1391. action;
  1392. .IP -
  1393. or, switching to a new buffer using
  1394. .B yy_switch_to_buffer()
  1395. as shown in the example above.
  1396. .PP
  1397. <<EOF>> rules may not be used with other
  1398. patterns; they may only be qualified with a list of start
  1399. conditions.  If an unqualified <<EOF>> rule is given, it
  1400. applies to
  1401. .I all
  1402. start conditions which do not already have <<EOF>> actions.  To
  1403. specify an <<EOF>> rule for only the initial start condition, use
  1404. .nf
  1405.  
  1406.     <INITIAL><<EOF>>
  1407.  
  1408. .fi
  1409. .PP
  1410. These rules are useful for catching things like unclosed comments.
  1411. An example:
  1412. .nf
  1413.  
  1414.     %x quote
  1415.     %%
  1416.  
  1417.     ...other rules for dealing with quotes...
  1418.  
  1419.     <quote><<EOF>>   {
  1420.              error( "unterminated quote" );
  1421.              yyterminate();
  1422.              }
  1423.     <<EOF>>  {
  1424.              if ( *++filelist )
  1425.                  yyin = fopen( *filelist, "r" );
  1426.              else
  1427.                 yyterminate();
  1428.              }
  1429.  
  1430. .fi
  1431. .SH MISCELLANEOUS MACROS
  1432. The macro
  1433. .bd
  1434. YY_USER_ACTION
  1435. can be defined to provide an action
  1436. which is always executed prior to the matched rule's action.  For example,
  1437. it could be #define'd to call a routine to convert yytext to lower-case.
  1438. .PP
  1439. The macro
  1440. .B YY_USER_INIT
  1441. may be defined to provide an action which is always executed before
  1442. the first scan (and before the scanner's internal initializations are done).
  1443. For example, it could be used to call a routine to read
  1444. in a data table or open a logging file.
  1445. .PP
  1446. In the generated scanner, the actions are all gathered in one large
  1447. switch statement and separated using
  1448. .B YY_BREAK,
  1449. which may be redefined.  By default, it is simply a "break", to separate
  1450. each rule's action from the following rule's.
  1451. Redefining
  1452. .B YY_BREAK
  1453. allows, for example, C++ users to
  1454. #define YY_BREAK to do nothing (while being very careful that every
  1455. rule ends with a "break" or a "return"!) to avoid suffering from
  1456. unreachable statement warnings where because a rule's action ends with
  1457. "return", the
  1458. .B YY_BREAK
  1459. is inaccessible.
  1460. .SH INTERFACING WITH YACC
  1461. One of the main uses of
  1462. .I flex
  1463. is as a companion to the
  1464. .I yacc
  1465. parser-generator.
  1466. .I yacc
  1467. parsers expect to call a routine named
  1468. .B yylex()
  1469. to find the next input token.  The routine is supposed to
  1470. return the type of the next token as well as putting any associated
  1471. value in the global
  1472. .B yylval.
  1473. To use
  1474. .I flex
  1475. with
  1476. .I yacc,
  1477. one specifies the
  1478. .B \-d
  1479. option to
  1480. .I yacc
  1481. to instruct it to generate the file
  1482. .B y.tab.h
  1483. containing definitions of all the
  1484. .B %tokens
  1485. appearing in the
  1486. .I yacc
  1487. input.  This file is then included in the
  1488. .I flex
  1489. scanner.  For example, if one of the tokens is "TOK_NUMBER",
  1490. part of the scanner might look like:
  1491. .nf
  1492.  
  1493.     %{
  1494.     #include "y.tab.h"
  1495.     %}
  1496.  
  1497.     %%
  1498.  
  1499.     [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
  1500.  
  1501. .fi
  1502. .SH OPTIONS
  1503. .I flex
  1504. has the following options:
  1505. .TP
  1506. .B \-b
  1507. Generate backing-up information to
  1508. .I lex.backup.
  1509. This is a list of scanner states which require backing up
  1510. and the input characters on which they do so.  By adding rules one
  1511. can remove backing-up states.  If all backing-up states
  1512. are eliminated and
  1513. .B \-Cf
  1514. or
  1515. .B \-CF
  1516. is used, the generated scanner will run faster (see the
  1517. .B \-p
  1518. flag).  Only users who wish to squeeze every last cycle out of their
  1519. scanners need worry about this option.  (See the section on Performance
  1520. Considerations below.)
  1521. .TP
  1522. .B \-c
  1523. is a do-nothing, deprecated option included for POSIX compliance.
  1524. .IP
  1525. .B NOTE:
  1526. in previous releases of
  1527. .I flex
  1528. .B \-c
  1529. specified table-compression options.  This functionality is
  1530. now given by the
  1531. .B \-C
  1532. flag.  To ease the the impact of this change, when
  1533. .I flex
  1534. encounters
  1535. .B \-c,
  1536. it currently issues a warning message and assumes that
  1537. .B \-C
  1538. was desired instead.  In the future this "promotion" of
  1539. .B \-c
  1540. to
  1541. .B \-C
  1542. will go away in the name of full POSIX compliance (unless
  1543. the POSIX meaning is removed first).
  1544. .TP
  1545. .B \-d
  1546. makes the generated scanner run in
  1547. .I debug
  1548. mode.  Whenever a pattern is recognized and the global
  1549. .B yy_flex_debug
  1550. is non-zero (which is the default),
  1551. the scanner will write to
  1552. .I stderr
  1553. a line of the form:
  1554. .nf
  1555.  
  1556.     --accepting rule at line 53 ("the matched text")
  1557.  
  1558. .fi
  1559. The line number refers to the location of the rule in the file
  1560. defining the scanner (i.e., the file that was fed to flex).  Messages
  1561. are also generated when the scanner backs up, accepts the
  1562. default rule, reaches the end of its input buffer (or encounters
  1563. a NUL; at this point, the two look the same as far as the scanner's concerned),
  1564. or reaches an end-of-file.
  1565. .TP
  1566. .B \-f
  1567. specifies
  1568. .I fast scanner.
  1569. No table compression is done and stdio is bypassed.
  1570. The result is large but fast.  This option is equivalent to
  1571. .B \-Cfr
  1572. (see below).
  1573. .TP
  1574. .B \-h
  1575. generates a "help" summary of
  1576. .I flex's
  1577. options to
  1578. .I stderr 
  1579. and then exits.
  1580. .TP
  1581. .B \-i
  1582. instructs
  1583. .I flex
  1584. to generate a
  1585. .I case-insensitive
  1586. scanner.  The case of letters given in the
  1587. .I flex
  1588. input patterns will
  1589. be ignored, and tokens in the input will be matched regardless of case.  The
  1590. matched text given in
  1591. .I yytext
  1592. will have the preserved case (i.e., it will not be folded).
  1593. .TP
  1594. .B \-l
  1595. turns on maximum compatibility with the original AT&T
  1596. .I lex
  1597. implementation.  Note that this does not mean
  1598. .I full
  1599. compatibility.  Use of this option costs a considerable amount of
  1600. performance, and it cannot be used with the
  1601. .B \-+, -f, -F, -Cf,
  1602. or
  1603. .B -CF
  1604. options.  For details on the compatibilities it provides, see the section
  1605. "Incompatibilities With Lex And POSIX" below.
  1606. .TP
  1607. .B \-n
  1608. is another do-nothing, deprecated option included only for
  1609. POSIX compliance.
  1610. .TP
  1611. .B \-p
  1612. generates a performance report to stderr.  The report
  1613. consists of comments regarding features of the
  1614. .I flex
  1615. input file which will cause a serious loss of performance in the resulting
  1616. scanner.  If you give the flag twice, you will also get comments regarding
  1617. features that lead to minor performance losses.
  1618. .IP
  1619. Note that the use of
  1620. .B REJECT
  1621. and variable trailing context (see the Bugs section in flex(1))
  1622. entails a substantial performance penalty; use of
  1623. .I yymore(),
  1624. the
  1625. .B ^
  1626. operator,
  1627. and the
  1628. .B \-I
  1629. flag entail minor performance penalties.
  1630. .TP
  1631. .B \-s
  1632. causes the
  1633. .I default rule
  1634. (that unmatched scanner input is echoed to
  1635. .I stdout)
  1636. to be suppressed.  If the scanner encounters input that does not
  1637. match any of its rules, it aborts with an error.  This option is
  1638. useful for finding holes in a scanner's rule set.
  1639. .TP
  1640. .B \-t
  1641. instructs
  1642. .I flex
  1643. to write the scanner it generates to standard output instead
  1644. of
  1645. .B lex.yy.c.
  1646. .TP
  1647. .B \-v
  1648. specifies that
  1649. .I flex
  1650. should write to
  1651. .I stderr
  1652. a summary of statistics regarding the scanner it generates.
  1653. Most of the statistics are meaningless to the casual
  1654. .I flex
  1655. user, but the first line identifies the version of
  1656. .I flex
  1657. (same as reported by
  1658. .B \-V),
  1659. and the next line the flags used when generating the scanner, including
  1660. those that are on by default.
  1661. .TP
  1662. .B \-w
  1663. suppresses warning messages.
  1664. .TP
  1665. .B \-B
  1666. instructs
  1667. .I flex
  1668. to generate a
  1669. .I batch
  1670. scanner, the opposite of
  1671. .I interactive
  1672. scanners generated by
  1673. .B \-I
  1674. (see below).  In general, you use
  1675. .B \-B
  1676. when you are
  1677. .I certain
  1678. that your scanner will never be used interactively, and you want to
  1679. squeeze a
  1680. .I little
  1681. more performance out of it.  If your goal is instead to squeeze out a
  1682. .I lot
  1683. more performance, you should  be using the
  1684. .B \-Cf
  1685. or
  1686. .B \-CF
  1687. options (discussed below), which turn on
  1688. .B \-B
  1689. automatically anyway.
  1690. .TP
  1691. .B \-F
  1692. specifies that the
  1693. .ul
  1694. fast
  1695. scanner table representation should be used (and stdio
  1696. bypassed).  This representation is
  1697. about as fast as the full table representation
  1698. .B (-f),
  1699. and for some sets of patterns will be considerably smaller (and for
  1700. others, larger).  In general, if the pattern set contains both "keywords"
  1701. and a catch-all, "identifier" rule, such as in the set:
  1702. .nf
  1703.  
  1704.     "case"    return TOK_CASE;
  1705.     "switch"  return TOK_SWITCH;
  1706.     ...
  1707.     "default" return TOK_DEFAULT;
  1708.     [a-z]+    return TOK_ID;
  1709.  
  1710. .fi
  1711. then you're better off using the full table representation.  If only
  1712. the "identifier" rule is present and you then use a hash table or some such
  1713. to detect the keywords, you're better off using
  1714. .B -F.
  1715. .IP
  1716. This option is equivalent to
  1717. .B \-CFr
  1718. (see below).  It cannot be used with
  1719. .B \-+.
  1720. .TP
  1721. .B \-I
  1722. instructs
  1723. .I flex
  1724. to generate an
  1725. .I interactive
  1726. scanner.  An interactive scanner is one that only looks ahead to decide
  1727. what token has been matched if it absolutely must.  It turns out that
  1728. always looking one extra character ahead, even if the scanner has already
  1729. seen enough text to disambiguate the current token, is a bit faster than
  1730. only looking ahead when necessary.  But scanners that always look ahead
  1731. give dreadful interactive performance; for example, when a user types
  1732. a newline, it is not recognized as a newline token until they enter
  1733. .I another
  1734. token, which often means typing in another whole line.
  1735. .IP
  1736. .I Flex
  1737. scanners default to
  1738. .I interactive
  1739. unless you use the
  1740. .B \-Cf
  1741. or
  1742. .B \-CF
  1743. table-compression options (see below).  That's because if you're looking
  1744. for high-performance you should be using one of these options, so if you
  1745. didn't,
  1746. .I flex
  1747. assumes you'd rather trade off a bit of run-time performance for intuitive
  1748. interactive behavior.  Note also that you
  1749. .I cannot
  1750. use
  1751. .B \-I
  1752. in conjunction with
  1753. .B \-Cf
  1754. or
  1755. .B \-CF.
  1756. Thus, this option is not really needed; it is on by default for all those
  1757. cases in which it is allowed.
  1758. .IP
  1759. You can force a scanner to
  1760. .I not
  1761. be interactive by using
  1762. .B \-B
  1763. (see above).
  1764. .TP
  1765. .B \-L
  1766. instructs
  1767. .I flex
  1768. not to generate
  1769. .B #line
  1770. directives.  Without this option,
  1771. .I flex
  1772. peppers the generated scanner
  1773. with #line directives so error messages in the actions will be correctly
  1774. located with respect to the original
  1775. .I flex
  1776. input file, and not to
  1777. the fairly meaningless line numbers of
  1778. .B lex.yy.c.
  1779. (Unfortunately
  1780. .I flex
  1781. does not presently generate the necessary directives
  1782. to "retarget" the line numbers for those parts of
  1783. .B lex.yy.c
  1784. which it generated.  So if there is an error in the generated code,
  1785. a meaningless line number is reported.)
  1786. .TP
  1787. .B \-T
  1788. makes
  1789. .I flex
  1790. run in
  1791. .I trace
  1792. mode.  It will generate a lot of messages to
  1793. .I stderr
  1794. concerning
  1795. the form of the input and the resultant non-deterministic and deterministic
  1796. finite automata.  This option is mostly for use in maintaining
  1797. .I flex.
  1798. .TP
  1799. .B \-V
  1800. prints the version number to
  1801. .I stderr
  1802. and exits.
  1803. .TP
  1804. .B \-7
  1805. instructs
  1806. .I flex
  1807. to generate a 7-bit scanner, i.e., one which can only recognized 7-bit
  1808. characters in its input.  The advantage of using
  1809. .B \-7
  1810. is that the scanner's tables can be up to half the size of those generated
  1811. using the
  1812. .B \-8
  1813. option (see below).  The disadvantage is that such scanners often hang
  1814. or crash if their input contains an 8-bit character.
  1815. .IP
  1816. Note, however, that unless you generate your scanner using the
  1817. .B \-Cf
  1818. or
  1819. .B \-CF
  1820. table compression options, use of
  1821. .B \-7
  1822. will save only a small amount of table space, and make your scanner
  1823. considerably less portable.
  1824. .I Flex's
  1825. default behavior is to generate an 8-bit scanner unless you use the
  1826. .B \-Cf
  1827. or
  1828. .B \-CF,
  1829. in which case
  1830. .I flex
  1831. defaults to generating 7-bit scanners unless your site was always
  1832. configured to generate 8-bit scanners (as will often be the case
  1833. with non-USA sites).  You can tell whether flex generated a 7-bit
  1834. or an 8-bit scanner by inspecting the flag summary in the
  1835. .B \-v
  1836. output as described above.
  1837. .IP
  1838. Note that if you use
  1839. .B \-Cfe
  1840. or
  1841. .B \-CFe
  1842. (those table compression options, but also using equivalence classes as
  1843. discussed see below), flex still defaults to generating an 8-bit
  1844. scanner, since usually with these compression options full 8-bit tables
  1845. are not much more expensive than 7-bit tables.
  1846. .TP
  1847. .B \-8
  1848. instructs
  1849. .I flex
  1850. to generate an 8-bit scanner, i.e., one which can recognize 8-bit
  1851. characters.  This flag is only needed for scanners generated using
  1852. .B \-Cf
  1853. or
  1854. .B \-CF,
  1855. as otherwise flex defaults to generating an 8-bit scanner anyway.
  1856. .IP
  1857. See the discussion of
  1858. .B \-7
  1859. above for flex's default behavior and the tradeoffs between 7-bit
  1860. and 8-bit scanners.
  1861. .TP
  1862. .B \-+
  1863. specifies that you want flex to generate a C++
  1864. scanner class.  See the section on Generating C++ Scanners below for
  1865. details.
  1866. .TP 
  1867. .B \-C[aefFmr]
  1868. controls the degree of table compression and, more generally, trade-offs
  1869. between small scanners and fast scanners.
  1870. .IP
  1871. .B \-Ca
  1872. ("align") instructs flex to trade off larger tables in the
  1873. generated scanner for faster performance because the elements of
  1874. the tables are better aligned for memory access and computation.  On some
  1875. RISC architectures, fetching and manipulating longwords is more efficient
  1876. than with smaller-sized datums such as shortwords.  This option can
  1877. double the size of the tables used by your scanner.
  1878. .IP
  1879. .B \-Ce
  1880. directs
  1881. .I flex
  1882. to construct
  1883. .I equivalence classes,
  1884. i.e., sets of characters
  1885. which have identical lexical properties (for example, if the only
  1886. appearance of digits in the
  1887. .I flex
  1888. input is in the character class
  1889. "[0-9]" then the digits '0', '1', ..., '9' will all be put
  1890. in the same equivalence class).  Equivalence classes usually give
  1891. dramatic reductions in the final table/object file sizes (typically
  1892. a factor of 2-5) and are pretty cheap performance-wise (one array
  1893. look-up per character scanned).
  1894. .IP
  1895. .B \-Cf
  1896. specifies that the
  1897. .I full
  1898. scanner tables should be generated -
  1899. .I flex
  1900. should not compress the
  1901. tables by taking advantages of similar transition functions for
  1902. different states.
  1903. .IP
  1904. .B \-CF
  1905. specifies that the alternate fast scanner representation (described
  1906. above under the
  1907. .B \-F
  1908. flag)
  1909. should be used.  This option cannot be used with
  1910. .B \-+.
  1911. .IP
  1912. .B \-Cm
  1913. directs
  1914. .I flex
  1915. to construct
  1916. .I meta-equivalence classes,
  1917. which are sets of equivalence classes (or characters, if equivalence
  1918. classes are not being used) that are commonly used together.  Meta-equivalence
  1919. classes are often a big win when using compressed tables, but they
  1920. have a moderate performance impact (one or two "if" tests and one
  1921. array look-up per character scanned).
  1922. .IP
  1923. .B \-Cr
  1924. causes the generated scanner to
  1925. .I bypass
  1926. use of the standard I/O library (stdio) for input.  Instead of calling
  1927. .B fread()
  1928. or
  1929. .B getc(),
  1930. the scanner will use the
  1931. .B read()
  1932. system call, resulting in a performance gain which varies from system
  1933. to system, but in general is probably negligible unless you are also using
  1934. .B \-Cf
  1935. or
  1936. .B \-CF.
  1937. Using
  1938. .B \-Cr
  1939. can cause strange behavior if, for example, you read from
  1940. .I yyin
  1941. using stdio prior to calling the scanner (because the scanner will miss
  1942. whatever text your previous reads left in the stdio input buffer).
  1943. .IP
  1944. .B \-Cr
  1945. has no effect if you define
  1946. .B YY_INPUT
  1947. (see The Generated Scanner above).
  1948. .IP
  1949. A lone
  1950. .B \-C
  1951. specifies that the scanner tables should be compressed but neither
  1952. equivalence classes nor meta-equivalence classes should be used.
  1953. .IP
  1954. The options
  1955. .B \-Cf
  1956. or
  1957. .B \-CF
  1958. and
  1959. .B \-Cm
  1960. do not make sense together - there is no opportunity for meta-equivalence
  1961. classes if the table is not being compressed.  Otherwise the options
  1962. may be freely mixed, and are cumulative.
  1963. .IP
  1964. The default setting is
  1965. .B \-Cem,
  1966. which specifies that
  1967. .I flex
  1968. should generate equivalence classes
  1969. and meta-equivalence classes.  This setting provides the highest
  1970. degree of table compression.  You can trade off
  1971. faster-executing scanners at the cost of larger tables with
  1972. the following generally being true:
  1973. .nf
  1974.  
  1975.     slowest & smallest
  1976.           -Cem
  1977.           -Cm
  1978.           -Ce
  1979.           -C
  1980.           -C{f,F}e
  1981.           -C{f,F}
  1982.           -C{f,F}a
  1983.     fastest & largest
  1984.  
  1985. .fi
  1986. Note that scanners with the smallest tables are usually generated and
  1987. compiled the quickest, so
  1988. during development you will usually want to use the default, maximal
  1989. compression.
  1990. .IP
  1991. .B \-Cfe
  1992. is often a good compromise between speed and size for production
  1993. scanners.
  1994. .TP
  1995. .B \-Pprefix
  1996. changes the default
  1997. .I "yy"
  1998. prefix used by
  1999. .I flex
  2000. for all globally-visible variable and function names to instead be
  2001. .I prefix.
  2002. For example,
  2003. .B \-Pfoo
  2004. changes the name of
  2005. .B yytext
  2006. to
  2007. .B footext.
  2008. It also changes the name of the default output file from
  2009. .B lex.yy.c
  2010. to
  2011. .B lex.foo.c.
  2012. Here are all of the names affected:
  2013. .nf
  2014.  
  2015.     yyFlexLexer
  2016.     yy_create_buffer
  2017.     yy_delete_buffer
  2018.     yy_flex_debug
  2019.     yy_init_buffer
  2020.     yy_load_buffer_state
  2021.     yy_switch_to_buffer
  2022.     yyin
  2023.     yyleng
  2024.     yylex
  2025.     yyout
  2026.     yyrestart
  2027.     yytext
  2028.     yywrap
  2029.  
  2030. .fi
  2031. Within your scanner itself, you can still refer to the global variables
  2032. and functions using either version of their name; but eternally, they
  2033. have the modified name.
  2034. .IP
  2035. This option lets you easily link together multiple
  2036. .I flex
  2037. programs into the same executable.  Note, though, that using this
  2038. option also renames
  2039. .B yywrap(),
  2040. so you now
  2041. .I must
  2042. provide your own (appropriately-named) version of the routine for your
  2043. scanner, as linking with
  2044. .B \-lfl
  2045. no longer provides one for you by default.
  2046. .TP
  2047. .B \-Sskeleton_file
  2048. overrides the default skeleton file from which
  2049. .I flex
  2050. constructs its scanners.  You'll never need this option unless you are doing
  2051. .I flex
  2052. maintenance or development.
  2053. .SH PERFORMANCE CONSIDERATIONS
  2054. The main design goal of
  2055. .I flex
  2056. is that it generate high-performance scanners.  It has been optimized
  2057. for dealing well with large sets of rules.  Aside from the effects on
  2058. scanner speed of the table compression
  2059. .B \-C
  2060. options outlined above,
  2061. there are a number of options/actions which degrade performance.  These
  2062. are, from most expensive to least:
  2063. .nf
  2064.  
  2065.     REJECT
  2066.  
  2067.     pattern sets that require backing up
  2068.     arbitrary trailing context
  2069.  
  2070.     yymore()
  2071.     '^' beginning-of-line operator
  2072.  
  2073. .fi
  2074. with the first three all being quite expensive and the last two
  2075. being quite cheap.  Note also that
  2076. .B unput()
  2077. is implemented as a routine call that potentially does quite a bit of
  2078. work, while
  2079. .B yyless()
  2080. is a quite-cheap macro; so if just putting back some excess text you
  2081. scanned, use
  2082. .B yyless().
  2083. .PP
  2084. .B REJECT
  2085. should be avoided at all costs when performance is important.
  2086. It is a particularly expensive option.
  2087. .PP
  2088. Getting rid of backing up is messy and often may be an enormous
  2089. amount of work for a complicated scanner.  In principal, one begins
  2090. by using the
  2091. .B \-b 
  2092. flag to generate a
  2093. .I lex.backup
  2094. file.  For example, on the input
  2095. .nf
  2096.  
  2097.     %%
  2098.     foo        return TOK_KEYWORD;
  2099.     foobar     return TOK_KEYWORD;
  2100.  
  2101. .fi
  2102. the file looks like:
  2103. .nf
  2104.  
  2105.     State #6 is non-accepting -
  2106.      associated rule line numbers:
  2107.            2       3
  2108.      out-transitions: [ o ]
  2109.      jam-transitions: EOF [ \\001-n  p-\\177 ]
  2110.  
  2111.     State #8 is non-accepting -
  2112.      associated rule line numbers:
  2113.            3
  2114.      out-transitions: [ a ]
  2115.      jam-transitions: EOF [ \\001-`  b-\\177 ]
  2116.  
  2117.     State #9 is non-accepting -
  2118.      associated rule line numbers:
  2119.            3
  2120.      out-transitions: [ r ]
  2121.      jam-transitions: EOF [ \\001-q  s-\\177 ]
  2122.  
  2123.     Compressed tables always back up.
  2124.  
  2125. .fi
  2126. The first few lines tell us that there's a scanner state in
  2127. which it can make a transition on an 'o' but not on any other
  2128. character, and that in that state the currently scanned text does not match
  2129. any rule.  The state occurs when trying to match the rules found
  2130. at lines 2 and 3 in the input file.
  2131. If the scanner is in that state and then reads
  2132. something other than an 'o', it will have to back up to find
  2133. a rule which is matched.  With
  2134. a bit of headscratching one can see that this must be the
  2135. state it's in when it has seen "fo".  When this has happened,
  2136. if anything other than another 'o' is seen, the scanner will
  2137. have to back up to simply match the 'f' (by the default rule).
  2138. .PP
  2139. The comment regarding State #8 indicates there's a problem
  2140. when "foob" has been scanned.  Indeed, on any character other
  2141. than an 'a', the scanner will have to back up to accept "foo".
  2142. Similarly, the comment for State #9 concerns when "fooba" has
  2143. been scanned and an 'r' does not follow.
  2144. .PP
  2145. The final comment reminds us that there's no point going to
  2146. all the trouble of removing backing up from the rules unless
  2147. we're using
  2148. .B \-Cf
  2149. or
  2150. .B \-CF,
  2151. since there's no performance gain doing so with compressed scanners.
  2152. .PP
  2153. The way to remove the backing up is to add "error" rules:
  2154. .nf
  2155.  
  2156.     %%
  2157.     foo         return TOK_KEYWORD;
  2158.     foobar      return TOK_KEYWORD;
  2159.  
  2160.     fooba       |
  2161.     foob        |
  2162.     fo          {
  2163.                 /* false alarm, not really a keyword */
  2164.                 return TOK_ID;
  2165.                 }
  2166.  
  2167. .fi
  2168. .PP
  2169. Eliminating backing up among a list of keywords can also be
  2170. done using a "catch-all" rule:
  2171. .nf
  2172.  
  2173.     %%
  2174.     foo         return TOK_KEYWORD;
  2175.     foobar      return TOK_KEYWORD;
  2176.  
  2177.     [a-z]+      return TOK_ID;
  2178.  
  2179. .fi
  2180. This is usually the best solution when appropriate.
  2181. .PP
  2182. Backing up messages tend to cascade.
  2183. With a complicated set of rules it's not uncommon to get hundreds
  2184. of messages.  If one can decipher them, though, it often
  2185. only takes a dozen or so rules to eliminate the backing up (though
  2186. it's easy to make a mistake and have an error rule accidentally match
  2187. a valid token.  A possible future
  2188. .I flex
  2189. feature will be to automatically add rules to eliminate backing up).
  2190. .PP
  2191. .I Variable
  2192. trailing context (where both the leading and trailing parts do not have
  2193. a fixed length) entails almost the same performance loss as
  2194. .B REJECT
  2195. (i.e., substantial).  So when possible a rule like:
  2196. .nf
  2197.  
  2198.     %%
  2199.     mouse|rat/(cat|dog)   run();
  2200.  
  2201. .fi
  2202. is better written:
  2203. .nf
  2204.  
  2205.     %%
  2206.     mouse/cat|dog         run();
  2207.     rat/cat|dog           run();
  2208.  
  2209. .fi
  2210. or as
  2211. .nf
  2212.  
  2213.     %%
  2214.     mouse|rat/cat         run();
  2215.     mouse|rat/dog         run();
  2216.  
  2217. .fi
  2218. Note that here the special '|' action does
  2219. .I not
  2220. provide any savings, and can even make things worse (see
  2221. .PP
  2222. A final note regarding performance: as mentioned above in the section
  2223. How the Input is Matched, dynamically resizing
  2224. .B yytext
  2225. to accomodate huge tokens is a slow process because it presently requires that
  2226. the (huge) token be rescanned from the beginning.  Thus if performance is
  2227. vital, you should attempt to match "large" quantities of text but not
  2228. "huge" quantities, where the cutoff between the two is at about 8K
  2229. characters/token.
  2230. .PP
  2231. Another area where the user can increase a scanner's performance
  2232. (and one that's easier to implement) arises from the fact that
  2233. the longer the tokens matched, the faster the scanner will run.
  2234. This is because with long tokens the processing of most input
  2235. characters takes place in the (short) inner scanning loop, and
  2236. does not often have to go through the additional work of setting up
  2237. the scanning environment (e.g.,
  2238. .B yytext)
  2239. for the action.  Recall the scanner for C comments:
  2240. .nf
  2241.  
  2242.     %x comment
  2243.     %%
  2244.             int line_num = 1;
  2245.  
  2246.     "/*"         BEGIN(comment);
  2247.  
  2248.     <comment>[^*\\n]*
  2249.     <comment>"*"+[^*/\\n]*
  2250.     <comment>\\n             ++line_num;
  2251.     <comment>"*"+"/"        BEGIN(INITIAL);
  2252.  
  2253. .fi
  2254. This could be sped up by writing it as:
  2255. .nf
  2256.  
  2257.     %x comment
  2258.     %%
  2259.             int line_num = 1;
  2260.  
  2261.     "/*"         BEGIN(comment);
  2262.  
  2263.     <comment>[^*\\n]*
  2264.     <comment>[^*\\n]*\\n      ++line_num;
  2265.     <comment>"*"+[^*/\\n]*
  2266.     <comment>"*"+[^*/\\n]*\\n ++line_num;
  2267.     <comment>"*"+"/"        BEGIN(INITIAL);
  2268.  
  2269. .fi
  2270. Now instead of each newline requiring the processing of another
  2271. action, recognizing the newlines is "distributed" over the other rules
  2272. to keep the matched text as long as possible.  Note that
  2273. .I adding
  2274. rules does
  2275. .I not
  2276. slow down the scanner!  The speed of the scanner is independent
  2277. of the number of rules or (modulo the considerations given at the
  2278. beginning of this section) how complicated the rules are with
  2279. regard to operators such as '*' and '|'.
  2280. .PP
  2281. A final example in speeding up a scanner: suppose you want to scan
  2282. through a file containing identifiers and keywords, one per line
  2283. and with no other extraneous characters, and recognize all the
  2284. keywords.  A natural first approach is:
  2285. .nf
  2286.  
  2287.     %%
  2288.     asm      |
  2289.     auto     |
  2290.     break    |
  2291.     ... etc ...
  2292.     volatile |
  2293.     while    /* it's a keyword */
  2294.  
  2295.     .|\\n     /* it's not a keyword */
  2296.  
  2297. .fi
  2298. To eliminate the back-tracking, introduce a catch-all rule:
  2299. .nf
  2300.  
  2301.     %%
  2302.     asm      |
  2303.     auto     |
  2304.     break    |
  2305.     ... etc ...
  2306.     volatile |
  2307.     while    /* it's a keyword */
  2308.  
  2309.     [a-z]+   |
  2310.     .|\\n     /* it's not a keyword */
  2311.  
  2312. .fi
  2313. Now, if it's guaranteed that there's exactly one word per line,
  2314. then we can reduce the total number of matches by a half by
  2315. merging in the recognition of newlines with that of the other
  2316. tokens:
  2317. .nf
  2318.  
  2319.     %%
  2320.     asm\\n    |
  2321.     auto\\n   |
  2322.     break\\n  |
  2323.     ... etc ...
  2324.     volatile\\n |
  2325.     while\\n  /* it's a keyword */
  2326.  
  2327.     [a-z]+\\n |
  2328.     .|\\n     /* it's not a keyword */
  2329.  
  2330. .fi
  2331. One has to be careful here, as we have now reintroduced backing up
  2332. into the scanner.  In particular, while
  2333. .I we
  2334. know that there will never be any characters in the input stream
  2335. other than letters or newlines,
  2336. .I flex
  2337. can't figure this out, and it will plan for possibly needing to back up
  2338. when it has scanned a token like "auto" and then the next character
  2339. is something other than a newline or a letter.  Previously it would
  2340. then just match the "auto" rule and be done, but now it has no "auto"
  2341. rule, only a "auto\\n" rule.  To eliminate the possibility of backing up,
  2342. we could either duplicate all rules but without final newlines, or,
  2343. since we never expect to encounter such an input and therefore don't
  2344. how it's classified, we can introduce one more catch-all rule, this
  2345. one which doesn't include a newline:
  2346. .nf
  2347.  
  2348.     %%
  2349.     asm\\n    |
  2350.     auto\\n   |
  2351.     break\\n  |
  2352.     ... etc ...
  2353.     volatile\\n |
  2354.     while\\n  /* it's a keyword */
  2355.  
  2356.     [a-z]+\\n |
  2357.     [a-z]+   |
  2358.     .|\\n     /* it's not a keyword */
  2359.  
  2360. .fi
  2361. Compiled with
  2362. .B \-Cf,
  2363. this is about as fast as one can get a
  2364. .I flex 
  2365. scanner to go for this particular problem.
  2366. .PP
  2367. A final note:
  2368. .I flex
  2369. is slow when matching NUL's, particularly when a token contains
  2370. multiple NUL's.
  2371. It's best to write rules which match
  2372. .I short
  2373. amounts of text if it's anticipated that the text will often include NUL's.
  2374. .SH GENERATING C++ SCANNERS
  2375. .I flex
  2376. provides two different ways to generate scanners for use with C++.  The
  2377. first way is to simply compile a scanner generated by
  2378. .I flex
  2379. using a C++ compiler instead of a C compiler.  You should not encounter
  2380. any compilations errors (please report any you find to the email address
  2381. given in the Author section below).  You can then use C++ code in your
  2382. rule actions instead of C code.  Note that the default input source for
  2383. your scanner remains
  2384. .I yyin,
  2385. and default echoing is still done to
  2386. .I yyout.
  2387. Both of these remain
  2388. .I FILE *
  2389. variables and not C++
  2390. .I streams.
  2391. .PP
  2392. You can also use
  2393. .I flex
  2394. to generate a C++ scanner class, using the
  2395. .B \-+
  2396. option, which is automatically specified if the name of the flex
  2397. executable ends in a '+', such as
  2398. .I flex++.
  2399. When using this option, flex defaults to generating the scanner to the file
  2400. .B lex.yy.cc
  2401. instead of
  2402. .B lex.yy.c.
  2403. The generated scanner includes the header file
  2404. .I FlexLexer.h,
  2405. which defines the interface to two C++ classes.
  2406. .PP
  2407. The first class,
  2408. .B FlexLexer,
  2409. provides an abstract base class defining the general scanner class
  2410. interface.  It provides the following member functions:
  2411. .TP
  2412. .B const char* YYText()
  2413. returns the text of the most recently matched token, the equivalent of
  2414. .B yytext.
  2415. .TP
  2416. .B int YYLeng()
  2417. returns the length of the most recently matched token, the equivalent of
  2418. .B yyleng.
  2419. .PP
  2420. Also provided are member functions equivalent to
  2421. .B yy_switch_to_buffer(),
  2422. .B yy_create_buffer()
  2423. (though the first argument is an
  2424. .B istream*
  2425. object pointer and not a
  2426. .B FILE*),
  2427. .B yy_delete_buffer(),
  2428. and
  2429. .B yyrestart()
  2430. (again, the first argument is a
  2431. .B istream*
  2432. object pointer).
  2433. .PP
  2434. The second class defined in
  2435. .I FlexLexer.h
  2436. is
  2437. .B yyFlexLexer,
  2438. which is derived from
  2439. .B FlexLexer.
  2440. It defines the following additional member functions:
  2441. .TP
  2442. .B
  2443. yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
  2444. constructs a
  2445. .B yyFlexLexer
  2446. object using the given streams for input and output.  If not specified,
  2447. the streams default to
  2448. .B cin
  2449. and
  2450. .B cout,
  2451. respectively.
  2452. .TP
  2453. .B virtual int yylex()
  2454. performs the same role is
  2455. .B yylex()
  2456. does for ordinary flex scanners: it scans the input stream, consuming
  2457. tokens, until a rule's action returns a value.
  2458. .PP
  2459. In addition,
  2460. .B yyFlexLexer
  2461. defines the following protected virtual functions which you can redefine
  2462. in derived classes to tailor the scanner:
  2463. .TP
  2464. .B
  2465. virtual int LexerInput( char* buf, int max_size )
  2466. reads up to
  2467. .B max_size
  2468. characters into
  2469. .B buf
  2470. and returns the number of characters read.  To indicate end-of-input,
  2471. return 0 characters.  Note that "interactive" scanners (see the
  2472. .B \-B
  2473. and
  2474. .B \-I
  2475. flags) define the macro
  2476. .B YY_INTERACTIVE.
  2477. If you redefine
  2478. .B LexerInput()
  2479. and need to take different actions depending on whether or not
  2480. the scanner might be scanning an interactive input source, you can
  2481. test for the presence of this name via
  2482. .B #ifdef.
  2483. .TP
  2484. .B
  2485. virtual void LexerOutput( const char* buf, int size )
  2486. writes out
  2487. .B size
  2488. characters from the buffer
  2489. .B buf,
  2490. which, while NUL-terminated, may also contain "internal" NUL's if
  2491. the scanner's rules can match text with NUL's in them.
  2492. .TP
  2493. .B
  2494. virtual void LexerError( const char* msg )
  2495. reports a fatal error message.  The default version of this function
  2496. writes the message to the stream
  2497. .B cerr
  2498. and exits.
  2499. .PP
  2500. Note that a
  2501. .B yyFlexLexer
  2502. object contains its
  2503. .I entire
  2504. scanning state.  Thus you can use such objects to create reentrant
  2505. scanners.  You can instantiate multiple instances of the same
  2506. .B yyFlexLexer
  2507. class, and you can also combine multiple C++ scanner classes together
  2508. in the same program using the
  2509. .B \-P
  2510. option discussed above.
  2511. .PP
  2512. Finally, note that the
  2513. .B %array
  2514. feature is not available to C++ scanner classes; you must use
  2515. .B %pointer
  2516. (the default).
  2517. .PP
  2518. Here is an example of a simple C++ scanner:
  2519. .nf
  2520.  
  2521.         // An example of using the flex C++ scanner class.
  2522.  
  2523.     %{
  2524.     int mylineno = 0;
  2525.     %}
  2526.  
  2527.     string  \\"[^\\n"]+\\"
  2528.  
  2529.     ws      [ \\t]+
  2530.  
  2531.     alpha   [A-Za-z]
  2532.     dig     [0-9]
  2533.     name    ({alpha}|{dig}|\\$)({alpha}|{dig}|[_.\\-/$])*
  2534.     num1    [-+]?{dig}+\\.?([eE][-+]?{dig}+)?
  2535.     num2    [-+]?{dig}*\\.{dig}+([eE][-+]?{dig}+)?
  2536.     number  {num1}|{num2}
  2537.  
  2538.     %%
  2539.  
  2540.     {ws}    /* skip blanks and tabs */
  2541.  
  2542.     "/*"    {
  2543.             int c;
  2544.  
  2545.             while((c = yyinput()) != 0)
  2546.                 {
  2547.                 if(c == '\\n')
  2548.                     ++mylineno;
  2549.  
  2550.                 else if(c == '*')
  2551.                     {
  2552.                     if((c = yyinput()) == '/')
  2553.                         break;
  2554.                     else
  2555.                         unput(c);
  2556.                     }
  2557.                 }
  2558.             }
  2559.  
  2560.     {number}  cout << "number " << YYText() << '\\n';
  2561.  
  2562.     \\n        mylineno++;
  2563.  
  2564.     {name}    cout << "name " << YYText() << '\\n';
  2565.  
  2566.     {string}  cout << "string " << YYText() << '\\n';
  2567.  
  2568.     %%
  2569.  
  2570.     int main( int /* argc */, char** /* argv */ )
  2571.         {
  2572.         FlexLexer* lexer = new yyFlexLexer;
  2573.         while(lexer->yylex() != 0)
  2574.             ;
  2575.         return 0;
  2576.         }
  2577. .fi
  2578. IMPORTANT: the present form of the scanning class is
  2579. .I experimental
  2580. and may change considerably between major releases.
  2581. .SH INCOMPATIBILITIES WITH LEX AND POSIX
  2582. .I flex
  2583. is a rewrite of the AT&T Unix
  2584. .I lex
  2585. tool (the two implementations do not share any code, though),
  2586. with some extensions and incompatibilities, both of which
  2587. are of concern to those who wish to write scanners acceptable
  2588. to either implementation.  The POSIX
  2589. .I lex
  2590. specification is closer to
  2591. .I flex's
  2592. behavior than that of the original
  2593. .I lex
  2594. implementation, but there also remain some incompatibilities between
  2595. .I flex
  2596. and POSIX.  The intent is that ultimately
  2597. .I flex
  2598. will be fully POSIX-conformant.  In this section we discuss all of
  2599. the known areas of incompatibility.
  2600. .PP
  2601. .I flex's
  2602. .B \-l
  2603. option turns on maximum compatibility with the original AT&T
  2604. .I lex
  2605. implementation, at the cost of a major loss in the generated scanner's
  2606. performance.  We note below which incompatibilities can be overcome
  2607. using the
  2608. .B \-l
  2609. option.
  2610. .PP
  2611. .I flex
  2612. is fully compatible with
  2613. .I lex
  2614. with the following exceptions:
  2615. .IP -
  2616. The undocumented
  2617. .I lex
  2618. scanner internal variable
  2619. .B yylineno
  2620. is not supported unless
  2621. .B \-l
  2622. is used.
  2623. .IP
  2624. yylineno is not part of the POSIX specification.
  2625. .IP -
  2626. The
  2627. .B input()
  2628. routine is not redefinable, though it may be called to read characters
  2629. following whatever has been matched by a rule.  If
  2630. .B input()
  2631. encounters an end-of-file the normal
  2632. .B yywrap()
  2633. processing is done.  A ``real'' end-of-file is returned by
  2634. .B input()
  2635. as
  2636. .I EOF.
  2637. .IP
  2638. Input is instead controlled by defining the
  2639. .B YY_INPUT
  2640. macro.
  2641. .IP
  2642. The
  2643. .I flex
  2644. restriction that
  2645. .B input()
  2646. cannot be redefined is in accordance with the POSIX specification,
  2647. which simply does not specify any way of controlling the
  2648. scanner's input other than by making an initial assignment to
  2649. .I yyin.
  2650. .IP -
  2651. .I flex
  2652. scanners are not as reentrant as
  2653. .I lex
  2654. scanners.  In particular, if you have an interactive scanner and
  2655. an interrupt handler which long-jumps out of the scanner, and
  2656. the scanner is subsequently called again, you may get the following
  2657. message:
  2658. .nf
  2659.  
  2660.     fatal flex scanner internal error--end of buffer missed
  2661.  
  2662. .fi
  2663. To reenter the scanner, first use
  2664. .nf
  2665.  
  2666.     yyrestart( yyin );
  2667.  
  2668. .fi
  2669. Note that this call will throw away any buffered input; usually this
  2670. isn't a problem with an interactive scanner.
  2671. .IP
  2672. Also note that flex C++ scanner classes
  2673. .I are
  2674. reentrant, so if using C++ is an option for you, you should use
  2675. them instead.  See "Generating C++ Scanners" above for details.
  2676. .IP -
  2677. .B output()
  2678. is not supported.
  2679. Output from the
  2680. .B ECHO
  2681. macro is done to the file-pointer
  2682. .I yyout
  2683. (default
  2684. .I stdout).
  2685. .IP
  2686. .B output()
  2687. is not part of the POSIX specification.
  2688. .IP -
  2689. .I lex
  2690. does not support exclusive start conditions (%x), though they
  2691. are in the POSIX specification.
  2692. .IP -
  2693. When definitions are expanded,
  2694. .I flex
  2695. encloses them in parentheses.
  2696. With lex, the following:
  2697. .nf
  2698.  
  2699.     NAME    [A-Z][A-Z0-9]*
  2700.     %%
  2701.     foo{NAME}?      printf( "Found it\\n" );
  2702.     %%
  2703.  
  2704. .fi
  2705. will not match the string "foo" because when the macro
  2706. is expanded the rule is equivalent to "foo[A-Z][A-Z0-9]*?"
  2707. and the precedence is such that the '?' is associated with
  2708. "[A-Z0-9]*".  With
  2709. .I flex,
  2710. the rule will be expanded to
  2711. "foo([A-Z][A-Z0-9]*)?" and so the string "foo" will match.
  2712. .IP
  2713. Note that if the definition begins with
  2714. .B ^
  2715. or ends with
  2716. .B $
  2717. then it is
  2718. .I not
  2719. expanded with parentheses, to allow these operators to appear in
  2720. definitions without losing their special meanings.  But the
  2721. .B <s>, /,
  2722. and
  2723. .B <<EOF>>
  2724. operators cannot be used in a
  2725. .I flex
  2726. definition.
  2727. .IP
  2728. Using
  2729. .B \-l
  2730. results in the
  2731. .I lex
  2732. behavior of no parentheses around the definition.
  2733. .IP
  2734. The POSIX specification is that the definition be enclosed in parentheses.
  2735. .IP -
  2736. The
  2737. .I lex
  2738. .B %r
  2739. (generate a Ratfor scanner) option is not supported.  It is not part
  2740. of the POSIX specification.
  2741. .IP -
  2742. After a call to
  2743. .B unput(),
  2744. .I yytext
  2745. and
  2746. .I yyleng
  2747. are undefined until the next token is matched, unless the scanner
  2748. was built using
  2749. .B %array.
  2750. This is not the case with
  2751. .I lex
  2752. or the POSIX specification.  The
  2753. .B \-l
  2754. option does away with this incompatibility.
  2755. .IP -
  2756. The precedence of the
  2757. .B {}
  2758. (numeric range) operator is different.
  2759. .I lex
  2760. interprets "abc{1,3}" as "match one, two, or
  2761. three occurrences of 'abc'", whereas
  2762. .I flex
  2763. interprets it as "match 'ab'
  2764. followed by one, two, or three occurrences of 'c'".  The latter is
  2765. in agreement with the POSIX specification.
  2766. .IP -
  2767. The precedence of the
  2768. .B ^
  2769. operator is different.
  2770. .I lex
  2771. interprets "^foo|bar" as "match either 'foo' at the beginning of a line,
  2772. or 'bar' anywhere", whereas
  2773. .I flex
  2774. interprets it as "match either 'foo' or 'bar' if they come at the beginning
  2775. of a line".  The latter is in agreement with the POSIX specification.
  2776. .IP -
  2777. .I yyin
  2778. is
  2779. .I initialized
  2780. by
  2781. .I lex
  2782. to be
  2783. .I stdin;
  2784. .I flex,
  2785. on the other hand,
  2786. initializes
  2787. .I yyin
  2788. to NULL
  2789. and then
  2790. .I assigns
  2791. it to
  2792. .I stdin
  2793. the first time the scanner is called, providing
  2794. .I yyin
  2795. has not already been assigned to a non-NULL value.  The difference is
  2796. subtle, but the net effect is that with
  2797. .I flex
  2798. scanners,
  2799. .I yyin
  2800. does not have a valid value until the scanner has been called.
  2801. .IP
  2802. The
  2803. .B \-l
  2804. option does away with this incompatibility.
  2805. .IP -
  2806. The special table-size declarations such as
  2807. .B %a
  2808. supported by
  2809. .I lex
  2810. are not required by
  2811. .I flex
  2812. scanners;
  2813. .I flex
  2814. ignores them.
  2815. .IP -
  2816. The name
  2817. .bd
  2818. FLEX_SCANNER
  2819. is #define'd so scanners may be written for use with either
  2820. .I flex
  2821. or
  2822. .I lex.
  2823. .PP
  2824. The following
  2825. .I flex
  2826. features are not included in
  2827. .I lex
  2828. or the POSIX specification:
  2829. .nf
  2830.  
  2831.     yyterminate()
  2832.     <<EOF>>
  2833.     <*>
  2834.     YY_DECL
  2835.     YY_START
  2836.     YY_USER_ACTION
  2837.     #line directives
  2838.     %{}'s around actions
  2839.     multiple actions on a line
  2840.  
  2841. .fi
  2842. plus almost all of the flex flags.
  2843. The last feature in the list refers to the fact that with
  2844. .I flex
  2845. you can put multiple actions on the same line, separated with
  2846. semi-colons, while with
  2847. .I lex,
  2848. the following
  2849. .nf
  2850.  
  2851.     foo    handle_foo(); ++num_foos_seen;
  2852.  
  2853. .fi
  2854. is (rather surprisingly) truncated to
  2855. .nf
  2856.  
  2857.     foo    handle_foo();
  2858.  
  2859. .fi
  2860. .I flex
  2861. does not truncate the action.  Actions that are not enclosed in
  2862. braces are simply terminated at the end of the line.
  2863. .SH DIAGNOSTICS
  2864. .PP
  2865. .I warning, rule cannot be matched
  2866. indicates that the given rule
  2867. cannot be matched because it follows other rules that will
  2868. always match the same text as it.  For
  2869. example, in the following "foo" cannot be matched because it comes after
  2870. an identifier "catch-all" rule:
  2871. .nf
  2872.  
  2873.     [a-z]+    got_identifier();
  2874.     foo       got_foo();
  2875.  
  2876. .fi
  2877. Using
  2878. .B REJECT
  2879. in a scanner suppresses this warning.
  2880. .PP
  2881. .I warning,
  2882. .B \-s
  2883. .I
  2884. option given but default rule can be matched
  2885. means that it is possible (perhaps only in a particular start condition)
  2886. that the default rule (match any single character) is the only one
  2887. that will match a particular input.  Since
  2888. .B \-s
  2889. was given, presumably this is not intended.
  2890. .PP
  2891. .I reject_used_but_not_detected undefined
  2892. or
  2893. .I yymore_used_but_not_detected undefined -
  2894. These errors can occur at compile time.  They indicate that the
  2895. scanner uses
  2896. .B REJECT
  2897. or
  2898. .B yymore()
  2899. but that
  2900. .I flex
  2901. failed to notice the fact, meaning that
  2902. .I flex
  2903. scanned the first two sections looking for occurrences of these actions
  2904. and failed to find any, but somehow you snuck some in (via a #include
  2905. file, for example).  Make an explicit reference to the action in your
  2906. .I flex
  2907. input file.  (Note that previously
  2908. .I flex
  2909. supported a
  2910. .B %used/%unused
  2911. mechanism for dealing with this problem; this feature is still supported
  2912. but now deprecated, and will go away soon unless the author hears from
  2913. people who can argue compellingly that they need it.)
  2914. .PP
  2915. .I flex scanner jammed -
  2916. a scanner compiled with
  2917. .B \-s
  2918. has encountered an input string which wasn't matched by
  2919. any of its rules.  This error can also occur due to internal problems.
  2920. .PP
  2921. .I token too large, exceeds YYLMAX -
  2922. your scanner uses
  2923. .B %array
  2924. and one of its rules matched a string longer than the
  2925. .B YYLMAX
  2926. constant (8K bytes by default).  You can increase the value by
  2927. #define'ing
  2928. .B YYLMAX
  2929. in the definitions section of your
  2930. .I flex
  2931. input.
  2932. .PP
  2933. .I scanner requires \-8 flag to
  2934. .I use the character 'x' -
  2935. Your scanner specification includes recognizing the 8-bit character
  2936. .I 'x'
  2937. and you did not specify the \-8 flag, and your scanner defaulted to 7-bit
  2938. because you used the
  2939. .B \-Cf
  2940. or
  2941. .B \-CF
  2942. table compression options.  See the discussion of the
  2943. .B \-7
  2944. flag for details.
  2945. .PP
  2946. .I flex scanner push-back overflow -
  2947. you used
  2948. .B unput()
  2949. to push back so much text that the scanner's buffer could not hold
  2950. both the pushed-back text and the current token in
  2951. .B yytext.
  2952. Ideally the scanner should dynamically resize the buffer in this case, but at
  2953. present it does not.
  2954. .PP
  2955. .I
  2956. input buffer overflow, can't enlarge buffer because scanner uses REJECT -
  2957. the scanner was working on matching an extremely large token and needed
  2958. to expand the input buffer.  This doesn't work with scanners that use
  2959. .B
  2960. REJECT.
  2961. .PP
  2962. .I
  2963. fatal flex scanner internal error--end of buffer missed -
  2964. This can occur in an scanner which is reentered after a long-jump
  2965. has jumped out (or over) the scanner's activation frame.  Before
  2966. reentering the scanner, use:
  2967. .nf
  2968.  
  2969.     yyrestart( yyin );
  2970.  
  2971. .fi
  2972. or, as noted above, switch to using the C++ scanner class.
  2973. .PP
  2974. .I too many start conditions in <> construct! -
  2975. you listed more start conditions in a <> construct than exist (so
  2976. you must have listed at least one of them twice).
  2977. .SH FILES
  2978. See flex(1).
  2979. .SH DEFICIENCIES / BUGS
  2980. Again, see flex(1).
  2981. .SH "SEE ALSO"
  2982. .PP
  2983. flex(1), lex(1), yacc(1), sed(1), awk(1).
  2984. .PP
  2985. M. E. Lesk and E. Schmidt,
  2986. .I LEX \- Lexical Analyzer Generator
  2987. .SH AUTHOR
  2988. Vern Paxson, with the help of many ideas and much inspiration from
  2989. Van Jacobson.  Original version by Jef Poskanzer.  The fast table
  2990. representation is a partial implementation of a design done by Van
  2991. Jacobson.  The implementation was done by Kevin Gong and Vern Paxson.
  2992. .PP
  2993. Thanks to the many
  2994. .I flex
  2995. beta-testers, feedbackers, and contributors, especially Francois Pinard,
  2996. Casey Leedom,
  2997. Nelson H.F. Beebe, benson@odi.com, Peter A. Bigot, Keith Bostic, Frederic
  2998. Brehm, Nick Christopher, Jason Coughlin, Bill Cox, Dave Curtis, Scott David
  2999. Daniels, Chris G. Demetriou, Mike Donahue, Chuck Doucette, Tom Epperly, Leo
  3000. Eskin, Chris Faylor, Jon Forrest, Kaveh R. Ghazi,
  3001. Eric Goldman, Ulrich Grepel, Jan Hajic,
  3002. Jarkko Hietaniemi, Eric Hughes, John Interrante,
  3003. Ceriel Jacobs, Jeffrey R. Jones, Henry
  3004. Juengst, Amir Katz, ken@ken.hilco.com, Kevin B. Kenny, Marq Kole, Ronald
  3005. Lamprecht, Greg Lee, Craig Leres, John Levine, Steve Liddle,
  3006. Mohamed el Lozy, Brian Madsen, Chris
  3007. Metcalf, Luke Mewburn, Jim Meyering, G.T. Nicol, Landon Noll, Marc Nozell,
  3008. Richard Ohnemus, Sven Panne, Roland Pesch, Walter Pelissero, Gaumond
  3009. Pierre, Esmond Pitt, Jef Poskanzer, Joe Rahmeh, Frederic Raimbault,
  3010. Rick Richardson,
  3011. Kevin Rodgers, Jim Roskind,
  3012. Doug Schmidt, Philippe Schnoebelen, Andreas Schwab,
  3013. Alex Siegel, Mike Stump, Paul Stuart, Dave Tallman, Chris Thewalt,
  3014. Paul Tuinenga, Gary Weik, Frank Whaley, Gerhard Wilhelms, Kent Williams, Ken
  3015. Yap, Nathan Zelle, David Zuhn, and those whose names have slipped my marginal
  3016. mail-archiving skills but whose contributions are appreciated all the
  3017. same.
  3018. .PP
  3019. Thanks to Keith Bostic, Jon Forrest, Noah Friedman,
  3020. John Gilmore, Craig Leres, John Levine, Bob Mulcahy, G.T.
  3021. Nicol, Francois Pinard, Rich Salz, and Richard Stallman for help with various
  3022. distribution headaches.
  3023. .PP
  3024. Thanks to Esmond Pitt and Earle Horton for 8-bit character support; to
  3025. Benson Margulies and Fred Burke for C++ support; to Kent Williams and Tom
  3026. Epperly for C++ class support; to Ove Ewerlid for support of NUL's; and to
  3027. Eric Hughes for support of multiple buffers.
  3028. .PP
  3029. This work was primarily done when I was with the Real Time Systems Group
  3030. at the Lawrence Berkeley Laboratory in Berkeley, CA.  Many thanks to all there
  3031. for the support I received.
  3032. .PP
  3033. Send comments to:
  3034. .nf
  3035.  
  3036.      Vern Paxson
  3037.      Systems Engineering
  3038.      Bldg. 46A, Room 1123
  3039.      Lawrence Berkeley Laboratory
  3040.      University of California
  3041.      Berkeley, CA 94720
  3042.  
  3043.      vern@ee.lbl.gov
  3044.  
  3045. .fi
  3046.