home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / c / Flex254.lha / Docs / flex.info < prev    next >
Encoding:
GNU Info File  |  1996-11-12  |  109.3 KB  |  2,951 lines

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