home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / docs / flex < prev    next >
Encoding:
GNU Info File  |  2004-09-05  |  327.3 KB  |  8,356 lines

  1. This is /home/riscos/gcc33/!gcc/docs/flex, produced by makeinfo version
  2. 4.7 from doc/flex.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * flex: (flex).      Fast lexical analyzer generator (lex replacement).
  7. END-INFO-DIR-ENTRY
  8.  
  9.    The flex manual is placed under the same licensing conditions as the
  10. rest of flex:
  11.  
  12.    Copyright (C) 1990, 1997 The Regents of the University of California.
  13. All rights reserved.
  14.  
  15.    This code is derived from software contributed to Berkeley by Vern
  16. Paxson.
  17.  
  18.    The United States Government has rights in this work pursuant to
  19. contract no. DE-AC03-76SF00098 between the United States Department of
  20. Energy and the University of California.
  21.  
  22.    Redistribution and use in source and binary forms, with or without
  23. modification, are permitted provided that the following conditions are
  24. met:
  25.  
  26.   1.  Redistributions of source code must retain the above copyright
  27.      notice, this list of conditions and the following disclaimer.
  28.  
  29.   2. Redistributions in binary form must reproduce the above copyright
  30.      notice, this list of conditions and the following disclaimer in the
  31.      documentation and/or other materials provided with the
  32.      distribution.
  33.  
  34.    Neither the name of the University nor the names of its contributors
  35. may be used to endorse or promote products derived from this software
  36. without specific prior written permission.
  37.  
  38.    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  39. WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  40. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  41.  
  42. 
  43. File: flex,  Node: Top,  Next: Copyright,  Prev: (dir),  Up: (dir)
  44.  
  45. flex
  46. ****
  47.  
  48. This manual describes `flex', a tool for generating programs that
  49. perform pattern-matching on text.  The manual includes both tutorial and
  50. reference sections.
  51.  
  52.    This edition of `The flex Manual' documents `flex' version 2.5.31.
  53. It was last updated on 27 March 2003.
  54.  
  55. * Menu:
  56.  
  57. * Copyright::
  58. * Reporting Bugs::
  59. * Introduction::
  60. * Simple Examples::
  61. * Format::
  62. * Patterns::
  63. * Matching::
  64. * Actions::
  65. * Generated Scanner::
  66. * Start Conditions::
  67. * Multiple Input Buffers::
  68. * EOF::
  69. * Misc Macros::
  70. * User Values::
  71. * Yacc::
  72. * Scanner Options::
  73. * Performance::
  74. * Cxx::
  75. * Reentrant::
  76. * Lex and Posix::
  77. * Memory Management::
  78. * Serialized Tables::
  79. * Diagnostics::
  80. * Limitations::
  81. * Bibliography::
  82. * FAQ::
  83. * Appendices::
  84. * Indices::
  85.  
  86.  --- The Detailed Node Listing ---
  87.  
  88. Format of the Input File
  89.  
  90. * Definitions Section::
  91. * Rules Section::
  92. * User Code Section::
  93. * Comments in the Input::
  94.  
  95. Scanner Options
  96.  
  97. * Options for Specifing Filenames::
  98. * Options Affecting Scanner Behavior::
  99. * Code-Level And API Options::
  100. * Options for Scanner Speed and Size::
  101. * Debugging Options::
  102. * Miscellaneous Options::
  103.  
  104. Reentrant C Scanners
  105.  
  106. * Reentrant Uses::
  107. * Reentrant Overview::
  108. * Reentrant Example::
  109. * Reentrant Detail::
  110. * Reentrant Functions::
  111.  
  112. The Reentrant API in Detail
  113.  
  114. * Specify Reentrant::
  115. * Extra Reentrant Argument::
  116. * Global Replacement::
  117. * Init and Destroy Functions::
  118. * Accessor Methods::
  119. * Extra Data::
  120. * About yyscan_t::
  121.  
  122. Memory Management
  123.  
  124. * The Default Memory Management::
  125. * Overriding The Default Memory Management::
  126. * A Note About yytext And Memory::
  127.  
  128. Serialized Tables
  129.  
  130. * Creating Serialized Tables::
  131. * Loading and Unloading Serialized Tables::
  132. * Tables File Format::
  133.  
  134. FAQ
  135.  
  136. * When was flex born?::
  137. * How do I expand \ escape sequences in C-style quoted strings?::
  138. * Why do flex scanners call fileno if it is not ANSI compatible?::
  139. * Does flex support recursive pattern definitions?::
  140. * How do I skip huge chunks of input (tens of megabytes) while using flex?::
  141. * Flex is not matching my patterns in the same order that I defined them.::
  142. * My actions are executing out of order or sometimes not at all.::
  143. * How can I have multiple input sources feed into the same scanner at the same time?::
  144. * Can I build nested parsers that work with the same input file?::
  145. * How can I match text only at the end of a file?::
  146. * How can I make REJECT cascade across start condition boundaries?::
  147. * Why cant I use fast or full tables with interactive mode?::
  148. * How much faster is -F or -f than -C?::
  149. * If I have a simple grammar cant I just parse it with flex?::
  150. * Why doesnt yyrestart() set the start state back to INITIAL?::
  151. * How can I match C-style comments?::
  152. * The period isnt working the way I expected.::
  153. * Can I get the flex manual in another format?::
  154. * Does there exist a "faster" NDFA->DFA algorithm?::
  155. * How does flex compile the DFA so quickly?::
  156. * How can I use more than 8192 rules?::
  157. * How do I abandon a file in the middle of a scan and switch to a new file?::
  158. * How do I execute code only during initialization (only before the first scan)?::
  159. * How do I execute code at termination?::
  160. * Where else can I find help?::
  161. * Can I include comments in the "rules" section of the file?::
  162. * I get an error about undefined yywrap().::
  163. * How can I change the matching pattern at run time?::
  164. * How can I expand macros in the input?::
  165. * How can I build a two-pass scanner?::
  166. * How do I match any string not matched in the preceding rules?::
  167. * I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
  168. * Is there a way to make flex treat NULL like a regular character?::
  169. * Whenever flex can not match the input it says "flex scanner jammed".::
  170. * Why doesnt flex have non-greedy operators like perl does?::
  171. * Memory leak - 16386 bytes allocated by malloc.::
  172. * How do I track the byte offset for lseek()?::
  173. * How do I use my own I/O classes in a C++ scanner?::
  174. * How do I skip as many chars as possible?::
  175. * deleteme00::
  176. * Are certain equivalent patterns faster than others?::
  177. * Is backing up a big deal?::
  178. * Can I fake multi-byte character support?::
  179. * deleteme01::
  180. * Can you discuss some flex internals?::
  181. * unput() messes up yy_at_bol::
  182. * The | operator is not doing what I want::
  183. * Why can't flex understand this variable trailing context pattern?::
  184. * The ^ operator isn't working::
  185. * Trailing context is getting confused with trailing optional patterns::
  186. * Is flex GNU or not?::
  187. * ERASEME53::
  188. * I need to scan if-then-else blocks and while loops::
  189. * ERASEME55::
  190. * ERASEME56::
  191. * ERASEME57::
  192. * Is there a repository for flex scanners?::
  193. * How can I conditionally compile or preprocess my flex input file?::
  194. * Where can I find grammars for lex and yacc?::
  195. * I get an end-of-buffer message for each character scanned.::
  196. * unnamed-faq-62::
  197. * unnamed-faq-63::
  198. * unnamed-faq-64::
  199. * unnamed-faq-65::
  200. * unnamed-faq-66::
  201. * unnamed-faq-67::
  202. * unnamed-faq-68::
  203. * unnamed-faq-69::
  204. * unnamed-faq-70::
  205. * unnamed-faq-71::
  206. * unnamed-faq-72::
  207. * unnamed-faq-73::
  208. * unnamed-faq-74::
  209. * unnamed-faq-75::
  210. * unnamed-faq-76::
  211. * unnamed-faq-77::
  212. * unnamed-faq-78::
  213. * unnamed-faq-79::
  214. * unnamed-faq-80::
  215. * unnamed-faq-81::
  216. * unnamed-faq-82::
  217. * unnamed-faq-83::
  218. * unnamed-faq-84::
  219. * unnamed-faq-85::
  220. * unnamed-faq-86::
  221. * unnamed-faq-87::
  222. * unnamed-faq-88::
  223. * unnamed-faq-90::
  224. * unnamed-faq-91::
  225. * unnamed-faq-92::
  226. * unnamed-faq-93::
  227. * unnamed-faq-94::
  228. * unnamed-faq-95::
  229. * unnamed-faq-96::
  230. * unnamed-faq-97::
  231. * unnamed-faq-98::
  232. * unnamed-faq-99::
  233. * unnamed-faq-100::
  234. * unnamed-faq-101::
  235.  
  236. Appendices
  237.  
  238. * Makefiles and Flex::
  239. * Bison Bridge::
  240. * M4 Dependency::
  241.  
  242. Indices
  243.  
  244. * Concept Index::
  245. * Index of Functions and Macros::
  246. * Index of Variables::
  247. * Index of Data Types::
  248. * Index of Hooks::
  249. * Index of Scanner Options::
  250.  
  251. 
  252. File: flex,  Node: Copyright,  Next: Reporting Bugs,  Prev: Top,  Up: Top
  253.  
  254. 1 Copyright
  255. ***********
  256.  
  257. The flex manual is placed under the same licensing conditions as the
  258. rest of flex:
  259.  
  260.    Copyright (C) 1990, 1997 The Regents of the University of California.
  261. All rights reserved.
  262.  
  263.    This code is derived from software contributed to Berkeley by Vern
  264. Paxson.
  265.  
  266.    The United States Government has rights in this work pursuant to
  267. contract no. DE-AC03-76SF00098 between the United States Department of
  268. Energy and the University of California.
  269.  
  270.    Redistribution and use in source and binary forms, with or without
  271. modification, are permitted provided that the following conditions are
  272. met:
  273.  
  274.   1.  Redistributions of source code must retain the above copyright
  275.      notice, this list of conditions and the following disclaimer.
  276.  
  277.   2. Redistributions in binary form must reproduce the above copyright
  278.      notice, this list of conditions and the following disclaimer in the
  279.      documentation and/or other materials provided with the
  280.      distribution.
  281.  
  282.    Neither the name of the University nor the names of its contributors
  283. may be used to endorse or promote products derived from this software
  284. without specific prior written permission.
  285.  
  286.    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  287. WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  288. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  289.  
  290. 
  291. File: flex,  Node: Reporting Bugs,  Next: Introduction,  Prev: Copyright,  Up: Top
  292.  
  293. 2 Reporting Bugs
  294. ****************
  295.  
  296. If you have problems with `flex' or think you have found a bug, please
  297. send mail detailing your problem to <lex-help@lists.sourceforge.net>.
  298. Patches are always welcome.
  299.  
  300. 
  301. File: flex,  Node: Introduction,  Next: Simple Examples,  Prev: Reporting Bugs,  Up: Top
  302.  
  303. 3 Introduction
  304. **************
  305.  
  306. `flex' is a tool for generating "scanners".  A scanner is a program
  307. which recognizes lexical patterns in text.  The `flex' program reads
  308. the given input files, or its standard input if no file names are
  309. given, for a description of a scanner to generate.  The description is
  310. in the form of pairs of regular expressions and C code, called "rules".
  311. `flex' generates as output a C source file, `lex.yy.c' by default,
  312. which defines a routine `yylex()'.  This file can be compiled and
  313. linked with the flex runtime library to produce an executable.  When
  314. the executable is run, it analyzes its input for occurrences of the
  315. regular expressions.  Whenever it finds one, it executes the
  316. corresponding C code.
  317.  
  318. 
  319. File: flex,  Node: Simple Examples,  Next: Format,  Prev: Introduction,  Up: Top
  320.  
  321. 4 Some Simple Examples
  322. **********************
  323.  
  324. First some simple examples to get the flavor of how one uses `flex'.
  325.  
  326.    The following `flex' input specifies a scanner which, when it
  327. encounters the string `username' will replace it with the user's login
  328. name:
  329.  
  330.  
  331.          %%
  332.          username    printf( "%s", getlogin() );
  333.  
  334.    By default, any text not matched by a `flex' scanner is copied to
  335. the output, so the net effect of this scanner is to copy its input file
  336. to its output with each occurrence of `username' expanded.  In this
  337. input, there is just one rule.  `username' is the "pattern" and the
  338. `printf' is the "action".  The `%%' symbol marks the beginning of the
  339. rules.
  340.  
  341.    Here's another simple example:
  342.  
  343.  
  344.                  int num_lines = 0, num_chars = 0;
  345.  
  346.          %%
  347.          \n      ++num_lines; ++num_chars;
  348.          .       ++num_chars;
  349.  
  350.          %%
  351.          main()
  352.                  {
  353.                  yylex();
  354.                  printf( "# of lines = %d, # of chars = %d\n",
  355.                          num_lines, num_chars );
  356.                  }
  357.  
  358.    This scanner counts the number of characters and the number of lines
  359. in its input. It produces no output other than the final report on the
  360. character and line counts.  The first line declares two globals,
  361. `num_lines' and `num_chars', which are accessible both inside `yylex()'
  362. and in the `main()' routine declared after the second `%%'.  There are
  363. two rules, one which matches a newline (`\n') and increments both the
  364. line count and the character count, and one which matches any character
  365. other than a newline (indicated by the `.' regular expression).
  366.  
  367.    A somewhat more complicated example:
  368.  
  369.  
  370.          /* scanner for a toy Pascal-like language */
  371.  
  372.          %{
  373.          /* need this for the call to atof() below */
  374.          #include math.h>
  375.          %}
  376.  
  377.          DIGIT    [0-9]
  378.          ID       [a-z][a-z0-9]*
  379.  
  380.          %%
  381.  
  382.          {DIGIT}+    {
  383.                      printf( "An integer: %s (%d)\n", yytext,
  384.                              atoi( yytext ) );
  385.                      }
  386.  
  387.          {DIGIT}+"."{DIGIT}*        {
  388.                      printf( "A float: %s (%g)\n", yytext,
  389.                              atof( yytext ) );
  390.                      }
  391.  
  392.          if|then|begin|end|procedure|function        {
  393.                      printf( "A keyword: %s\n", yytext );
  394.                      }
  395.  
  396.          {ID}        printf( "An identifier: %s\n", yytext );
  397.  
  398.          "+"|"-"|"*"|"/"   printf( "An operator: %s\n", yytext );
  399.  
  400.          "{"[\^{}}\n]*"}"     /* eat up one-line comments */
  401.  
  402.          [ \t\n]+          /* eat up whitespace */
  403.  
  404.          .           printf( "Unrecognized character: %s\n", yytext );
  405.  
  406.          %%
  407.  
  408.          main( argc, argv )
  409.          int argc;
  410.          char **argv;
  411.              {
  412.              ++argv, --argc;  /* skip over program name */
  413.              if ( argc > 0 )
  414.                      yyin = fopen( argv[0], "r" );
  415.              else
  416.                      yyin = stdin;
  417.  
  418.              yylex();
  419.              }
  420.  
  421.    This is the beginnings of a simple scanner for a language like
  422. Pascal.  It identifies different types of "tokens" and reports on what
  423. it has seen.
  424.  
  425.    The details of this example will be explained in the following
  426. sections.
  427.  
  428. 
  429. File: flex,  Node: Format,  Next: Patterns,  Prev: Simple Examples,  Up: Top
  430.  
  431. 5 Format of the Input File
  432. **************************
  433.  
  434. The `flex' input file consists of three sections, separated by a line
  435. containing only `%%'.
  436.  
  437.  
  438.          definitions
  439.          %%
  440.          rules
  441.          %%
  442.          user code
  443.  
  444. * Menu:
  445.  
  446. * Definitions Section::
  447. * Rules Section::
  448. * User Code Section::
  449. * Comments in the Input::
  450.  
  451. 
  452. File: flex,  Node: Definitions Section,  Next: Rules Section,  Prev: Format,  Up: Format
  453.  
  454. 5.1 Format of the Definitions Section
  455. =====================================
  456.  
  457. The "definitions section" contains declarations of simple "name"
  458. definitions to simplify the scanner specification, and declarations of
  459. "start conditions", which are explained in a later section.
  460.  
  461.    Name definitions have the form:
  462.  
  463.  
  464.          name definition
  465.  
  466.    The `name' is a word beginning with a letter or an underscore (`_')
  467. followed by zero or more letters, digits, `_', or `-' (dash).  The
  468. definition is taken to begin at the first non-whitespace character
  469. following the name and continuing to the end of the line.  The
  470. definition can subsequently be referred to using `{name}', which will
  471. expand to `(definition)'.  For example,
  472.  
  473.  
  474.          DIGIT    [0-9]
  475.          ID       [a-z][a-z0-9]*
  476.  
  477.    Defines `DIGIT' to be a regular expression which matches a single
  478. digit, and `ID' to be a regular expression which matches a letter
  479. followed by zero-or-more letters-or-digits.  A subsequent reference to
  480.  
  481.  
  482.          {DIGIT}+"."{DIGIT}*
  483.  
  484.    is identical to
  485.  
  486.  
  487.          ([0-9])+"."([0-9])*
  488.  
  489.    and matches one-or-more digits followed by a `.' followed by
  490. zero-or-more digits.
  491.  
  492.    An unindented comment (i.e., a line beginning with `/*') is copied
  493. verbatim to the output up to the next `*/'.
  494.  
  495.    Any _indented_ text or text enclosed in `%{' and `%}' is also copied
  496. verbatim to the output (with the %{ and %} symbols removed).  The %{
  497. and %} symbols must appear unindented on lines by themselves.
  498.  
  499.    A `%top' block is similar to a `%{' ... `%}' block, except that the
  500. code in a `%top' block is relocated to the _top_ of the generated file,
  501. before any flex definitions (1).  The `%top' block is useful when you
  502. want certain preprocessor macros to be defined or certain files to be
  503. included before the generated code.  The single characters, `{'  and
  504. `}' are used to delimit the `%top' block, as show in the example below:
  505.  
  506.  
  507.          %top{
  508.              /* This code goes at the "top" of the generated file. */
  509.              #include <stdint.h>
  510.              #include <inttypes.h>
  511.          }
  512.  
  513.    Multiple `%top' blocks are allowed, and their order is preserved.
  514.  
  515.    ---------- Footnotes ----------
  516.  
  517.    (1) Actually, `yyIN_HEADER' is defined before the `%top' block.
  518.  
  519. 
  520. File: flex,  Node: Rules Section,  Next: User Code Section,  Prev: Definitions Section,  Up: Format
  521.  
  522. 5.2 Format of the Rules Section
  523. ===============================
  524.  
  525. The "rules" section of the `flex' input contains a series of rules of
  526. the form:
  527.  
  528.  
  529.          pattern   action
  530.  
  531.    where the pattern must be unindented and the action must begin on
  532. the same line.  *Note Patterns::, for a further description of patterns
  533. and actions.
  534.  
  535.    In the rules section, any indented or %{ %} enclosed text appearing
  536. before the first rule may be used to declare variables which are local
  537. to the scanning routine and (after the declarations) code which is to be
  538. executed whenever the scanning routine is entered.  Other indented or
  539. %{ %} text in the rule section is still copied to the output, but its
  540. meaning is not well-defined and it may well cause compile-time errors
  541. (this feature is present for POSIX compliance. *Note Lex and Posix::,
  542. for other such features).
  543.  
  544.    Any _indented_ text or text enclosed in `%{' and `%}' is copied
  545. verbatim to the output (with the %{ and %} symbols removed).  The %{
  546. and %} symbols must appear unindented on lines by themselves.
  547.  
  548. 
  549. File: flex,  Node: User Code Section,  Next: Comments in the Input,  Prev: Rules Section,  Up: Format
  550.  
  551. 5.3 Format of the User Code Section
  552. ===================================
  553.  
  554. The user code section is simply copied to `lex.yy.c' verbatim.  It is
  555. used for companion routines which call or are called by the scanner.
  556. The presence of this section is optional; if it is missing, the second
  557. `%%' in the input file may be skipped, too.
  558.  
  559. 
  560. File: flex,  Node: Comments in the Input,  Prev: User Code Section,  Up: Format
  561.  
  562. 5.4 Comments in the Input
  563. =========================
  564.  
  565. Flex supports C-style comments, that is, anything between /* and */ is
  566. considered a comment. Whenever flex encounters a comment, it copies the
  567. entire comment verbatim to the generated source code. Comments may
  568. appear just about anywhere, but with the following exceptions:
  569.  
  570.    * Comments may not appear in the Rules Section wherever flex is
  571.      expecting a regular expression. This means comments may not appear
  572.      at the beginning of a line, or immediately following a list of
  573.      scanner states.
  574.  
  575.    * Comments may not appear on an `%option' line in the Definitions
  576.      Section.
  577.  
  578.    If you want to follow a simple rule, then always begin a comment on a
  579. new line, with one or more whitespace characters before the initial
  580. `/*').  This rule will work anywhere in the input file.
  581.  
  582.    All the comments in the following example are valid:
  583.  
  584.  
  585.      %{
  586.      /* code block */
  587.      %}
  588.  
  589.      /* Definitions Section */
  590.      %x STATE_X
  591.  
  592.      %%
  593.          /* Rules Section */
  594.      ruleA   /* after regex */ { /* code block */ } /* after code block */
  595.              /* Rules Section (indented) */
  596.      <STATE_X>{
  597.      ruleC   ECHO;
  598.      ruleD   ECHO;
  599.      %{
  600.      /* code block */
  601.      %}
  602.      }
  603.      %%
  604.      /* User Code Section */
  605.  
  606. 
  607. File: flex,  Node: Patterns,  Next: Matching,  Prev: Format,  Up: Top
  608.  
  609. 6 Patterns
  610. **********
  611.  
  612. The patterns in the input (see *Note Rules Section::) are written using
  613. an extended set of regular expressions.  These are:
  614.  
  615. `x'
  616.      match the character 'x'
  617.  
  618. `.'
  619.      any character (byte) except newline
  620.  
  621. `[xyz]'
  622.      a "character class"; in this case, the pattern matches either an
  623.      'x', a 'y', or a 'z'
  624.  
  625. `[abj-oZ]'
  626.      a "character class" with a range in it; matches an 'a', a 'b', any
  627.      letter from 'j' through 'o', or a 'Z'
  628.  
  629. `[^A-Z]'
  630.      a "negated character class", i.e., any character but those in the
  631.      class.  In this case, any character EXCEPT an uppercase letter.
  632.  
  633. `[^A-Z\n]'
  634.      any character EXCEPT an uppercase letter or a newline
  635.  
  636. `r*'
  637.      zero or more r's, where r is any regular expression
  638.  
  639. `r+'
  640.      one or more r's
  641.  
  642. `r?'
  643.      zero or one r's (that is, "an optional r")
  644.  
  645. `r{2,5}'
  646.      anywhere from two to five r's
  647.  
  648. `r{2,}'
  649.      two or more r's
  650.  
  651. `r{4}'
  652.      exactly 4 r's
  653.  
  654. `{name}'
  655.      the expansion of the `name' definition (*note Format::).
  656.  
  657. `"[xyz]\"foo"'
  658.      the literal string: `[xyz]"foo'
  659.  
  660. `\X'
  661.      if X is `a', `b', `f', `n', `r', `t', or `v', then the ANSI-C
  662.      interpretation of `\x'.  Otherwise, a literal `X' (used to escape
  663.      operators such as `*')
  664.  
  665. `\0'
  666.      a NUL character (ASCII code 0)
  667.  
  668. `\123'
  669.      the character with octal value 123
  670.  
  671. `\x2a'
  672.      the character with hexadecimal value 2a
  673.  
  674. `(r)'
  675.      match an `r'; parentheses are used to override precedence (see
  676.      below)
  677.  
  678. `rs'
  679.      the regular expression `r' followed by the regular expression `s';
  680.      called "concatenation"
  681.  
  682. `r|s'
  683.      either an `r' or an `s'
  684.  
  685. `r/s'
  686.      an `r' but only if it is followed by an `s'.  The text matched by
  687.      `s' is included when determining whether this rule is the longest
  688.      match, but is then returned to the input before the action is
  689.      executed.  So the action only sees the text matched by `r'.  This
  690.      type of pattern is called "trailing context".  (There are some
  691.      combinations of `r/s' that flex cannot match correctly. *Note
  692.      Limitations::, regarding dangerous trailing context.)
  693.  
  694. `^r'
  695.      an `r', but only at the beginning of a line (i.e., when just
  696.      starting to scan, or right after a newline has been scanned).
  697.  
  698. `r$'
  699.      an `r', but only at the end of a line (i.e., just before a
  700.      newline).  Equivalent to `r/\n'.
  701.  
  702.      Note that `flex''s notion of "newline" is exactly whatever the C
  703.      compiler used to compile `flex' interprets `\n' as; in particular,
  704.      on some DOS systems you must either filter out `\r's in the input
  705.      yourself, or explicitly use `r/\r\n' for `r$'.
  706.  
  707. `<s>r'
  708.      an `r', but only in start condition `s' (see *Note Start
  709.      Conditions:: for discussion of start conditions).
  710.  
  711. `<s1,s2,s3>r'
  712.      same, but in any of start conditions `s1', `s2', or `s3'.
  713.  
  714. `<*>r'
  715.      an `r' in any start condition, even an exclusive one.
  716.  
  717. `<<EOF>>'
  718.      an end-of-file.
  719.  
  720. `<s1,s2><<EOF>>'
  721.      an end-of-file when in start condition `s1' or `s2'
  722.  
  723.    Note that inside of a character class, all regular expression
  724. operators lose their special meaning except escape (`\') and the
  725. character class operators, `-', `]]', and, at the beginning of the
  726. class, `^'.
  727.  
  728.    The regular expressions listed above are grouped according to
  729. precedence, from highest precedence at the top to lowest at the bottom.
  730. Those grouped together have equal precedence (see special note on the
  731. precedence of the repeat operator, `{}', under the documentation for
  732. the `--posix' POSIX compliance option).  For example,
  733.  
  734.  
  735.          foo|bar*
  736.  
  737.    is the same as
  738.  
  739.  
  740.          (foo)|(ba(r*))
  741.  
  742.    since the `*' operator has higher precedence than concatenation, and
  743. concatenation higher than alternation (`|').  This pattern therefore
  744. matches _either_ the string `foo' _or_ the string `ba' followed by
  745. zero-or-more `r''s.  To match `foo' or zero-or-more repetitions of the
  746. string `bar', use:
  747.  
  748.  
  749.          foo|(bar)*
  750.  
  751.    And to match a sequence of zero or more repetitions of `foo' and
  752. `bar':
  753.  
  754.  
  755.          (foo|bar)*
  756.  
  757.    In addition to characters and ranges of characters, character classes
  758. can also contain "character class expressions".  These are expressions
  759. enclosed inside `[': and `:]' delimiters (which themselves must appear
  760. between the `[' and `]' of the character class. Other elements may
  761. occur inside the character class, too).  The valid expressions are:
  762.  
  763.  
  764.          [:alnum:] [:alpha:] [:blank:]
  765.          [:cntrl:] [:digit:] [:graph:]
  766.          [:lower:] [:print:] [:punct:]
  767.          [:space:] [:upper:] [:xdigit:]
  768.  
  769.    These expressions all designate a set of characters equivalent to the
  770. corresponding standard C `isXXX' function.  For example, `[:alnum:]'
  771. designates those characters for which `isalnum()' returns true - i.e.,
  772. any alphabetic or numeric character.  Some systems don't provide
  773. `isblank()', so flex defines `[:blank:]' as a blank or a tab.
  774.  
  775.    For example, the following character classes are all equivalent:
  776.  
  777.  
  778.          [[:alnum:]]
  779.          [[:alpha:][:digit:]]
  780.          [[:alpha:][0-9]]
  781.          [a-zA-Z0-9]
  782.  
  783.    Some notes on patterns are in order.
  784.  
  785.    * If your scanner is case-insensitive (the `-i' flag), then
  786.      `[:upper:]' and `[:lower:]' are equivalent to `[:alpha:]'.
  787.  
  788.    * Character classes with ranges, such as `[a-Z]', should be used with
  789.      caution in a case-insensitive scanner if the range spans upper or
  790.      lowercase characters. Flex does not know if you want to fold all
  791.      upper and lowercase characters together, or if you want the
  792.      literal numeric range specified (with no case folding). When in
  793.      doubt, flex will assume that you meant the literal numeric range,
  794.      and will issue a warning. The exception to this rule is a
  795.      character range such as `[a-z]' or `[S-W]' where it is obvious
  796.      that you want case-folding to occur. Here are some examples with
  797.      the `-i' flag enabled:
  798.  
  799.      Range        Result      Literal Range        Alternate Range
  800.      `[a-t]'      ok          `[a-tA-T]'           
  801.      `[A-T]'      ok          `[a-tA-T]'           
  802.      `[A-t]'      ambiguous   `[A-Z\[\\\]_`a-t]'   `[a-tA-T]'
  803.      `[_-{]'      ambiguous   `[_`a-z{]'           `[_`a-zA-Z{]'
  804.      `[@-C]'      ambiguous   `[@ABC]'             `[@A-Z\[\\\]_`abc]'
  805.  
  806.    * A negated character class such as the example `[^A-Z]' above
  807.      _will_ match a newline unless `\n' (or an equivalent escape
  808.      sequence) is one of the characters explicitly present in the
  809.      negated character class (e.g., `[^A-Z\n]').  This is unlike how
  810.      many other regular expression tools treat negated character
  811.      classes, but unfortunately the inconsistency is historically
  812.      entrenched.  Matching newlines means that a pattern like `[^"]*'
  813.      can match the entire input unless there's another quote in the
  814.      input.
  815.  
  816.    * A rule can have at most one instance of trailing context (the `/'
  817.      operator or the `$' operator).  The start condition, `^', and
  818.      `<<EOF>>' patterns can only occur at the beginning of a pattern,
  819.      and, as well as with `/' and `$', cannot be grouped inside
  820.      parentheses.  A `^' which does not occur at the beginning of a
  821.      rule or a `$' which does not occur at the end of a rule loses its
  822.      special properties and is treated as a normal character.
  823.  
  824.    * The following are invalid:
  825.  
  826.  
  827.               foo/bar$
  828.               <sc1>foo<sc2>bar
  829.  
  830.      Note that the first of these can be written `foo/bar\n'.
  831.  
  832.    * The following will result in `$' or `^' being treated as a normal
  833.      character:
  834.  
  835.  
  836.               foo|(bar$)
  837.               foo|^bar
  838.  
  839.      If the desired meaning is a `foo' or a
  840.      `bar'-followed-by-a-newline, the following could be used (the
  841.      special `|' action is explained below, *note Actions::):
  842.  
  843.  
  844.               foo      |
  845.               bar$     /* action goes here */
  846.  
  847.      A similar trick will work for matching a `foo' or a
  848.      `bar'-at-the-beginning-of-a-line.
  849.  
  850. 
  851. File: flex,  Node: Matching,  Next: Actions,  Prev: Patterns,  Up: Top
  852.  
  853. 7 How the Input Is Matched
  854. **************************
  855.  
  856. When the generated scanner is run, it analyzes its input looking for
  857. strings which match any of its patterns.  If it finds more than one
  858. match, it takes the one matching the most text (for trailing context
  859. rules, this includes the length of the trailing part, even though it
  860. will then be returned to the input).  If it finds two or more matches of
  861. the same length, the rule listed first in the `flex' input file is
  862. chosen.
  863.  
  864.    Once the match is determined, the text corresponding to the match
  865. (called the "token") is made available in the global character pointer
  866. `yytext', and its length in the global integer `yyleng'.  The "action"
  867. corresponding to the matched pattern is then executed (*note
  868. Actions::), and then the remaining input is scanned for another match.
  869.  
  870.    If no match is found, then the "default rule" is executed: the next
  871. character in the input is considered matched and copied to the standard
  872. output.  Thus, the simplest valid `flex' input is:
  873.  
  874.  
  875.          %%
  876.  
  877.    which generates a scanner that simply copies its input (one
  878. character at a time) to its output.
  879.  
  880.    Note that `yytext' can be defined in two different ways: either as a
  881. character _pointer_ or as a character _array_. You can control which
  882. definition `flex' uses by including one of the special directives
  883. `%pointer' or `%array' in the first (definitions) section of your flex
  884. input.  The default is `%pointer', unless you use the `-l' lex
  885. compatibility option, in which case `yytext' will be an array.  The
  886. advantage of using `%pointer' is substantially faster scanning and no
  887. buffer overflow when matching very large tokens (unless you run out of
  888. dynamic memory).  The disadvantage is that you are restricted in how
  889. your actions can modify `yytext' (*note Actions::), and calls to the
  890. `unput()' function destroys the present contents of `yytext', which can
  891. be a considerable porting headache when moving between different `lex'
  892. versions.
  893.  
  894.    The advantage of `%array' is that you can then modify `yytext' to
  895. your heart's content, and calls to `unput()' do not destroy `yytext'
  896. (*note Actions::).  Furthermore, existing `lex' programs sometimes
  897. access `yytext' externally using declarations of the form:
  898.  
  899.  
  900.          extern char yytext[];
  901.  
  902.    This definition is erroneous when used with `%pointer', but correct
  903. for `%array'.
  904.  
  905.    The `%array' declaration defines `yytext' to be an array of `YYLMAX'
  906. characters, which defaults to a fairly large value.  You can change the
  907. size by simply #define'ing `YYLMAX' to a different value in the first
  908. section of your `flex' input.  As mentioned above, with `%pointer'
  909. yytext grows dynamically to accommodate large tokens.  While this means
  910. your `%pointer' scanner can accommodate very large tokens (such as
  911. matching entire blocks of comments), bear in mind that each time the
  912. scanner must resize `yytext' it also must rescan the entire token from
  913. the beginning, so matching such tokens can prove slow.  `yytext'
  914. presently does _not_ dynamically grow if a call to `unput()' results in
  915. too much text being pushed back; instead, a run-time error results.
  916.  
  917.    Also note that you cannot use `%array' with C++ scanner classes
  918. (*note Cxx::).
  919.  
  920. 
  921. File: flex,  Node: Actions,  Next: Generated Scanner,  Prev: Matching,  Up: Top
  922.  
  923. 8 Actions
  924. *********
  925.  
  926. Each pattern in a rule has a corresponding "action", which can be any
  927. arbitrary C statement.  The pattern ends at the first non-escaped
  928. whitespace character; the remainder of the line is its action.  If the
  929. action is empty, then when the pattern is matched the input token is
  930. simply discarded.  For example, here is the specification for a program
  931. which deletes all occurrences of `zap me' from its input:
  932.  
  933.  
  934.          %%
  935.          "zap me"
  936.  
  937.    This example will copy all other characters in the input to the
  938. output since they will be matched by the default rule.
  939.  
  940.    Here is a program which compresses multiple blanks and tabs down to a
  941. single blank, and throws away whitespace found at the end of a line:
  942.  
  943.  
  944.          %%
  945.          [ \t]+        putchar( ' ' );
  946.          [ \t]+$       /* ignore this token */
  947.  
  948.    If the action contains a `}', then the action spans till the
  949. balancing `}' is found, and the action may cross multiple lines.
  950. `flex' knows about C strings and comments and won't be fooled by braces
  951. found within them, but also allows actions to begin with `%{' and will
  952. consider the action to be all the text up to the next `%}' (regardless
  953. of ordinary braces inside the action).
  954.  
  955.    An action consisting solely of a vertical bar (`|') means "same as
  956. the action for the next rule".  See below for an illustration.
  957.  
  958.    Actions can include arbitrary C code, including `return' statements
  959. to return a value to whatever routine called `yylex()'.  Each time
  960. `yylex()' is called it continues processing tokens from where it last
  961. left off until it either reaches the end of the file or executes a
  962. return.
  963.  
  964.    Actions are free to modify `yytext' except for lengthening it
  965. (adding characters to its end-these will overwrite later characters in
  966. the input stream).  This however does not apply when using `%array'
  967. (*note Matching::). In that case, `yytext' may be freely modified in
  968. any way.
  969.  
  970.    Actions are free to modify `yyleng' except they should not do so if
  971. the action also includes use of `yymore()' (see below).
  972.  
  973.    There are a number of special directives which can be included
  974. within an action:
  975.  
  976. `ECHO'
  977.      copies yytext to the scanner's output.
  978.  
  979. `BEGIN'
  980.      followed by the name of a start condition places the scanner in the
  981.      corresponding start condition (see below).
  982.  
  983. `REJECT'
  984.      directs the scanner to proceed on to the "second best" rule which
  985.      matched the input (or a prefix of the input).  The rule is chosen
  986.      as described above in *Note Matching::, and `yytext' and `yyleng'
  987.      set up appropriately.  It may either be one which matched as much
  988.      text as the originally chosen rule but came later in the `flex'
  989.      input file, or one which matched less text.  For example, the
  990.      following will both count the words in the input and call the
  991.      routine `special()' whenever `frob' is seen:
  992.  
  993.  
  994.                       int word_count = 0;
  995.               %%
  996.  
  997.               frob        special(); REJECT;
  998.               [^ \t\n]+   ++word_count;
  999.  
  1000.      Without the `REJECT', any occurences of `frob' in the input would
  1001.      not be counted as words, since the scanner normally executes only
  1002.      one action per token.  Multiple uses of `REJECT' are allowed, each
  1003.      one finding the next best choice to the currently active rule.  For
  1004.      example, when the following scanner scans the token `abcd', it will
  1005.      write `abcdabcaba' to the output:
  1006.  
  1007.  
  1008.               %%
  1009.               a        |
  1010.               ab       |
  1011.               abc      |
  1012.               abcd     ECHO; REJECT;
  1013.               .|\n     /* eat up any unmatched character */
  1014.  
  1015.      The first three rules share the fourth's action since they use the
  1016.      special `|' action.
  1017.  
  1018.      `REJECT' is a particularly expensive feature in terms of scanner
  1019.      performance; if it is used in _any_ of the scanner's actions it
  1020.      will slow down _all_ of the scanner's matching.  Furthermore,
  1021.      `REJECT' cannot be used with the `-Cf' or `-CF' options (*note
  1022.      Scanner Options::).
  1023.  
  1024.      Note also that unlike the other special actions, `REJECT' is a
  1025.      _branch_.  code immediately following it in the action will _not_
  1026.      be executed.
  1027.  
  1028. `yymore()'
  1029.      tells the scanner that the next time it matches a rule, the
  1030.      corresponding token should be _appended_ onto the current value of
  1031.      `yytext' rather than replacing it.  For example, given the input
  1032.      `mega-kludge' the following will write `mega-mega-kludge' to the
  1033.      output:
  1034.  
  1035.  
  1036.               %%
  1037.               mega-    ECHO; yymore();
  1038.               kludge   ECHO;
  1039.  
  1040.      First `mega-' is matched and echoed to the output.  Then `kludge'
  1041.      is matched, but the previous `mega-' is still hanging around at the
  1042.      beginning of `yytext' so the `ECHO' for the `kludge' rule will
  1043.      actually write `mega-kludge'.
  1044.  
  1045.    Two notes regarding use of `yymore()'.  First, `yymore()' depends on
  1046. the value of `yyleng' correctly reflecting the size of the current
  1047. token, so you must not modify `yyleng' if you are using `yymore()'.
  1048. Second, the presence of `yymore()' in the scanner's action entails a
  1049. minor performance penalty in the scanner's matching speed.
  1050.  
  1051.    `yyless(n)' returns all but the first `n' characters of the current
  1052. token back to the input stream, where they will be rescanned when the
  1053. scanner looks for the next match.  `yytext' and `yyleng' are adjusted
  1054. appropriately (e.g., `yyleng' will now be equal to `n').  For example,
  1055. on the input `foobar' the following will write out `foobarbar':
  1056.  
  1057.  
  1058.          %%
  1059.          foobar    ECHO; yyless(3);
  1060.          [a-z]+    ECHO;
  1061.  
  1062.    An argument of 0 to `yyless()' will cause the entire current input
  1063. string to be scanned again.  Unless you've changed how the scanner will
  1064. subsequently process its input (using `BEGIN', for example), this will
  1065. result in an endless loop.
  1066.  
  1067.    Note that `yyless()' is a macro and can only be used in the flex
  1068. input file, not from other source files.
  1069.  
  1070.    `unput(c)' puts the character `c' back onto the input stream.  It
  1071. will be the next character scanned.  The following action will take the
  1072. current token and cause it to be rescanned enclosed in parentheses.
  1073.  
  1074.  
  1075.          {
  1076.          int i;
  1077.          /* Copy yytext because unput() trashes yytext */
  1078.          char *yycopy = strdup( yytext );
  1079.          unput( ')' );
  1080.          for ( i = yyleng - 1; i >= 0; --i )
  1081.              unput( yycopy[i] );
  1082.          unput( '(' );
  1083.          free( yycopy );
  1084.          }
  1085.  
  1086.    Note that since each `unput()' puts the given character back at the
  1087. _beginning_ of the input stream, pushing back strings must be done
  1088. back-to-front.
  1089.  
  1090.    An important potential problem when using `unput()' is that if you
  1091. are using `%pointer' (the default), a call to `unput()' _destroys_ the
  1092. contents of `yytext', starting with its rightmost character and
  1093. devouring one character to the left with each call.  If you need the
  1094. value of `yytext' preserved after a call to `unput()' (as in the above
  1095. example), you must either first copy it elsewhere, or build your
  1096. scanner using `%array' instead (*note Matching::).
  1097.  
  1098.    Finally, note that you cannot put back `EOF' to attempt to mark the
  1099. input stream with an end-of-file.
  1100.  
  1101.    `input()' reads the next character from the input stream.  For
  1102. example, the following is one way to eat up C comments:
  1103.  
  1104.  
  1105.          %%
  1106.          "/*"        {
  1107.                      register int c;
  1108.  
  1109.                      for ( ; ; )
  1110.                          {
  1111.                          while ( (c = input()) != '*' &&
  1112.                                  c != EOF )
  1113.                              ;    /* eat up text of comment */
  1114.  
  1115.                          if ( c == '*' )
  1116.                              {
  1117.                              while ( (c = input()) == '*' )
  1118.                                  ;
  1119.                              if ( c == '/' )
  1120.                                  break;    /* found the end */
  1121.                              }
  1122.  
  1123.                          if ( c == EOF )
  1124.                              {
  1125.                              error( "EOF in comment" );
  1126.                              break;
  1127.                              }
  1128.                          }
  1129.                      }
  1130.  
  1131.    (Note that if the scanner is compiled using `C++', then `input()' is
  1132. instead referred to as yyinput(), in order to avoid a name clash with
  1133. the `C++' stream by the name of `input'.)
  1134.  
  1135.    `YY_FLUSH_BUFFER()' flushes the scanner's internal buffer so that
  1136. the next time the scanner attempts to match a token, it will first
  1137. refill the buffer using `YY_INPUT()' (*note Generated Scanner::).  This
  1138. action is a special case of the more general `yy_flush_buffer()'
  1139. function, described below (*note Multiple Input Buffers::)
  1140.  
  1141.    `yyterminate()' can be used in lieu of a return statement in an
  1142. action.  It terminates the scanner and returns a 0 to the scanner's
  1143. caller, indicating "all done".  By default, `yyterminate()' is also
  1144. called when an end-of-file is encountered.  It is a macro and may be
  1145. redefined.
  1146.  
  1147. 
  1148. File: flex,  Node: Generated Scanner,  Next: Start Conditions,  Prev: Actions,  Up: Top
  1149.  
  1150. 9 The Generated Scanner
  1151. ***********************
  1152.  
  1153. The output of `flex' is the file `lex.yy.c', which contains the
  1154. scanning routine `yylex()', a number of tables used by it for matching
  1155. tokens, and a number of auxiliary routines and macros.  By default,
  1156. `yylex()' is declared as follows:
  1157.  
  1158.  
  1159.          int yylex()
  1160.              {
  1161.              ... various definitions and the actions in here ...
  1162.              }
  1163.  
  1164.    (If your environment supports function prototypes, then it will be
  1165. `int yylex( void )'.)  This definition may be changed by defining the
  1166. `YY_DECL' macro.  For example, you could use:
  1167.  
  1168.  
  1169.          #define YY_DECL float lexscan( a, b ) float a, b;
  1170.  
  1171.    to give the scanning routine the name `lexscan', returning a float,
  1172. and taking two floats as arguments.  Note that if you give arguments to
  1173. the scanning routine using a K&R-style/non-prototyped function
  1174. declaration, you must terminate the definition with a semi-colon (;).
  1175.  
  1176.    `flex' generates `C99' function definitions by default. However flex
  1177. does have the ability to generate obsolete, er, `traditional', function
  1178. definitions. This is to support bootstrapping gcc on old systems.
  1179. Unfortunately, traditional definitions prevent us from using any
  1180. standard data types smaller than int (such as short, char, or bool) as
  1181. function arguments.  For this reason, future versions of `flex' may
  1182. generate standard C99 code only, leaving K&R-style functions to the
  1183. historians.  Currently, if you do *not* want `C99' definitions, then
  1184. you must use `%option noansi-definitions'.
  1185.  
  1186.    Whenever `yylex()' is called, it scans tokens from the global input
  1187. file `yyin' (which defaults to stdin).  It continues until it either
  1188. reaches an end-of-file (at which point it returns the value 0) or one
  1189. of its actions executes a `return' statement.
  1190.  
  1191.    If the scanner reaches an end-of-file, subsequent calls are undefined
  1192. unless either `yyin' is pointed at a new input file (in which case
  1193. scanning continues from that file), or `yyrestart()' is called.
  1194. `yyrestart()' takes one argument, a `FILE *' pointer (which can be
  1195. NULL, if you've set up `YY_INPUT' to scan from a source other than
  1196. `yyin'), and initializes `yyin' for scanning from that file.
  1197. Essentially there is no difference between just assigning `yyin' to a
  1198. new input file or using `yyrestart()' to do so; the latter is available
  1199. for compatibility with previous versions of `flex', and because it can
  1200. be used to switch input files in the middle of scanning.  It can also
  1201. be used to throw away the current input buffer, by calling it with an
  1202. argument of `yyin'; but it would be better to use `YY_FLUSH_BUFFER'
  1203. (*note Actions::).  Note that `yyrestart()' does _not_ reset the start
  1204. condition to `INITIAL' (*note Start Conditions::).
  1205.  
  1206.    If `yylex()' stops scanning due to executing a `return' statement in
  1207. one of the actions, the scanner may then be called again and it will
  1208. resume scanning where it left off.
  1209.  
  1210.    By default (and for purposes of efficiency), the scanner uses
  1211. block-reads rather than simple `getc()' calls to read characters from
  1212. `yyin'.  The nature of how it gets its input can be controlled by
  1213. defining the `YY_INPUT' macro.  The calling sequence for `YY_INPUT()'
  1214. is `YY_INPUT(buf,result,max_size)'.  Its action is to place up to
  1215. `max_size' characters in the character array `buf' and return in the
  1216. integer variable `result' either the number of characters read or the
  1217. constant `YY_NULL' (0 on Unix systems) to indicate `EOF'.  The default
  1218. `YY_INPUT' reads from the global file-pointer `yyin'.
  1219.  
  1220.    Here is a sample definition of `YY_INPUT' (in the definitions
  1221. section of the input file):
  1222.  
  1223.  
  1224.          %{
  1225.          #define YY_INPUT(buf,result,max_size) \
  1226.              { \
  1227.              int c = getchar(); \
  1228.              result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
  1229.              }
  1230.          %}
  1231.  
  1232.    This definition will change the input processing to occur one
  1233. character at a time.
  1234.  
  1235.    When the scanner receives an end-of-file indication from YY_INPUT, it
  1236. then checks the `yywrap()' function.  If `yywrap()' returns false
  1237. (zero), then it is assumed that the function has gone ahead and set up
  1238. `yyin' to point to another input file, and scanning continues.  If it
  1239. returns true (non-zero), then the scanner terminates, returning 0 to
  1240. its caller.  Note that in either case, the start condition remains
  1241. unchanged; it does _not_ revert to `INITIAL'.
  1242.  
  1243.    If you do not supply your own version of `yywrap()', then you must
  1244. either use `%option noyywrap' (in which case the scanner behaves as
  1245. though `yywrap()' returned 1), or you must link with `-lfl' to obtain
  1246. the default version of the routine, which always returns 1.
  1247.  
  1248.    For scanning from in-memory buffers (e.g., scanning strings), see
  1249. *Note Scanning Strings::. *Note Multiple Input Buffers::.
  1250.  
  1251.    The scanner writes its `ECHO' output to the `yyout' global (default,
  1252. `stdout'), which may be redefined by the user simply by assigning it to
  1253. some other `FILE' pointer.
  1254.  
  1255. 
  1256. File: flex,  Node: Start Conditions,  Next: Multiple Input Buffers,  Prev: Generated Scanner,  Up: Top
  1257.  
  1258. 10 Start Conditions
  1259. *******************
  1260.  
  1261. `flex' provides a mechanism for conditionally activating rules.  Any
  1262. rule whose pattern is prefixed with `<sc>' will only be active when the
  1263. scanner is in the "start condition" named `sc'.  For example,
  1264.  
  1265.  
  1266.          <STRING>[^"]*        { /* eat up the string body ... */
  1267.                      ...
  1268.                      }
  1269.  
  1270.    will be active only when the scanner is in the `STRING' start
  1271. condition, and
  1272.  
  1273.  
  1274.          <INITIAL,STRING,QUOTE>\.        { /* handle an escape ... */
  1275.                      ...
  1276.                      }
  1277.  
  1278.    will be active only when the current start condition is either
  1279. `INITIAL', `STRING', or `QUOTE'.
  1280.  
  1281.    Start conditions are declared in the definitions (first) section of
  1282. the input using unindented lines beginning with either `%s' or `%x'
  1283. followed by a list of names.  The former declares "inclusive" start
  1284. conditions, the latter "exclusive" start conditions.  A start condition
  1285. is activated using the `BEGIN' action.  Until the next `BEGIN' action
  1286. is executed, rules with the given start condition will be active and
  1287. rules with other start conditions will be inactive.  If the start
  1288. condition is inclusive, then rules with no start conditions at all will
  1289. also be active.  If it is exclusive, then _only_ rules qualified with
  1290. the start condition will be active.  A set of rules contingent on the
  1291. same exclusive start condition describe a scanner which is independent
  1292. of any of the other rules in the `flex' input.  Because of this,
  1293. exclusive start conditions make it easy to specify "mini-scanners"
  1294. which scan portions of the input that are syntactically different from
  1295. the rest (e.g., comments).
  1296.  
  1297.    If the distinction between inclusive and exclusive start conditions
  1298. is still a little vague, here's a simple example illustrating the
  1299. connection between the two.  The set of rules:
  1300.  
  1301.  
  1302.          %s example
  1303.          %%
  1304.  
  1305.          <example>foo   do_something();
  1306.  
  1307.          bar            something_else();
  1308.  
  1309.    is equivalent to
  1310.  
  1311.  
  1312.          %x example
  1313.          %%
  1314.  
  1315.          <example>foo   do_something();
  1316.  
  1317.          <INITIAL,example>bar    something_else();
  1318.  
  1319.    Without the `<INITIAL,example>' qualifier, the `bar' pattern in the
  1320. second example wouldn't be active (i.e., couldn't match) when in start
  1321. condition `example'.  If we just used `example>' to qualify `bar',
  1322. though, then it would only be active in `example' and not in `INITIAL',
  1323. while in the first example it's active in both, because in the first
  1324. example the `example' start condition is an inclusive `(%s)' start
  1325. condition.
  1326.  
  1327.    Also note that the special start-condition specifier `<*>' matches
  1328. every start condition.  Thus, the above example could also have been
  1329. written:
  1330.  
  1331.  
  1332.          %x example
  1333.          %%
  1334.  
  1335.          <example>foo   do_something();
  1336.  
  1337.          <*>bar    something_else();
  1338.  
  1339.    The default rule (to `ECHO' any unmatched character) remains active
  1340. in start conditions.  It is equivalent to:
  1341.  
  1342.  
  1343.          <*>.|\n     ECHO;
  1344.  
  1345.    `BEGIN(0)' returns to the original state where only the rules with
  1346. no start conditions are active.  This state can also be referred to as
  1347. the start-condition `INITIAL', so `BEGIN(INITIAL)' is equivalent to
  1348. `BEGIN(0)'.  (The parentheses around the start condition name are not
  1349. required but are considered good style.)
  1350.  
  1351.    `BEGIN' actions can also be given as indented code at the beginning
  1352. of the rules section.  For example, the following will cause the scanner
  1353. to enter the `SPECIAL' start condition whenever `yylex()' is called and
  1354. the global variable `enter_special' is true:
  1355.  
  1356.  
  1357.                  int enter_special;
  1358.  
  1359.          %x SPECIAL
  1360.          %%
  1361.                  if ( enter_special )
  1362.                      BEGIN(SPECIAL);
  1363.  
  1364.          <SPECIAL>blahblahblah
  1365.          ...more rules follow...
  1366.  
  1367.    To illustrate the uses of start conditions, here is a scanner which
  1368. provides two different interpretations of a string like `123.456'.  By
  1369. default it will treat it as three tokens, the integer `123', a dot
  1370. (`.'), and the integer `456'.  But if the string is preceded earlier in
  1371. the line by the string `expect-floats' it will treat it as a single
  1372. token, the floating-point number `123.456':
  1373.  
  1374.  
  1375.          %{
  1376.          #include <math.h>
  1377.          %}
  1378.          %s expect
  1379.  
  1380.          %%
  1381.          expect-floats        BEGIN(expect);
  1382.  
  1383.          <expect>[0-9]+@samp{.}[0-9]+      {
  1384.                      printf( "found a float, = %f\n",
  1385.                              atof( yytext ) );
  1386.                      }
  1387.          <expect>\n           {
  1388.                      /* that's the end of the line, so
  1389.                       * we need another "expect-number"
  1390.                       * before we'll recognize any more
  1391.                       * numbers
  1392.                       */
  1393.                      BEGIN(INITIAL);
  1394.                      }
  1395.  
  1396.          [0-9]+      {
  1397.                      printf( "found an integer, = %d\n",
  1398.                              atoi( yytext ) );
  1399.                      }
  1400.  
  1401.          "."         printf( "found a dot\n" );
  1402.  
  1403.    Here is a scanner which recognizes (and discards) C comments while
  1404. maintaining a count of the current input line.
  1405.  
  1406.  
  1407.          %x comment
  1408.          %%
  1409.                  int line_num = 1;
  1410.  
  1411.          "/*"         BEGIN(comment);
  1412.  
  1413.          <comment>[^*\n]*        /* eat anything that's not a '*' */
  1414.          <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1415.          <comment>\n             ++line_num;
  1416.          <comment>"*"+"/"        BEGIN(INITIAL);
  1417.  
  1418.    This scanner goes to a bit of trouble to match as much text as
  1419. possible with each rule.  In general, when attempting to write a
  1420. high-speed scanner try to match as much possible in each rule, as it's
  1421. a big win.
  1422.  
  1423.    Note that start-conditions names are really integer values and can
  1424. be stored as such.  Thus, the above could be extended in the following
  1425. fashion:
  1426.  
  1427.  
  1428.          %x comment foo
  1429.          %%
  1430.                  int line_num = 1;
  1431.                  int comment_caller;
  1432.  
  1433.          "/*"         {
  1434.                       comment_caller = INITIAL;
  1435.                       BEGIN(comment);
  1436.                       }
  1437.  
  1438.          ...
  1439.  
  1440.          <foo>"/*"    {
  1441.                       comment_caller = foo;
  1442.                       BEGIN(comment);
  1443.                       }
  1444.  
  1445.          <comment>[^*\n]*        /* eat anything that's not a '*' */
  1446.          <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1447.          <comment>\n             ++line_num;
  1448.          <comment>"*"+"/"        BEGIN(comment_caller);
  1449.  
  1450.    Furthermore, you can access the current start condition using the
  1451. integer-valued `YY_START' macro.  For example, the above assignments to
  1452. `comment_caller' could instead be written
  1453.  
  1454.  
  1455.          comment_caller = YY_START;
  1456.  
  1457.    Flex provides `YYSTATE' as an alias for `YY_START' (since that is
  1458. what's used by AT&T `lex').
  1459.  
  1460.    For historical reasons, start conditions do not have their own
  1461. name-space within the generated scanner. The start condition names are
  1462. unmodified in the generated scanner and generated header.  *Note
  1463. option-header::. *Note option-prefix::.
  1464.  
  1465.    Finally, here's an example of how to match C-style quoted strings
  1466. using exclusive start conditions, including expanded escape sequences
  1467. (but not including checking for a string that's too long):
  1468.  
  1469.  
  1470.          %x str
  1471.  
  1472.          %%
  1473.                  char string_buf[MAX_STR_CONST];
  1474.                  char *string_buf_ptr;
  1475.  
  1476.  
  1477.          \"      string_buf_ptr = string_buf; BEGIN(str);
  1478.  
  1479.          <str>\"        { /* saw closing quote - all done */
  1480.                  BEGIN(INITIAL);
  1481.                  *string_buf_ptr = '\0';
  1482.                  /* return string constant token type and
  1483.                   * value to parser
  1484.                   */
  1485.                  }
  1486.  
  1487.          <str>\n        {
  1488.                  /* error - unterminated string constant */
  1489.                  /* generate error message */
  1490.                  }
  1491.  
  1492.          <str>\\[0-7]{1,3} {
  1493.                  /* octal escape sequence */
  1494.                  int result;
  1495.  
  1496.                  (void) sscanf( yytext + 1, "%o", &result );
  1497.  
  1498.                  if ( result > 0xff )
  1499.                          /* error, constant is out-of-bounds */
  1500.  
  1501.                  *string_buf_ptr++ = result;
  1502.                  }
  1503.  
  1504.          <str>\\[0-9]+ {
  1505.                  /* generate error - bad escape sequence; something
  1506.                   * like '\48' or '\0777777'
  1507.                   */
  1508.                  }
  1509.  
  1510.          <str>\\n  *string_buf_ptr++ = '\n';
  1511.          <str>\\t  *string_buf_ptr++ = '\t';
  1512.          <str>\\r  *string_buf_ptr++ = '\r';
  1513.          <str>\\b  *string_buf_ptr++ = '\b';
  1514.          <str>\\f  *string_buf_ptr++ = '\f';
  1515.  
  1516.          <str>\\(.|\n)  *string_buf_ptr++ = yytext[1];
  1517.  
  1518.          <str>[^\\\n\"]+        {
  1519.                  char *yptr = yytext;
  1520.  
  1521.                  while ( *yptr )
  1522.                          *string_buf_ptr++ = *yptr++;
  1523.                  }
  1524.  
  1525.    Often, such as in some of the examples above, you wind up writing a
  1526. whole bunch of rules all preceded by the same start condition(s).  Flex
  1527. makes this a little easier and cleaner by introducing a notion of start
  1528. condition "scope".  A start condition scope is begun with:
  1529.  
  1530.  
  1531.          <SCs>{
  1532.  
  1533.    where `SCs' is a list of one or more start conditions.  Inside the
  1534. start condition scope, every rule automatically has the prefix `SCs>'
  1535. applied to it, until a `}' which matches the initial `{'.  So, for
  1536. example,
  1537.  
  1538.  
  1539.          <ESC>{
  1540.              "\\n"   return '\n';
  1541.              "\\r"   return '\r';
  1542.              "\\f"   return '\f';
  1543.              "\\0"   return '\0';
  1544.          }
  1545.  
  1546.    is equivalent to:
  1547.  
  1548.  
  1549.          <ESC>"\\n"  return '\n';
  1550.          <ESC>"\\r"  return '\r';
  1551.          <ESC>"\\f"  return '\f';
  1552.          <ESC>"\\0"  return '\0';
  1553.  
  1554.    Start condition scopes may be nested.
  1555.  
  1556.    The following routines are available for manipulating stacks of
  1557. start conditions:
  1558.  
  1559.  -- Function: void yy_push_state ( int `new_state' )
  1560.      pushes the current start condition onto the top of the start
  1561.      condition stack and switches to `new_state' as though you had used
  1562.      `BEGIN new_state' (recall that start condition names are also
  1563.      integers).
  1564.  
  1565.  -- Function: void yy_pop_state ()
  1566.      pops the top of the stack and switches to it via `BEGIN'.
  1567.  
  1568.  -- Function: int yy_top_state ()
  1569.      returns the top of the stack without altering the stack's contents.
  1570.  
  1571.    The start condition stack grows dynamically and so has no built-in
  1572. size limitation.  If memory is exhausted, program execution aborts.
  1573.  
  1574.    To use start condition stacks, your scanner must include a `%option
  1575. stack' directive (*note Scanner Options::).
  1576.  
  1577. 
  1578. File: flex,  Node: Multiple Input Buffers,  Next: EOF,  Prev: Start Conditions,  Up: Top
  1579.  
  1580. 11 Multiple Input Buffers
  1581. *************************
  1582.  
  1583. Some scanners (such as those which support "include" files) require
  1584. reading from several input streams.  As `flex' scanners do a large
  1585. amount of buffering, one cannot control where the next input will be
  1586. read from by simply writing a `YY_INPUT()' which is sensitive to the
  1587. scanning context.  `YY_INPUT()' is only called when the scanner reaches
  1588. the end of its buffer, which may be a long time after scanning a
  1589. statement such as an `include' statement which requires switching the
  1590. input source.
  1591.  
  1592.    To negotiate these sorts of problems, `flex' provides a mechanism
  1593. for creating and switching between multiple input buffers.  An input
  1594. buffer is created by using:
  1595.  
  1596.  -- Function: YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size )
  1597.  
  1598.    which takes a `FILE' pointer and a size and creates a buffer
  1599. associated with the given file and large enough to hold `size'
  1600. characters (when in doubt, use `YY_BUF_SIZE' for the size).  It returns
  1601. a `YY_BUFFER_STATE' handle, which may then be passed to other routines
  1602. (see below).  The `YY_BUFFER_STATE' type is a pointer to an opaque
  1603. `struct yy_buffer_state' structure, so you may safely initialize
  1604. `YY_BUFFER_STATE' variables to `((YY_BUFFER_STATE) 0)' if you wish, and
  1605. also refer to the opaque structure in order to correctly declare input
  1606. buffers in source files other than that of your scanner.  Note that the
  1607. `FILE' pointer in the call to `yy_create_buffer' is only used as the
  1608. value of `yyin' seen by `YY_INPUT'.  If you redefine `YY_INPUT()' so it
  1609. no longer uses `yyin', then you can safely pass a NULL `FILE' pointer to
  1610. `yy_create_buffer'.  You select a particular buffer to scan from using:
  1611.  
  1612.  -- Function: void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer )
  1613.  
  1614.    The above function switches the scanner's input buffer so subsequent
  1615. tokens will come from `new_buffer'.  Note that `yy_switch_to_buffer()'
  1616. may be used by `yywrap()' to set things up for continued scanning,
  1617. instead of opening a new file and pointing `yyin' at it. If you are
  1618. looking for a stack of input buffers, then you want to use
  1619. `yypush_buffer_state()' instead of this function. Note also that
  1620. switching input sources via either `yy_switch_to_buffer()' or
  1621. `yywrap()' does _not_ change the start condition.
  1622.  
  1623.  -- Function: void yy_delete_buffer ( YY_BUFFER_STATE buffer )
  1624.  
  1625.    is used to reclaim the storage associated with a buffer.  (`buffer'
  1626. can be NULL, in which case the routine does nothing.)  You can also
  1627. clear the current contents of a buffer using:
  1628.  
  1629.  -- Function: void yypush_buffer_state ( YY_BUFFER_STATE buffer )
  1630.  
  1631.    This function pushes the new buffer state onto an internal stack.
  1632. The pushed state becomes the new current state. The stack is maintained
  1633. by flex and will grow as required. This function is intended to be used
  1634. instead of `yy_switch_to_buffer', when you want to change states, but
  1635. preserve the current state for later use.
  1636.  
  1637.  -- Function: void yypop_buffer_state ( )
  1638.  
  1639.    This function removes the current state from the top of the stack,
  1640. and deletes it by calling `yy_delete_buffer'.  The next state on the
  1641. stack, if any, becomes the new current state.
  1642.  
  1643.  -- Function: void yy_flush_buffer ( YY_BUFFER_STATE buffer )
  1644.  
  1645.    This function discards the buffer's contents, so the next time the
  1646. scanner attempts to match a token from the buffer, it will first fill
  1647. the buffer anew using `YY_INPUT()'.
  1648.  
  1649.  -- Function: YY_BUFFER_STATE yy_new_buffer ( FILE *file, int size )
  1650.  
  1651.    is an alias for `yy_create_buffer()', provided for compatibility
  1652. with the C++ use of `new' and `delete' for creating and destroying
  1653. dynamic objects.
  1654.  
  1655.    `YY_CURRENT_BUFFER' macro returns a `YY_BUFFER_STATE' handle to the
  1656. current buffer. It should not be used as an lvalue.
  1657.  
  1658.    Here are two examples of using these features for writing a scanner
  1659. which expands include files (the `<<EOF>>' feature is discussed below).
  1660.  
  1661.    This first example uses yypush_buffer_state and yypop_buffer_state.
  1662. Flex maintains the stack internally.
  1663.  
  1664.  
  1665.          /* the "incl" state is used for picking up the name
  1666.           * of an include file
  1667.           */
  1668.          %x incl
  1669.          %%
  1670.          include             BEGIN(incl);
  1671.  
  1672.          [a-z]+              ECHO;
  1673.          [^a-z\n]*\n?        ECHO;
  1674.  
  1675.          <incl>[ \t]*      /* eat the whitespace */
  1676.          <incl>[^ \t\n]+   { /* got the include file name */
  1677.                  yyin = fopen( yytext, "r" );
  1678.  
  1679.                  if ( ! yyin )
  1680.                      error( ... );
  1681.  
  1682.                  yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
  1683.  
  1684.                  BEGIN(INITIAL);
  1685.                  }
  1686.  
  1687.          <<EOF>> {
  1688.                  yypop_buffer_state();
  1689.  
  1690.                  if ( !YY_CURRENT_BUFFER )
  1691.                      {
  1692.                      yyterminate();
  1693.                      }
  1694.                  }
  1695.  
  1696.    The second example, below, does the same thing as the previous
  1697. example did, but manages its own input buffer stack manually (instead
  1698. of letting flex do it).
  1699.  
  1700.  
  1701.          /* the "incl" state is used for picking up the name
  1702.           * of an include file
  1703.           */
  1704.          %x incl
  1705.  
  1706.          %{
  1707.          #define MAX_INCLUDE_DEPTH 10
  1708.          YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  1709.          int include_stack_ptr = 0;
  1710.          %}
  1711.  
  1712.          %%
  1713.          include             BEGIN(incl);
  1714.  
  1715.          [a-z]+              ECHO;
  1716.          [^a-z\n]*\n?        ECHO;
  1717.  
  1718.          <incl>[ \t]*      /* eat the whitespace */
  1719.          <incl>[^ \t\n]+   { /* got the include file name */
  1720.                  if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
  1721.                      {
  1722.                      fprintf( stderr, "Includes nested too deeply" );
  1723.                      exit( 1 );
  1724.                      }
  1725.  
  1726.                  include_stack[include_stack_ptr++] =
  1727.                      YY_CURRENT_BUFFER;
  1728.  
  1729.                  yyin = fopen( yytext, "r" );
  1730.  
  1731.                  if ( ! yyin )
  1732.                      error( ... );
  1733.  
  1734.                  yy_switch_to_buffer(
  1735.                      yy_create_buffer( yyin, YY_BUF_SIZE ) );
  1736.  
  1737.                  BEGIN(INITIAL);
  1738.                  }
  1739.  
  1740.          <<EOF>> {
  1741.                  if ( --include_stack_ptr  0 )
  1742.                      {
  1743.                      yyterminate();
  1744.                      }
  1745.  
  1746.                  else
  1747.                      {
  1748.                      yy_delete_buffer( YY_CURRENT_BUFFER );
  1749.                      yy_switch_to_buffer(
  1750.                           include_stack[include_stack_ptr] );
  1751.                      }
  1752.                  }
  1753.  
  1754.    The following routines are available for setting up input buffers for
  1755. scanning in-memory strings instead of files.  All of them create a new
  1756. input buffer for scanning the string, and return a corresponding
  1757. `YY_BUFFER_STATE' handle (which you should delete with
  1758. `yy_delete_buffer()' when done with it).  They also switch to the new
  1759. buffer using `yy_switch_to_buffer()', so the next call to `yylex()'
  1760. will start scanning the string.
  1761.  
  1762.  -- Function: YY_BUFFER_STATE yy_scan_string ( const char *str )
  1763.      scans a NUL-terminated string.
  1764.  
  1765.  -- Function: YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int
  1766.           len )
  1767.      scans `len' bytes (including possibly `NUL's) starting at location
  1768.      `bytes'.
  1769.  
  1770.    Note that both of these functions create and scan a _copy_ of the
  1771. string or bytes.  (This may be desirable, since `yylex()' modifies the
  1772. contents of the buffer it is scanning.)  You can avoid the copy by
  1773. using:
  1774.  
  1775.  -- Function: YY_BUFFER_STATE yy_scan_buffer (char *base, yy_size_t
  1776.           size)
  1777.      which scans in place the buffer starting at `base', consisting of
  1778.      `size' bytes, the last two bytes of which _must_ be
  1779.      `YY_END_OF_BUFFER_CHAR' (ASCII NUL).  These last two bytes are not
  1780.      scanned; thus, scanning consists of `base[0]' through
  1781.      `base[size-2]', inclusive.
  1782.  
  1783.    If you fail to set up `base' in this manner (i.e., forget the final
  1784. two `YY_END_OF_BUFFER_CHAR' bytes), then `yy_scan_buffer()' returns a
  1785. NULL pointer instead of creating a new input buffer.
  1786.  
  1787.  -- Data type: yy_size_t
  1788.      is an integral type to which you can cast an integer expression
  1789.      reflecting the size of the buffer.
  1790.  
  1791. 
  1792. File: flex,  Node: EOF,  Next: Misc Macros,  Prev: Multiple Input Buffers,  Up: Top
  1793.  
  1794. 12 End-of-File Rules
  1795. ********************
  1796.  
  1797. The special rule `<<EOF>>' indicates actions which are to be taken when
  1798. an end-of-file is encountered and `yywrap()' returns non-zero (i.e.,
  1799. indicates no further files to process).  The action must finish by
  1800. doing one of the following things:
  1801.  
  1802.    * assigning `yyin' to a new input file (in previous versions of
  1803.      `flex', after doing the assignment you had to call the special
  1804.      action `YY_NEW_FILE'.  This is no longer necessary.)
  1805.  
  1806.    * executing a `return' statement;
  1807.  
  1808.    * executing the special `yyterminate()' action.
  1809.  
  1810.    * or, switching to a new buffer using `yy_switch_to_buffer()' as
  1811.      shown in the example above.
  1812.  
  1813.    <<EOF>> rules may not be used with other patterns; they may only be
  1814. qualified with a list of start conditions.  If an unqualified <<EOF>>
  1815. rule is given, it applies to _all_ start conditions which do not
  1816. already have <<EOF>> actions.  To specify an <<EOF>> rule for only the
  1817. initial start condition, use:
  1818.  
  1819.  
  1820.          <INITIAL><<EOF>>
  1821.  
  1822.    These rules are useful for catching things like unclosed comments.
  1823. An example:
  1824.  
  1825.  
  1826.          %x quote
  1827.          %%
  1828.  
  1829.          ...other rules for dealing with quotes...
  1830.  
  1831.          <quote><<EOF>>   {
  1832.                   error( "unterminated quote" );
  1833.                   yyterminate();
  1834.                   }
  1835.         <<EOF>>  {
  1836.                   if ( *++filelist )
  1837.                       yyin = fopen( *filelist, "r" );
  1838.                   else
  1839.                      yyterminate();
  1840.                   }
  1841.  
  1842. 
  1843. File: flex,  Node: Misc Macros,  Next: User Values,  Prev: EOF,  Up: Top
  1844.  
  1845. 13 Miscellaneous Macros
  1846. ***********************
  1847.  
  1848. The macro `YY_USER_ACTION' can be defined to provide an action which is
  1849. always executed prior to the matched rule's action.  For example, it
  1850. could be #define'd to call a routine to convert yytext to lower-case.
  1851. When `YY_USER_ACTION' is invoked, the variable `yy_act' gives the
  1852. number of the matched rule (rules are numbered starting with 1).
  1853. Suppose you want to profile how often each of your rules is matched.
  1854. The following would do the trick:
  1855.  
  1856.  
  1857.          #define YY_USER_ACTION ++ctr[yy_act]
  1858.  
  1859.    where `ctr' is an array to hold the counts for the different rules.
  1860. Note that the macro `YY_NUM_RULES' gives the total number of rules
  1861. (including the default rule), even if you use `-s)', so a correct
  1862. declaration for `ctr' is:
  1863.  
  1864.  
  1865.          int ctr[YY_NUM_RULES];
  1866.  
  1867.    The macro `YY_USER_INIT' may be defined to provide an action which
  1868. is always executed before the first scan (and before the scanner's
  1869. internal initializations are done).  For example, it could be used to
  1870. call a routine to read in a data table or open a logging file.
  1871.  
  1872.    The macro `yy_set_interactive(is_interactive)' can be used to
  1873. control whether the current buffer is considered "interactive".  An
  1874. interactive buffer is processed more slowly, but must be used when the
  1875. scanner's input source is indeed interactive to avoid problems due to
  1876. waiting to fill buffers (see the discussion of the `-I' flag in *Note
  1877. Scanner Options::).  A non-zero value in the macro invocation marks the
  1878. buffer as interactive, a zero value as non-interactive.  Note that use
  1879. of this macro overrides `%option always-interactive' or `%option
  1880. never-interactive' (*note Scanner Options::).  `yy_set_interactive()'
  1881. must be invoked prior to beginning to scan the buffer that is (or is
  1882. not) to be considered interactive.
  1883.  
  1884.    The macro `yy_set_bol(at_bol)' can be used to control whether the
  1885. current buffer's scanning context for the next token match is done as
  1886. though at the beginning of a line.  A non-zero macro argument makes
  1887. rules anchored with `^' active, while a zero argument makes `^' rules
  1888. inactive.
  1889.  
  1890.    The macro `YY_AT_BOL()' returns true if the next token scanned from
  1891. the current buffer will have `^' rules active, false otherwise.
  1892.  
  1893.    In the generated scanner, the actions are all gathered in one large
  1894. switch statement and separated using `YY_BREAK', which may be
  1895. redefined.  By default, it is simply a `break', to separate each rule's
  1896. action from the following rule's.  Redefining `YY_BREAK' allows, for
  1897. example, C++ users to #define YY_BREAK to do nothing (while being very
  1898. careful that every rule ends with a `break'" or a `return'!) to avoid
  1899. suffering from unreachable statement warnings where because a rule's
  1900. action ends with `return', the `YY_BREAK' is inaccessible.
  1901.  
  1902. 
  1903. File: flex,  Node: User Values,  Next: Yacc,  Prev: Misc Macros,  Up: Top
  1904.  
  1905. 14 Values Available To the User
  1906. *******************************
  1907.  
  1908. This chapter summarizes the various values available to the user in the
  1909. rule actions.
  1910.  
  1911. `char *yytext'
  1912.      holds the text of the current token.  It may be modified but not
  1913.      lengthened (you cannot append characters to the end).
  1914.  
  1915.      If the special directive `%array' appears in the first section of
  1916.      the scanner description, then `yytext' is instead declared `char
  1917.      yytext[YYLMAX]', where `YYLMAX' is a macro definition that you can
  1918.      redefine in the first section if you don't like the default value
  1919.      (generally 8KB).  Using `%array' results in somewhat slower
  1920.      scanners, but the value of `yytext' becomes immune to calls to
  1921.      `unput()', which potentially destroy its value when `yytext' is a
  1922.      character pointer.  The opposite of `%array' is `%pointer', which
  1923.      is the default.
  1924.  
  1925.      You cannot use `%array' when generating C++ scanner classes (the
  1926.      `-+' flag).
  1927.  
  1928. `int yyleng'
  1929.      holds the length of the current token.
  1930.  
  1931. `FILE *yyin'
  1932.      is the file which by default `flex' reads from.  It may be
  1933.      redefined but doing so only makes sense before scanning begins or
  1934.      after an EOF has been encountered.  Changing it in the midst of
  1935.      scanning will have unexpected results since `flex' buffers its
  1936.      input; use `yyrestart()' instead.  Once scanning terminates
  1937.      because an end-of-file has been seen, you can assign `yyin' at the
  1938.      new input file and then call the scanner again to continue
  1939.      scanning.
  1940.  
  1941. `void yyrestart( FILE *new_file )'
  1942.      may be called to point `yyin' at the new input file.  The
  1943.      switch-over to the new file is immediate (any previously
  1944.      buffered-up input is lost).  Note that calling `yyrestart()' with
  1945.      `yyin' as an argument thus throws away the current input buffer
  1946.      and continues scanning the same input file.
  1947.  
  1948. `FILE *yyout'
  1949.      is the file to which `ECHO' actions are done.  It can be reassigned
  1950.      by the user.
  1951.  
  1952. `YY_CURRENT_BUFFER'
  1953.      returns a `YY_BUFFER_STATE' handle to the current buffer.
  1954.  
  1955. `YY_START'
  1956.      returns an integer value corresponding to the current start
  1957.      condition.  You can subsequently use this value with `BEGIN' to
  1958.      return to that start condition.
  1959.  
  1960. 
  1961. File: flex,  Node: Yacc,  Next: Scanner Options,  Prev: User Values,  Up: Top
  1962.  
  1963. 15 Interfacing with Yacc
  1964. ************************
  1965.  
  1966. One of the main uses of `flex' is as a companion to the `yacc'
  1967. parser-generator.  `yacc' parsers expect to call a routine named
  1968. `yylex()' to find the next input token.  The routine is supposed to
  1969. return the type of the next token as well as putting any associated
  1970. value in the global `yylval'.  To use `flex' with `yacc', one specifies
  1971. the `-d' option to `yacc' to instruct it to generate the file `y.tab.h'
  1972. containing definitions of all the `%tokens' appearing in the `yacc'
  1973. input.  This file is then included in the `flex' scanner.  For example,
  1974. if one of the tokens is `TOK_NUMBER', part of the scanner might look
  1975. like:
  1976.  
  1977.  
  1978.          %{
  1979.          #include "y.tab.h"
  1980.          %}
  1981.  
  1982.          %%
  1983.  
  1984.          [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
  1985.  
  1986. 
  1987. File: flex,  Node: Scanner Options,  Next: Performance,  Prev: Yacc,  Up: Top
  1988.  
  1989. 16 Scanner Options
  1990. ******************
  1991.  
  1992. The various `flex' options are categorized by function in the following
  1993. menu. If you want to lookup a particular option by name, *Note Index of
  1994. Scanner Options::.
  1995.  
  1996. * Menu:
  1997.  
  1998. * Options for Specifing Filenames::
  1999. * Options Affecting Scanner Behavior::
  2000. * Code-Level And API Options::
  2001. * Options for Scanner Speed and Size::
  2002. * Debugging Options::
  2003. * Miscellaneous Options::
  2004.  
  2005.    Even though there are many scanner options, a typical scanner might
  2006. only specify the following options:
  2007.  
  2008.  
  2009.      %option   8bit reentrant bison-bridge
  2010.      %option   warn nodefault
  2011.      %option   yylineno
  2012.      %option   outfile="scanner.c" header-file="scanner.h"
  2013.  
  2014.    The first line specifies the general type of scanner we want. The
  2015. second line specifies that we are being careful. The third line asks
  2016. flex to track line numbers. The last line tells flex what to name the
  2017. files. (The options can be specified in any order. We just dividied
  2018. them.)
  2019.  
  2020.    `flex' also provides a mechanism for controlling options within the
  2021. scanner specification itself, rather than from the flex command-line.
  2022. This is done by including `%option' directives in the first section of
  2023. the scanner specification.  You can specify multiple options with a
  2024. single `%option' directive, and multiple directives in the first
  2025. section of your flex input file.
  2026.  
  2027.    Most options are given simply as names, optionally preceded by the
  2028. word `no' (with no intervening whitespace) to negate their meaning.
  2029. The names are the same as their long-option equivalents (but without the
  2030. leading `--' ).
  2031.  
  2032.    `flex' scans your rule actions to determine whether you use the
  2033. `REJECT' or `yymore()' features.  The `REJECT' and `yymore' options are
  2034. available to override its decision as to whether you use the options,
  2035. either by setting them (e.g., `%option reject)' to indicate the feature
  2036. is indeed used, or unsetting them to indicate it actually is not used
  2037. (e.g., `%option noyymore)'.
  2038.  
  2039.    A number of options are available for lint purists who want to
  2040. suppress the appearance of unneeded routines in the generated scanner.
  2041. Each of the following, if unset (e.g., `%option nounput'), results in
  2042. the corresponding routine not appearing in the generated scanner:
  2043.  
  2044.  
  2045.          input, unput
  2046.          yy_push_state, yy_pop_state, yy_top_state
  2047.          yy_scan_buffer, yy_scan_bytes, yy_scan_string
  2048.  
  2049.          yyget_extra, yyset_extra, yyget_leng, yyget_text,
  2050.          yyget_lineno, yyset_lineno, yyget_in, yyset_in,
  2051.          yyget_out, yyset_out, yyget_lval, yyset_lval,
  2052.          yyget_lloc, yyset_lloc, yyget_debug, yyset_debug
  2053.  
  2054.    (though `yy_push_state()' and friends won't appear anyway unless you
  2055. use `%option stack)'.
  2056.  
  2057. 
  2058. File: flex,  Node: Options for Specifing Filenames,  Next: Options Affecting Scanner Behavior,  Prev: Scanner Options,  Up: Scanner Options
  2059.  
  2060. 16.1 Options for Specifing Filenames
  2061. ====================================
  2062.  
  2063. `--header-file=FILE, `%option header-file="FILE"''
  2064.      instructs flex to write a C header to `FILE'. This file contains
  2065.      function prototypes, extern variables, and types used by the
  2066.      scanner.  Only the external API is exported by the header file.
  2067.      Many macros that are usable from within scanner actions are not
  2068.      exported to the header file. This is due to namespace problems and
  2069.      the goal of a clean external API.
  2070.  
  2071.      While in the header, the macro `yyIN_HEADER' is defined, where `yy'
  2072.      is substituted with the appropriate prefix.
  2073.  
  2074.      The `--header-file' option is not compatible with the `--c++'
  2075.      option, since the C++ scanner provides its own header in
  2076.      `yyFlexLexer.h'.
  2077.  
  2078. `-oFILE, --outfile=FILE, `%option outfile="FILE"''
  2079.      directs flex to write the scanner to the file `FILE' instead of
  2080.      `lex.yy.c'.  If you combine `--outfile' with the `--stdout' option,
  2081.      then the scanner is written to `stdout' but its `#line' directives
  2082.      (see the `-l' option above) refer to the file `FILE'.
  2083.  
  2084. `-t, --stdout, `%option stdout''
  2085.      instructs `flex' to write the scanner it generates to standard
  2086.      output instead of `lex.yy.c'.
  2087.  
  2088. `-SFILE, --skel=FILE'
  2089.      overrides the default skeleton file from which `flex' constructs
  2090.      its scanners.  You'll never need this option unless you are doing
  2091.      `flex' maintenance or development.
  2092.  
  2093. `--tables-file=FILE'
  2094.      Write serialized scanner dfa tables to FILE. The generated scanner
  2095.      will not contain the tables, and requires them to be loaded at
  2096.      runtime.  *Note serialization::.
  2097.  
  2098. `--tables-verify'
  2099.      This option is for flex development. We document it here in case
  2100.      you stumble upon it by accident or in case you suspect some
  2101.      inconsistency in the serialized tables.  Flex will serialize the
  2102.      scanner dfa tables but will also generate the in-code tables as it
  2103.      normally does. At runtime, the scanner will verify that the
  2104.      serialized tables match the in-code tables, instead of loading
  2105.      them.
  2106.  
  2107.  
  2108. 
  2109. File: flex,  Node: Options Affecting Scanner Behavior,  Next: Code-Level And API Options,  Prev: Options for Specifing Filenames,  Up: Scanner Options
  2110.  
  2111. 16.2 Options Affecting Scanner Behavior
  2112. =======================================
  2113.  
  2114. `-i, --case-insensitive, `%option case-insensitive''
  2115.      instructs `flex' to generate a "case-insensitive" scanner.  The
  2116.      case of letters given in the `flex' input patterns will be ignored,
  2117.      and tokens in the input will be matched regardless of case.  The
  2118.      matched text given in `yytext' will have the preserved case (i.e.,
  2119.      it will not be folded).  For tricky behavior, see *Note case and
  2120.      character ranges::.
  2121.  
  2122. `-l, --lex-compat, `%option lex-compat''
  2123.      turns on maximum compatibility with the original AT&T `lex'
  2124.      implementation.  Note that this does not mean _full_ compatibility.
  2125.      Use of this option costs a considerable amount of performance, and
  2126.      it cannot be used with the `--c++', `--full', `--fast', `-Cf', or
  2127.      `-CF' options.  For details on the compatibilities it provides, see
  2128.      *Note Lex and Posix::.  This option also results in the name
  2129.      `YY_FLEX_LEX_COMPAT' being `#define''d in the generated scanner.
  2130.  
  2131. `-B, --batch, `%option batch''
  2132.      instructs `flex' to generate a "batch" scanner, the opposite of
  2133.      _interactive_ scanners generated by `--interactive' (see below).
  2134.      In general, you use `-B' when you are _certain_ that your scanner
  2135.      will never be used interactively, and you want to squeeze a
  2136.      _little_ more performance out of it.  If your goal is instead to
  2137.      squeeze out a _lot_ more performance, you should be using the
  2138.      `-Cf' or `-CF' options, which turn on `--batch' automatically
  2139.      anyway.
  2140.  
  2141. `-I, --interactive, `%option interactive''
  2142.      instructs `flex' to generate an interactive scanner.  An
  2143.      interactive scanner is one that only looks ahead to decide what
  2144.      token has been matched if it absolutely must.  It turns out that
  2145.      always looking one extra character ahead, even if the scanner has
  2146.      already seen enough text to disambiguate the current token, is a
  2147.      bit faster than only looking ahead when necessary.  But scanners
  2148.      that always look ahead give dreadful interactive performance; for
  2149.      example, when a user types a newline, it is not recognized as a
  2150.      newline token until they enter _another_ token, which often means
  2151.      typing in another whole line.
  2152.  
  2153.      `flex' scanners default to `interactive' unless you use the `-Cf'
  2154.      or `-CF' table-compression options (*note Performance::).  That's
  2155.      because if you're looking for high-performance you should be using
  2156.      one of these options, so if you didn't, `flex' assumes you'd
  2157.      rather trade off a bit of run-time performance for intuitive
  2158.      interactive behavior.  Note also that you _cannot_ use
  2159.      `--interactive' in conjunction with `-Cf' or `-CF'.  Thus, this
  2160.      option is not really needed; it is on by default for all those
  2161.      cases in which it is allowed.
  2162.  
  2163.      You can force a scanner to _not_ be interactive by using `--batch'
  2164.  
  2165. `-7, --7bit, `%option 7bit''
  2166.      instructs `flex' to generate a 7-bit scanner, i.e., one which can
  2167.      only recognize 7-bit characters in its input.  The advantage of
  2168.      using `--7bit' is that the scanner's tables can be up to half the
  2169.      size of those generated using the `--8bit'.  The disadvantage is
  2170.      that such scanners often hang or crash if their input contains an
  2171.      8-bit character.
  2172.  
  2173.      Note, however, that unless you generate your scanner using the
  2174.      `-Cf' or `-CF' table compression options, use of `--7bit' will
  2175.      save only a small amount of table space, and make your scanner
  2176.      considerably less portable.  `Flex''s default behavior is to
  2177.      generate an 8-bit scanner unless you use the `-Cf' or `-CF', in
  2178.      which case `flex' defaults to generating 7-bit scanners unless
  2179.      your site was always configured to generate 8-bit scanners (as will
  2180.      often be the case with non-USA sites).  You can tell whether flex
  2181.      generated a 7-bit or an 8-bit scanner by inspecting the flag
  2182.      summary in the `--verbose' output as described above.
  2183.  
  2184.      Note that if you use `-Cfe' or `-CFe' `flex' still defaults to
  2185.      generating an 8-bit scanner, since usually with these compression
  2186.      options full 8-bit tables are not much more expensive than 7-bit
  2187.      tables.
  2188.  
  2189. `-8, --8bit, `%option 8bit''
  2190.      instructs `flex' to generate an 8-bit scanner, i.e., one which can
  2191.      recognize 8-bit characters.  This flag is only needed for scanners
  2192.      generated using `-Cf' or `-CF', as otherwise flex defaults to
  2193.      generating an 8-bit scanner anyway.
  2194.  
  2195.      See the discussion of `--7bit' above for `flex''s default behavior
  2196.      and the tradeoffs between 7-bit and 8-bit scanners.
  2197.  
  2198. `--default, `%option default''
  2199.      generate the default rule.
  2200.  
  2201. `--always-interactive, `%option always-interactive''
  2202.      instructs flex to generate a scanner which always considers its
  2203.      input _interactive_.  Normally, on each new input file the scanner
  2204.      calls `isatty()' in an attempt to determine whether the scanner's
  2205.      input source is interactive and thus should be read a character at
  2206.      a time.  When this option is used, however, then no such call is
  2207.      made.
  2208.  
  2209. `--never-interactive, `--never-interactive''
  2210.      instructs flex to generate a scanner which never considers its
  2211.      input interactive.  This is the opposite of `always-interactive'.
  2212.  
  2213. `-X, --posix, `%option posix''
  2214.      turns on maximum compatibility with the POSIX 1003.2-1992
  2215.      definition of `lex'.  Since `flex' was originally designed to
  2216.      implement the POSIX definition of `lex' this generally involves
  2217.      very few changes in behavior.  At the current writing the known
  2218.      differences between `flex' and the POSIX standard are:
  2219.  
  2220.         * In POSIX and AT&T `lex', the repeat operator, `{}', has lower
  2221.           precedence than concatenation (thus `ab{3}' yields `ababab').
  2222.           Most POSIX utilities use an Extended Regular Expression (ERE)
  2223.           precedence that has the precedence of the repeat operator
  2224.           higher than concatenation (which causes `ab{3}' to yield
  2225.           `abbb').  By default, `flex' places the precedence of the
  2226.           repeat operator higher than concatenation which matches the
  2227.           ERE processing of other POSIX utilities.  When either
  2228.           `--posix' or `-l' are specified, `flex' will use the
  2229.           traditional AT&T and POSIX-compliant precedence for the
  2230.           repeat operator where concatenation has higher precedence
  2231.           than the repeat operator.
  2232.  
  2233. `--stack, `%option stack''
  2234.      enables the use of start condition stacks (*note Start
  2235.      Conditions::).
  2236.  
  2237. `--stdinit, `%option stdinit''
  2238.      if set (i.e., %option stdinit) initializes `yyin' and `yyout' to
  2239.      `stdin' and `stdout', instead of the default of `NULL'.  Some
  2240.      existing `lex' programs depend on this behavior, even though it is
  2241.      not compliant with ANSI C, which does not require `stdin' and
  2242.      `stdout' to be compile-time constant. In a reentrant scanner,
  2243.      however, this is not a problem since initialization is performed
  2244.      in `yylex_init' at runtime.
  2245.  
  2246. `--yylineno, `%option yylineno''
  2247.      directs `flex' to generate a scanner that maintains the number of
  2248.      the current line read from its input in the global variable
  2249.      `yylineno'.  This option is implied by `%option lex-compat'.  In a
  2250.      reentrant C scanner, the macro `yylineno' is accessible regardless
  2251.      of the value of `%option yylineno', however, its value is not
  2252.      modified by `flex' unless `%option yylineno' is enabled.
  2253.  
  2254. `--yywrap, `%option yywrap''
  2255.      if unset (i.e., `--noyywrap)', makes the scanner not call
  2256.      `yywrap()' upon an end-of-file, but simply assume that there are no
  2257.      more files to scan (until the user points `yyin' at a new file and
  2258.      calls `yylex()' again).
  2259.  
  2260.  
  2261. 
  2262. File: flex,  Node: Code-Level And API Options,  Next: Options for Scanner Speed and Size,  Prev: Options Affecting Scanner Behavior,  Up: Scanner Options
  2263.  
  2264. 16.3 Code-Level And API Options
  2265. ===============================
  2266.  
  2267. `--ansi-definitions, `%option ansi-definitions''
  2268.      instruct flex to generate ANSI C99 definitions for functions.
  2269.      This option is enabled by default.  If `%option
  2270.      noansi-definitions' is specified, then the obsolete style is
  2271.      generated.
  2272.  
  2273. `--ansi-prototypes, `%option ansi-prototypes''
  2274.      instructs flex to generate ANSI C99 prototypes for functions.
  2275.      This option is enabled by default.  If `noansi-prototypes' is
  2276.      specified, then prototypes will have empty parameter lists.
  2277.  
  2278. `--bison-bridge, `%option bison-bridge''
  2279.      instructs flex to generate a C scanner that is meant to be called
  2280.      by a `GNU bison' parser. The scanner has minor API changes for
  2281.      `bison' compatibility. In particular, the declaration of `yylex'
  2282.      is modified to take an additional parameter, `yylval'.  *Note
  2283.      Bison Bridge::.
  2284.  
  2285. `--bison-locations, `%option bison-locations''
  2286.      instruct flex that `GNU bison' `%locations' are being used.  This
  2287.      means `yylex' will be passed an additional parameter, `yylloc'.
  2288.      This option implies `%option bison-bridge'.  *Note Bison Bridge::.
  2289.  
  2290. `-L, --noline, `%option noline''
  2291.      instructs `flex' not to generate `#line' directives.  Without this
  2292.      option, `flex' peppers the generated scanner with `#line'
  2293.      directives so error messages in the actions will be correctly
  2294.      located with respect to either the original `flex' input file (if
  2295.      the errors are due to code in the input file), or `lex.yy.c' (if
  2296.      the errors are `flex''s fault - you should report these sorts of
  2297.      errors to the email address given in *Note Reporting Bugs::).
  2298.  
  2299. `-R, --reentrant, `%option reentrant''
  2300.      instructs flex to generate a reentrant C scanner.  The generated
  2301.      scanner may safely be used in a multi-threaded environment. The
  2302.      API for a reentrant scanner is different than for a non-reentrant
  2303.      scanner *note Reentrant::).  Because of the API difference between
  2304.      reentrant and non-reentrant `flex' scanners, non-reentrant flex
  2305.      code must be modified before it is suitable for use with this
  2306.      option.  This option is not compatible with the `--c++' option.
  2307.  
  2308.      The option `--reentrant' does not affect the performance of the
  2309.      scanner.
  2310.  
  2311. `-+, --c++, `%option c++''
  2312.      specifies that you want flex to generate a C++ scanner class.
  2313.      *Note Cxx::, for details.
  2314.  
  2315. `--array, `%option array''
  2316.      specifies that you want yytext to be an array instead of a char*
  2317.  
  2318. `--pointer, `%option pointer''
  2319.      specify that  `yytext' should be a `char *', not an array.  This
  2320.      default is `char *'.
  2321.  
  2322. `-PPREFIX, --prefix=PREFIX, `%option prefix="PREFIX"''
  2323.      changes the default `yy' prefix used by `flex' for all
  2324.      globally-visible variable and function names to instead be
  2325.      `PREFIX'.  For example, `--prefix=foo' changes the name of
  2326.      `yytext' to `footext'.  It also changes the name of the default
  2327.      output file from `lex.yy.c' to `lex.foo.c'.  Here is a partial
  2328.      list of the names affected:
  2329.  
  2330.  
  2331.               yy_create_buffer
  2332.               yy_delete_buffer
  2333.               yy_flex_debug
  2334.               yy_init_buffer
  2335.               yy_flush_buffer
  2336.               yy_load_buffer_state
  2337.               yy_switch_to_buffer
  2338.               yyin
  2339.               yyleng
  2340.               yylex
  2341.               yylineno
  2342.               yyout
  2343.               yyrestart
  2344.               yytext
  2345.               yywrap
  2346.               yyalloc
  2347.               yyrealloc
  2348.               yyfree
  2349.  
  2350.      (If you are using a C++ scanner, then only `yywrap' and
  2351.      `yyFlexLexer' are affected.)  Within your scanner itself, you can
  2352.      still refer to the global variables and functions using either
  2353.      version of their name; but externally, they have the modified name.
  2354.  
  2355.      This option lets you easily link together multiple `flex' programs
  2356.      into the same executable.  Note, though, that using this option
  2357.      also renames `yywrap()', so you now _must_ either provide your own
  2358.      (appropriately-named) version of the routine for your scanner, or
  2359.      use `%option noyywrap', as linking with `-lfl' no longer provides
  2360.      one for you by default.
  2361.  
  2362. `--main, `%option main''
  2363.      directs flex to provide a default `main()' program for the
  2364.      scanner, which simply calls `yylex()'.  This option implies
  2365.      `noyywrap' (see below).
  2366.  
  2367. `--nounistd, `%option nounistd''
  2368.      suppresses inclusion of the non-ANSI header file `unistd.h'. This
  2369.      option is meant to target environments in which `unistd.h' does
  2370.      not exist. Be aware that certain options may cause flex to
  2371.      generate code that relies on functions normally found in
  2372.      `unistd.h', (e.g. `isatty()', `read()'.)  If you wish to use these
  2373.      functions, you will have to inform your compiler where to find
  2374.      them.  *Note option-always-interactive::. *Note option-read::.
  2375.  
  2376. `--yyclass, `%option yyclass="NAME"''
  2377.      only applies when generating a C++ scanner (the `--c++' option).
  2378.      It informs `flex' that you have derived `foo' as a subclass of
  2379.      `yyFlexLexer', so `flex' will place your actions in the member
  2380.      function `foo::yylex()' instead of `yyFlexLexer::yylex()'.  It
  2381.      also generates a `yyFlexLexer::yylex()' member function that emits
  2382.      a run-time error (by invoking `yyFlexLexer::LexerError())' if
  2383.      called.  *Note Cxx::.
  2384.  
  2385.  
  2386. 
  2387. File: flex,  Node: Options for Scanner Speed and Size,  Next: Debugging Options,  Prev: Code-Level And API Options,  Up: Scanner Options
  2388.  
  2389. 16.4 Options for Scanner Speed and Size
  2390. =======================================
  2391.  
  2392. `-C[aefFmr]'
  2393.      controls the degree of table compression and, more generally,
  2394.      trade-offs between small scanners and fast scanners.
  2395.  
  2396.     `-C'
  2397.           A lone `-C' specifies that the scanner tables should be
  2398.           compressed but neither equivalence classes nor
  2399.           meta-equivalence classes should be used.
  2400.  
  2401.     `-Ca, --align, `%option align''
  2402.           ("align") instructs flex to trade off larger tables in the
  2403.           generated scanner for faster performance because the elements
  2404.           of the tables are better aligned for memory access and
  2405.           computation.  On some RISC architectures, fetching and
  2406.           manipulating longwords is more efficient than with
  2407.           smaller-sized units such as shortwords.  This option can
  2408.           quadruple the size of the tables used by your scanner.
  2409.  
  2410.     `-Ce, --ecs, `%option ecs''
  2411.           directs `flex' to construct "equivalence classes", i.e., sets
  2412.           of characters which have identical lexical properties (for
  2413.           example, if the only appearance of digits in the `flex' input
  2414.           is in the character class "[0-9]" then the digits '0', '1',
  2415.           ..., '9' will all be put in the same equivalence class).
  2416.           Equivalence classes usually give dramatic reductions in the
  2417.           final table/object file sizes (typically a factor of 2-5) and
  2418.           are pretty cheap performance-wise (one array look-up per
  2419.           character scanned).
  2420.  
  2421.     `-Cf'
  2422.           specifies that the "full" scanner tables should be generated -
  2423.           `flex' should not compress the tables by taking advantages of
  2424.           similar transition functions for different states.
  2425.  
  2426.     `-CF'
  2427.           specifies that the alternate fast scanner representation
  2428.           (described above under the `--fast' flag) should be used.
  2429.           This option cannot be used with `--c++'.
  2430.  
  2431.     `-Cm, --meta-ecs, `%option meta-ecs''
  2432.           directs `flex' to construct "meta-equivalence classes", which
  2433.           are sets of equivalence classes (or characters, if equivalence
  2434.           classes are not being used) that are commonly used together.
  2435.           Meta-equivalence classes are often a big win when using
  2436.           compressed tables, but they have a moderate performance
  2437.           impact (one or two `if' tests and one array look-up per
  2438.           character scanned).
  2439.  
  2440.     `-Cr, --read, `%option read''
  2441.           causes the generated scanner to _bypass_ use of the standard
  2442.           I/O library (`stdio') for input.  Instead of calling
  2443.           `fread()' or `getc()', the scanner will use the `read()'
  2444.           system call, resulting in a performance gain which varies
  2445.           from system to system, but in general is probably negligible
  2446.           unless you are also using `-Cf' or `-CF'.  Using `-Cr' can
  2447.           cause strange behavior if, for example, you read from `yyin'
  2448.           using `stdio' prior to calling the scanner (because the
  2449.           scanner will miss whatever text your previous reads left in
  2450.           the `stdio' input buffer).  `-Cr' has no effect if you define
  2451.           `YY_INPUT()' (*note Generated Scanner::).
  2452.  
  2453.      The options `-Cf' or `-CF' and `-Cm' do not make sense together -
  2454.      there is no opportunity for meta-equivalence classes if the table
  2455.      is not being compressed.  Otherwise the options may be freely
  2456.      mixed, and are cumulative.
  2457.  
  2458.      The default setting is `-Cem', which specifies that `flex' should
  2459.      generate equivalence classes and meta-equivalence classes.  This
  2460.      setting provides the highest degree of table compression.  You can
  2461.      trade off faster-executing scanners at the cost of larger tables
  2462.      with the following generally being true:
  2463.  
  2464.  
  2465.               slowest & smallest
  2466.                     -Cem
  2467.                     -Cm
  2468.                     -Ce
  2469.                     -C
  2470.                     -C{f,F}e
  2471.                     -C{f,F}
  2472.                     -C{f,F}a
  2473.               fastest & largest
  2474.  
  2475.      Note that scanners with the smallest tables are usually generated
  2476.      and compiled the quickest, so during development you will usually
  2477.      want to use the default, maximal compression.
  2478.  
  2479.      `-Cfe' is often a good compromise between speed and size for
  2480.      production scanners.
  2481.  
  2482. `-f, --full, `%option full''
  2483.      specifies "fast scanner".  No table compression is done and
  2484.      `stdio' is bypassed.  The result is large but fast.  This option
  2485.      is equivalent to `--Cfr'
  2486.  
  2487. `-F, --fast, `%option fast''
  2488.      specifies that the _fast_ scanner table representation should be
  2489.      used (and `stdio' bypassed).  This representation is about as fast
  2490.      as the full table representation `--full', and for some sets of
  2491.      patterns will be considerably smaller (and for others, larger).  In
  2492.      general, if the pattern set contains both _keywords_ and a
  2493.      catch-all, _identifier_ rule, such as in the set:
  2494.  
  2495.  
  2496.               "case"    return TOK_CASE;
  2497.               "switch"  return TOK_SWITCH;
  2498.               ...
  2499.               "default" return TOK_DEFAULT;
  2500.               [a-z]+    return TOK_ID;
  2501.  
  2502.      then you're better off using the full table representation.  If
  2503.      only the _identifier_ rule is present and you then use a hash
  2504.      table or some such to detect the keywords, you're better off using
  2505.      `--fast'.
  2506.  
  2507.      This option is equivalent to `-CFr' (see below).  It cannot be used
  2508.      with `--c++'.
  2509.  
  2510.  
  2511. 
  2512. File: flex,  Node: Debugging Options,  Next: Miscellaneous Options,  Prev: Options for Scanner Speed and Size,  Up: Scanner Options
  2513.  
  2514. 16.5 Debugging Options
  2515. ======================
  2516.  
  2517. `-b, --backup, `%option backup''
  2518.      Generate backing-up information to `lex.backup'.  This is a list of
  2519.      scanner states which require backing up and the input characters on
  2520.      which they do so.  By adding rules one can remove backing-up
  2521.      states.  If _all_ backing-up states are eliminated and `-Cf' or
  2522.      `-CF' is used, the generated scanner will run faster (see the
  2523.      `--perf-report' flag).  Only users who wish to squeeze every last
  2524.      cycle out of their scanners need worry about this option.  (*note
  2525.      Performance::).
  2526.  
  2527. `-d, --debug, `%option debug''
  2528.      makes the generated scanner run in "debug" mode.  Whenever a
  2529.      pattern is recognized and the global variable `yy_flex_debug' is
  2530.      non-zero (which is the default), the scanner will write to
  2531.      `stderr' a line of the form:
  2532.  
  2533.  
  2534.               -accepting rule at line 53 ("the matched text")
  2535.  
  2536.      The line number refers to the location of the rule in the file
  2537.      defining the scanner (i.e., the file that was fed to flex).
  2538.      Messages are also generated when the scanner backs up, accepts the
  2539.      default rule, reaches the end of its input buffer (or encounters a
  2540.      NUL; at this point, the two look the same as far as the scanner's
  2541.      concerned), or reaches an end-of-file.
  2542.  
  2543. `-p, --perf-report, `%option perf-report''
  2544.      generates a performance report to `stderr'.  The report consists of
  2545.      comments regarding features of the `flex' input file which will
  2546.      cause a serious loss of performance in the resulting scanner.  If
  2547.      you give the flag twice, you will also get comments regarding
  2548.      features that lead to minor performance losses.
  2549.  
  2550.      Note that the use of `REJECT', and variable trailing context
  2551.      (*note Limitations::) entails a substantial performance penalty;
  2552.      use of `yymore()', the `^' operator, and the `--interactive' flag
  2553.      entail minor performance penalties.
  2554.  
  2555. `-s, --nodefault, `%option nodefault''
  2556.      causes the _default rule_ (that unmatched scanner input is echoed
  2557.      to `stdout)' to be suppressed.  If the scanner encounters input
  2558.      that does not match any of its rules, it aborts with an error.
  2559.      This option is useful for finding holes in a scanner's rule set.
  2560.  
  2561. `-T, --trace, `%option trace''
  2562.      makes `flex' run in "trace" mode.  It will generate a lot of
  2563.      messages to `stderr' concerning the form of the input and the
  2564.      resultant non-deterministic and deterministic finite automata.
  2565.      This option is mostly for use in maintaining `flex'.
  2566.  
  2567. `-w, --nowarn, `%option nowarn''
  2568.      suppresses warning messages.
  2569.  
  2570. `-v, --verbose, `%option verbose''
  2571.      specifies that `flex' should write to `stderr' a summary of
  2572.      statistics regarding the scanner it generates.  Most of the
  2573.      statistics are meaningless to the casual `flex' user, but the
  2574.      first line identifies the version of `flex' (same as reported by
  2575.      `--version'), and the next line the flags used when generating the
  2576.      scanner, including those that are on by default.
  2577.  
  2578. `--warn, `%option warn''
  2579.      warn about certain things. In particular, if the default rule can
  2580.      be matched but no defualt rule has been given, the flex will warn
  2581.      you.  We recommend using this option always.
  2582.  
  2583.  
  2584. 
  2585. File: flex,  Node: Miscellaneous Options,  Prev: Debugging Options,  Up: Scanner Options
  2586.  
  2587. 16.6 Miscellaneous Options
  2588. ==========================
  2589.  
  2590. `-c'
  2591.      is a do-nothing option included for POSIX compliance.
  2592.  
  2593.      generates
  2594.  
  2595. `-h, -?, --help'
  2596.      generates a "help" summary of `flex''s options to `stdout' and
  2597.      then exits.
  2598.  
  2599. `-n'
  2600.      is another do-nothing option included only for POSIX compliance.
  2601.  
  2602. `-V, --version'
  2603.      prints the version number to `stdout' and exits.
  2604.  
  2605.  
  2606. 
  2607. File: flex,  Node: Performance,  Next: Cxx,  Prev: Scanner Options,  Up: Top
  2608.  
  2609. 17 Performance Considerations
  2610. *****************************
  2611.  
  2612. The main design goal of `flex' is that it generate high-performance
  2613. scanners.  It has been optimized for dealing well with large sets of
  2614. rules.  Aside from the effects on scanner speed of the table compression
  2615. `-C' options outlined above, there are a number of options/actions
  2616. which degrade performance.  These are, from most expensive to least:
  2617.  
  2618.  
  2619.          REJECT
  2620.          arbitrary trailing context
  2621.  
  2622.          pattern sets that require backing up
  2623.          %option yylineno
  2624.          %array
  2625.  
  2626.          %option interactive
  2627.          %option always-interactive
  2628.  
  2629.          @samp{^} beginning-of-line operator
  2630.          yymore()
  2631.  
  2632.    with the first two all being quite expensive and the last two being
  2633. quite cheap.  Note also that `unput()' is implemented as a routine call
  2634. that potentially does quite a bit of work, while `yyless()' is a
  2635. quite-cheap macro. So if you are just putting back some excess text you
  2636. scanned, use `ss()'.
  2637.  
  2638.    `REJECT' should be avoided at all costs when performance is
  2639. important.  It is a particularly expensive option.
  2640.  
  2641.    There is one case when `%option yylineno' can be expensive. That is
  2642. when your patterns match long tokens that could _possibly_ contain a
  2643. newline character. There is no performance penalty for rules that can
  2644. not possibly match newlines, since flex does not need to check them for
  2645. newlines.  In general, you should avoid rules such as `[^f]+', which
  2646. match very long tokens, including newlines, and may possibly match your
  2647. entire file! A better approach is to separate `[^f]+' into two rules:
  2648.  
  2649.  
  2650.      %option yylineno
  2651.      %%
  2652.          [^f\n]+
  2653.          \n+
  2654.  
  2655.    The above scanner does not incur a performance penalty.
  2656.  
  2657.    Getting rid of backing up is messy and often may be an enormous
  2658. amount of work for a complicated scanner.  In principal, one begins by
  2659. using the `-b' flag to generate a `lex.backup' file.  For example, on
  2660. the input:
  2661.  
  2662.  
  2663.          %%
  2664.          foo        return TOK_KEYWORD;
  2665.          foobar     return TOK_KEYWORD;
  2666.  
  2667.    the file looks like:
  2668.  
  2669.  
  2670.          State #6 is non-accepting -
  2671.           associated rule line numbers:
  2672.                 2       3
  2673.           out-transitions: [ o ]
  2674.           jam-transitions: EOF [ \001-n  p-\177 ]
  2675.  
  2676.          State #8 is non-accepting -
  2677.           associated rule line numbers:
  2678.                 3
  2679.           out-transitions: [ a ]
  2680.           jam-transitions: EOF [ \001-`  b-\177 ]
  2681.  
  2682.          State #9 is non-accepting -
  2683.           associated rule line numbers:
  2684.                 3
  2685.           out-transitions: [ r ]
  2686.           jam-transitions: EOF [ \001-q  s-\177 ]
  2687.  
  2688.          Compressed tables always back up.
  2689.  
  2690.    The first few lines tell us that there's a scanner state in which it
  2691. can make a transition on an 'o' but not on any other character, and
  2692. that in that state the currently scanned text does not match any rule.
  2693. The state occurs when trying to match the rules found at lines 2 and 3
  2694. in the input file.  If the scanner is in that state and then reads
  2695. something other than an 'o', it will have to back up to find a rule
  2696. which is matched.  With a bit of headscratching one can see that this
  2697. must be the state it's in when it has seen `fo'.  When this has
  2698. happened, if anything other than another `o' is seen, the scanner will
  2699. have to back up to simply match the `f' (by the default rule).
  2700.  
  2701.    The comment regarding State #8 indicates there's a problem when
  2702. `foob' has been scanned.  Indeed, on any character other than an `a',
  2703. the scanner will have to back up to accept "foo".  Similarly, the
  2704. comment for State #9 concerns when `fooba' has been scanned and an `r'
  2705. does not follow.
  2706.  
  2707.    The final comment reminds us that there's no point going to all the
  2708. trouble of removing backing up from the rules unless we're using `-Cf'
  2709. or `-CF', since there's no performance gain doing so with compressed
  2710. scanners.
  2711.  
  2712.    The way to remove the backing up is to add "error" rules:
  2713.  
  2714.  
  2715.          %%
  2716.          foo         return TOK_KEYWORD;
  2717.          foobar      return TOK_KEYWORD;
  2718.  
  2719.          fooba       |
  2720.          foob        |
  2721.          fo          {
  2722.                      /* false alarm, not really a keyword */
  2723.                      return TOK_ID;
  2724.                      }
  2725.  
  2726.    Eliminating backing up among a list of keywords can also be done
  2727. using a "catch-all" rule:
  2728.  
  2729.  
  2730.          %%
  2731.          foo         return TOK_KEYWORD;
  2732.          foobar      return TOK_KEYWORD;
  2733.  
  2734.          [a-z]+      return TOK_ID;
  2735.  
  2736.    This is usually the best solution when appropriate.
  2737.  
  2738.    Backing up messages tend to cascade.  With a complicated set of rules
  2739. it's not uncommon to get hundreds of messages.  If one can decipher
  2740. them, though, it often only takes a dozen or so rules to eliminate the
  2741. backing up (though it's easy to make a mistake and have an error rule
  2742. accidentally match a valid token.  A possible future `flex' feature
  2743. will be to automatically add rules to eliminate backing up).
  2744.  
  2745.    It's important to keep in mind that you gain the benefits of
  2746. eliminating backing up only if you eliminate _every_ instance of
  2747. backing up.  Leaving just one means you gain nothing.
  2748.  
  2749.    _Variable_ trailing context (where both the leading and trailing
  2750. parts do not have a fixed length) entails almost the same performance
  2751. loss as `REJECT' (i.e., substantial).  So when possible a rule like:
  2752.  
  2753.  
  2754.          %%
  2755.          mouse|rat/(cat|dog)   run();
  2756.  
  2757.    is better written:
  2758.  
  2759.  
  2760.          %%
  2761.          mouse/cat|dog         run();
  2762.          rat/cat|dog           run();
  2763.  
  2764.    or as
  2765.  
  2766.  
  2767.          %%
  2768.          mouse|rat/cat         run();
  2769.          mouse|rat/dog         run();
  2770.  
  2771.    Note that here the special '|' action does _not_ provide any
  2772. savings, and can even make things worse (*note Limitations::).
  2773.  
  2774.    Another area where the user can increase a scanner's performance (and
  2775. one that's easier to implement) arises from the fact that the longer the
  2776. tokens matched, the faster the scanner will run.  This is because with
  2777. long tokens the processing of most input characters takes place in the
  2778. (short) inner scanning loop, and does not often have to go through the
  2779. additional work of setting up the scanning environment (e.g., `yytext')
  2780. for the action.  Recall the scanner for C comments:
  2781.  
  2782.  
  2783.          %x comment
  2784.          %%
  2785.                  int line_num = 1;
  2786.  
  2787.          "/*"         BEGIN(comment);
  2788.  
  2789.          <comment>[^*\n]*
  2790.          <comment>"*"+[^*/\n]*
  2791.          <comment>\n             ++line_num;
  2792.          <comment>"*"+"/"        BEGIN(INITIAL);
  2793.  
  2794.    This could be sped up by writing it as:
  2795.  
  2796.  
  2797.          %x comment
  2798.          %%
  2799.                  int line_num = 1;
  2800.  
  2801.          "/*"         BEGIN(comment);
  2802.  
  2803.          <comment>[^*\n]*
  2804.          <comment>[^*\n]*\n      ++line_num;
  2805.          <comment>"*"+[^*/\n]*
  2806.          <comment>"*"+[^*/\n]*\n ++line_num;
  2807.          <comment>"*"+"/"        BEGIN(INITIAL);
  2808.  
  2809.    Now instead of each newline requiring the processing of another
  2810. action, recognizing the newlines is distributed over the other rules to
  2811. keep the matched text as long as possible.  Note that _adding_ rules
  2812. does _not_ slow down the scanner!  The speed of the scanner is
  2813. independent of the number of rules or (modulo the considerations given
  2814. at the beginning of this section) how complicated the rules are with
  2815. regard to operators such as `*' and `|'.
  2816.  
  2817.    A final example in speeding up a scanner: suppose you want to scan
  2818. through a file containing identifiers and keywords, one per line and
  2819. with no other extraneous characters, and recognize all the keywords.  A
  2820. natural first approach is:
  2821.  
  2822.  
  2823.          %%
  2824.          asm      |
  2825.          auto     |
  2826.          break    |
  2827.          ... etc ...
  2828.          volatile |
  2829.          while    /* it's a keyword */
  2830.  
  2831.          .|\n     /* it's not a keyword */
  2832.  
  2833.    To eliminate the back-tracking, introduce a catch-all rule:
  2834.  
  2835.  
  2836.          %%
  2837.          asm      |
  2838.          auto     |
  2839.          break    |
  2840.          ... etc ...
  2841.          volatile |
  2842.          while    /* it's a keyword */
  2843.  
  2844.          [a-z]+   |
  2845.          .|\n     /* it's not a keyword */
  2846.  
  2847.    Now, if it's guaranteed that there's exactly one word per line, then
  2848. we can reduce the total number of matches by a half by merging in the
  2849. recognition of newlines with that of the other tokens:
  2850.  
  2851.  
  2852.          %%
  2853.          asm\n    |
  2854.          auto\n   |
  2855.          break\n  |
  2856.          ... etc ...
  2857.          volatile\n |
  2858.          while\n  /* it's a keyword */
  2859.  
  2860.          [a-z]+\n |
  2861.          .|\n     /* it's not a keyword */
  2862.  
  2863.    One has to be careful here, as we have now reintroduced backing up
  2864. into the scanner.  In particular, while _we_ know that there will never
  2865. be any characters in the input stream other than letters or newlines,
  2866. `flex' can't figure this out, and it will plan for possibly needing to
  2867. back up when it has scanned a token like `auto' and then the next
  2868. character is something other than a newline or a letter.  Previously it
  2869. would then just match the `auto' rule and be done, but now it has no
  2870. `auto' rule, only a `auto\n' rule.  To eliminate the possibility of
  2871. backing up, we could either duplicate all rules but without final
  2872. newlines, or, since we never expect to encounter such an input and
  2873. therefore don't how it's classified, we can introduce one more
  2874. catch-all rule, this one which doesn't include a newline:
  2875.  
  2876.  
  2877.          %%
  2878.          asm\n    |
  2879.          auto\n   |
  2880.          break\n  |
  2881.          ... etc ...
  2882.          volatile\n |
  2883.          while\n  /* it's a keyword */
  2884.  
  2885.          [a-z]+\n |
  2886.          [a-z]+   |
  2887.          .|\n     /* it's not a keyword */
  2888.  
  2889.    Compiled with `-Cf', this is about as fast as one can get a `flex'
  2890. scanner to go for this particular problem.
  2891.  
  2892.    A final note: `flex' is slow when matching `NUL's, particularly when
  2893. a token contains multiple `NUL's.  It's best to write rules which match
  2894. _short_ amounts of text if it's anticipated that the text will often
  2895. include `NUL's.
  2896.  
  2897.    Another final note regarding performance: as mentioned in *Note
  2898. Matching::, dynamically resizing `yytext' to accommodate huge tokens is
  2899. a slow process because it presently requires that the (huge) token be
  2900. rescanned from the beginning.  Thus if performance is vital, you should
  2901. attempt to match "large" quantities of text but not "huge" quantities,
  2902. where the cutoff between the two is at about 8K characters per token.
  2903.  
  2904. 
  2905. File: flex,  Node: Cxx,  Next: Reentrant,  Prev: Performance,  Up: Top
  2906.  
  2907. 18 Generating C++ Scanners
  2908. **************************
  2909.  
  2910. *IMPORTANT*: the present form of the scanning class is _experimental_
  2911. and may change considerably between major releases.
  2912.  
  2913.    `flex' provides two different ways to generate scanners for use with
  2914. C++.  The first way is to simply compile a scanner generated by `flex'
  2915. using a C++ compiler instead of a C compiler.  You should not encounter
  2916. any compilation errors (*note Reporting Bugs::).  You can then use C++
  2917. code in your rule actions instead of C code.  Note that the default
  2918. input source for your scanner remains `yyin', and default echoing is
  2919. still done to `yyout'.  Both of these remain `FILE *' variables and not
  2920. C++ _streams_.
  2921.  
  2922.    You can also use `flex' to generate a C++ scanner class, using the
  2923. `-+' option (or, equivalently, `%option c++)', which is automatically
  2924. specified if the name of the `flex' executable ends in a '+', such as
  2925. `flex++'.  When using this option, `flex' defaults to generating the
  2926. scanner to the file `lex.yy.cc' instead of `lex.yy.c'.  The generated
  2927. scanner includes the header file `FlexLexer.h', which defines the
  2928. interface to two C++ classes.
  2929.  
  2930.    The first class, `FlexLexer', provides an abstract base class
  2931. defining the general scanner class interface.  It provides the
  2932. following member functions:
  2933.  
  2934. `const char* YYText()'
  2935.      returns the text of the most recently matched token, the
  2936.      equivalent of `yytext'.
  2937.  
  2938. `int YYLeng()'
  2939.      returns the length of the most recently matched token, the
  2940.      equivalent of `yyleng'.
  2941.  
  2942. `int lineno() const'
  2943.      returns the current input line number (see `%option yylineno)', or
  2944.      `1' if `%option yylineno' was not used.
  2945.  
  2946. `void set_debug( int flag )'
  2947.      sets the debugging flag for the scanner, equivalent to assigning to
  2948.      `yy_flex_debug' (*note Scanner Options::).  Note that you must
  2949.      build the scannerusing `%option debug' to include debugging
  2950.      information in it.
  2951.  
  2952. `int debug() const'
  2953.      returns the current setting of the debugging flag.
  2954.  
  2955.    Also provided are member functions equivalent to
  2956. `yy_switch_to_buffer()', `yy_create_buffer()' (though the first
  2957. argument is an `istream*' object pointer and not a `FILE*)',
  2958. `yy_flush_buffer()', `yy_delete_buffer()', and `yyrestart()' (again,
  2959. the first argument is a `istream*' object pointer).
  2960.  
  2961.    The second class defined in `FlexLexer.h' is `yyFlexLexer', which is
  2962. derived from `FlexLexer'.  It defines the following additional member
  2963. functions:
  2964.  
  2965. `yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )'
  2966.      constructs a `yyFlexLexer' object using the given streams for input
  2967.      and output.  If not specified, the streams default to `cin' and
  2968.      `cout', respectively.
  2969.  
  2970. `virtual int yylex()'
  2971.      performs the same role is `yylex()' does for ordinary `flex'
  2972.      scanners: it scans the input stream, consuming tokens, until a
  2973.      rule's action returns a value.  If you derive a subclass `S' from
  2974.      `yyFlexLexer' and want to access the member functions and variables
  2975.      of `S' inside `yylex()', then you need to use `%option
  2976.      yyclass="S"' to inform `flex' that you will be using that subclass
  2977.      instead of `yyFlexLexer'.  In this case, rather than generating
  2978.      `yyFlexLexer::yylex()', `flex' generates `S::yylex()' (and also
  2979.      generates a dummy `yyFlexLexer::yylex()' that calls
  2980.      `yyFlexLexer::LexerError()' if called).
  2981.  
  2982. `virtual void switch_streams(istream* new_in = 0, ostream* new_out = 0)'
  2983.      reassigns `yyin' to `new_in' (if non-null) and `yyout' to
  2984.      `new_out' (if non-null), deleting the previous input buffer if
  2985.      `yyin' is reassigned.
  2986.  
  2987. `int yylex( istream* new_in, ostream* new_out = 0 )'
  2988.      first switches the input streams via `switch_streams( new_in,
  2989.      new_out )' and then returns the value of `yylex()'.
  2990.  
  2991.    In addition, `yyFlexLexer' defines the following protected virtual
  2992. functions which you can redefine in derived classes to tailor the
  2993. scanner:
  2994.  
  2995. `virtual int LexerInput( char* buf, int max_size )'
  2996.      reads up to `max_size' characters into `buf' and returns the
  2997.      number of characters read.  To indicate end-of-input, return 0
  2998.      characters.  Note that `interactive' scanners (see the `-B' and
  2999.      `-I' flags in *Note Scanner Options::) define the macro
  3000.      `YY_INTERACTIVE'.  If you redefine `LexerInput()' and need to take
  3001.      different actions depending on whether or not the scanner might be
  3002.      scanning an interactive input source, you can test for the
  3003.      presence of this name via `#ifdef' statements.
  3004.  
  3005. `virtual void LexerOutput( const char* buf, int size )'
  3006.      writes out `size' characters from the buffer `buf', which, while
  3007.      `NUL'-terminated, may also contain internal `NUL's if the
  3008.      scanner's rules can match text with `NUL's in them.
  3009.  
  3010. `virtual void LexerError( const char* msg )'
  3011.      reports a fatal error message.  The default version of this
  3012.      function writes the message to the stream `cerr' and exits.
  3013.  
  3014.    Note that a `yyFlexLexer' object contains its _entire_ scanning
  3015. state.  Thus you can use such objects to create reentrant scanners, but
  3016. see also *Note Reentrant::.  You can instantiate multiple instances of
  3017. the same `yyFlexLexer' class, and you can also combine multiple C++
  3018. scanner classes together in the same program using the `-P' option
  3019. discussed above.
  3020.  
  3021.    Finally, note that the `%array' feature is not available to C++
  3022. scanner classes; you must use `%pointer' (the default).
  3023.  
  3024.    Here is an example of a simple C++ scanner:
  3025.  
  3026.  
  3027.              // An example of using the flex C++ scanner class.
  3028.  
  3029.          %{
  3030.          int mylineno = 0;
  3031.          %}
  3032.  
  3033.          string  \"[^\n"]+\"
  3034.  
  3035.          ws      [ \t]+
  3036.  
  3037.          alpha   [A-Za-z]
  3038.          dig     [0-9]
  3039.          name    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
  3040.          num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
  3041.          num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
  3042.          number  {num1}|{num2}
  3043.  
  3044.          %%
  3045.  
  3046.          {ws}    /* skip blanks and tabs */
  3047.  
  3048.          "/*"    {
  3049.                  int c;
  3050.  
  3051.                  while((c = yyinput()) != 0)
  3052.                      {
  3053.                      if(c == '\n')
  3054.                          ++mylineno;
  3055.  
  3056.                      else if(c == @samp{*})
  3057.                          {
  3058.                          if((c = yyinput()) == '/')
  3059.                              break;
  3060.                          else
  3061.                              unput(c);
  3062.                          }
  3063.                      }
  3064.                  }
  3065.  
  3066.          {number}  cout  "number "  YYText()  '\n';
  3067.  
  3068.          \n        mylineno++;
  3069.  
  3070.          {name}    cout  "name "  YYText()  '\n';
  3071.  
  3072.          {string}  cout  "string "  YYText()  '\n';
  3073.  
  3074.          %%
  3075.  
  3076.          int main( int /* argc */, char** /* argv */ )
  3077.              {
  3078.              @code{flex}Lexer* lexer = new yyFlexLexer;
  3079.              while(lexer->yylex() != 0)
  3080.                  ;
  3081.              return 0;
  3082.              }
  3083.  
  3084.    If you want to create multiple (different) lexer classes, you use the
  3085. `-P' flag (or the `prefix=' option) to rename each `yyFlexLexer' to
  3086. some other `xxFlexLexer'.  You then can include `FlexLexer.h>' in your
  3087. other sources once per lexer class, first renaming `yyFlexLexer' as
  3088. follows:
  3089.  
  3090.  
  3091.          #undef yyFlexLexer
  3092.          #define yyFlexLexer xxFlexLexer
  3093.          #include <FflexLexer.h>
  3094.  
  3095.          #undef yyFlexLexer
  3096.          #define yyFlexLexer zzFlexLexer
  3097.          #include FlexLexer.h>
  3098.  
  3099.    if, for example, you used `%option prefix="xx"' for one of your
  3100. scanners and `%option prefix="zz"' for the other.
  3101.  
  3102. 
  3103. File: flex,  Node: Reentrant,  Next: Lex and Posix,  Prev: Cxx,  Up: Top
  3104.  
  3105. 19 Reentrant C Scanners
  3106. ***********************
  3107.  
  3108. `flex' has the ability to generate a reentrant C scanner. This is
  3109. accomplished by specifying `%option reentrant' (`-R') The generated
  3110. scanner is both portable, and safe to use in one or more separate
  3111. threads of control.  The most common use for reentrant scanners is from
  3112. within multi-threaded applications.  Any thread may create and execute
  3113. a reentrant `flex' scanner without the need for synchronization with
  3114. other threads.
  3115.  
  3116. * Menu:
  3117.  
  3118. * Reentrant Uses::
  3119. * Reentrant Overview::
  3120. * Reentrant Example::
  3121. * Reentrant Detail::
  3122. * Reentrant Functions::
  3123.  
  3124. 
  3125. File: flex,  Node: Reentrant Uses,  Next: Reentrant Overview,  Prev: Reentrant,  Up: Reentrant
  3126.  
  3127. 19.1 Uses for Reentrant Scanners
  3128. ================================
  3129.  
  3130. However, there are other uses for a reentrant scanner.  For example, you
  3131. could scan two or more files simultaneously to implement a `diff' at
  3132. the token level (i.e., instead of at the character level):
  3133.  
  3134.  
  3135.          /* Example of maintaining more than one active scanner. */
  3136.  
  3137.          do {
  3138.              int tok1, tok2;
  3139.  
  3140.              tok1 = yylex( scanner_1 );
  3141.              tok2 = yylex( scanner_2 );
  3142.  
  3143.              if( tok1 != tok2 )
  3144.                  printf("Files are different.");
  3145.  
  3146.         } while ( tok1 && tok2 );
  3147.  
  3148.    Another use for a reentrant scanner is recursion.  (Note that a
  3149. recursive scanner can also be created using a non-reentrant scanner and
  3150. buffer states. *Note Multiple Input Buffers::.)
  3151.  
  3152.    The following crude scanner supports the `eval' command by invoking
  3153. another instance of itself.
  3154.  
  3155.  
  3156.          /* Example of recursive invocation. */
  3157.  
  3158.          %option reentrant
  3159.  
  3160.          %%
  3161.          "eval(".+")"  {
  3162.                            yyscan_t scanner;
  3163.                            YY_BUFFER_STATE buf;
  3164.  
  3165.                            yylex_init( &scanner );
  3166.                            yytext[yyleng-1] = ' ';
  3167.  
  3168.                            buf = yy_scan_string( yytext + 5, scanner );
  3169.                            yylex( scanner );
  3170.  
  3171.                            yy_delete_buffer(buf,scanner);
  3172.                            yylex_destroy( scanner );
  3173.                       }
  3174.          ...
  3175.          %%
  3176.  
  3177. 
  3178. File: flex,  Node: Reentrant Overview,  Next: Reentrant Example,  Prev: Reentrant Uses,  Up: Reentrant
  3179.  
  3180. 19.2 An Overview of the Reentrant API
  3181. =====================================
  3182.  
  3183. The API for reentrant scanners is different than for non-reentrant
  3184. scanners. Here is a quick overview of the API:
  3185.  
  3186.      `%option reentrant' must be specified.
  3187.  
  3188.    * All functions take one additional argument: `yyscanner'
  3189.  
  3190.    * All global variables are replaced by their macro equivalents.  (We
  3191.      tell you this because it may be important to you during debugging.)
  3192.  
  3193.    * `yylex_init' and `yylex_destroy' must be called before and after
  3194.      `yylex', respectively.
  3195.  
  3196.    * Accessor methods (get/set functions) provide access to common
  3197.      `flex' variables.
  3198.  
  3199.    * User-specific data can be stored in `yyextra'.
  3200.  
  3201. 
  3202. File: flex,  Node: Reentrant Example,  Next: Reentrant Detail,  Prev: Reentrant Overview,  Up: Reentrant
  3203.  
  3204. 19.3 Reentrant Example
  3205. ======================
  3206.  
  3207. First, an example of a reentrant scanner: 
  3208.  
  3209.          /* This scanner prints "//" comments. */
  3210.          %option reentrant stack
  3211.          %x COMMENT
  3212.          %%
  3213.          "//"                 yy_push_state( COMMENT, yyscanner);
  3214.          .|\n
  3215.          <COMMENT>\n          yy_pop_state( yyscanner );
  3216.          <COMMENT>[^\n]+      fprintf( yyout, "%s\n", yytext);
  3217.          %%
  3218.          int main ( int argc, char * argv[] )
  3219.          {
  3220.              yyscan_t scanner;
  3221.  
  3222.              yylex_init ( &scanner );
  3223.              yylex ( scanner );
  3224.              yylex_destroy ( scanner );
  3225.          return 0;
  3226.         }
  3227.  
  3228. 
  3229. File: flex,  Node: Reentrant Detail,  Next: Reentrant Functions,  Prev: Reentrant Example,  Up: Reentrant
  3230.  
  3231. 19.4 The Reentrant API in Detail
  3232. ================================
  3233.  
  3234. Here are the things you need to do or know to use the reentrant C API of
  3235. `flex'.
  3236.  
  3237. * Menu:
  3238.  
  3239. * Specify Reentrant::
  3240. * Extra Reentrant Argument::
  3241. * Global Replacement::
  3242. * Init and Destroy Functions::
  3243. * Accessor Methods::
  3244. * Extra Data::
  3245. * About yyscan_t::
  3246.  
  3247. 
  3248. File: flex,  Node: Specify Reentrant,  Next: Extra Reentrant Argument,  Prev: Reentrant Detail,  Up: Reentrant Detail
  3249.  
  3250. 19.4.1 Declaring a Scanner As Reentrant
  3251. ---------------------------------------
  3252.  
  3253. %option reentrant (-reentrant) must be specified.
  3254.  
  3255.    Notice that `%option reentrant' is specified in the above example
  3256. (*note Reentrant Example::. Had this option not been specified, `flex'
  3257. would have happily generated a non-reentrant scanner without
  3258. complaining. You may explicitly specify `%option noreentrant', if you
  3259. do _not_ want a reentrant scanner, although it is not necessary. The
  3260. default is to generate a non-reentrant scanner.
  3261.  
  3262. 
  3263. File: flex,  Node: Extra Reentrant Argument,  Next: Global Replacement,  Prev: Specify Reentrant,  Up: Reentrant Detail
  3264.  
  3265. 19.4.2 The Extra Argument
  3266. -------------------------
  3267.  
  3268. All functions take one additional argument: `yyscanner'.
  3269.  
  3270.    Notice that the calls to `yy_push_state' and `yy_pop_state' both
  3271. have an argument, `yyscanner' , that is not present in a non-reentrant
  3272. scanner.  Here are the declarations of `yy_push_state' and
  3273. `yy_pop_state' in the generated scanner:
  3274.  
  3275.  
  3276.          static void yy_push_state  ( int new_state , yyscan_t yyscanner ) ;
  3277.          static void yy_pop_state  ( yyscan_t yyscanner  ) ;
  3278.  
  3279.    Notice that the argument `yyscanner' appears in the declaration of
  3280. both functions.  In fact, all `flex' functions in a reentrant scanner
  3281. have this additional argument.  It is always the last argument in the
  3282. argument list, it is always of type `yyscan_t' (which is typedef'd to
  3283. `void *') and it is always named `yyscanner'.  As you may have guessed,
  3284. `yyscanner' is a pointer to an opaque data structure encapsulating the
  3285. current state of the scanner.  For a list of function declarations, see
  3286. *Note Reentrant Functions::. Note that preprocessor macros, such as
  3287. `BEGIN', `ECHO', and `REJECT', do not take this additional argument.
  3288.  
  3289. 
  3290. File: flex,  Node: Global Replacement,  Next: Init and Destroy Functions,  Prev: Extra Reentrant Argument,  Up: Reentrant Detail
  3291.  
  3292. 19.4.3 Global Variables Replaced By Macros
  3293. ------------------------------------------
  3294.  
  3295. All global variables in traditional flex have been replaced by macro
  3296. equivalents.
  3297.  
  3298.    Note that in the above example, `yyout' and `yytext' are not plain
  3299. variables. These are macros that will expand to their equivalent lvalue.
  3300. All of the familiar `flex' globals have been replaced by their macro
  3301. equivalents. In particular, `yytext', `yyleng', `yylineno', `yyin',
  3302. `yyout', `yyextra', `yylval', and `yylloc' are macros. You may safely
  3303. use these macros in actions as if they were plain variables. We only
  3304. tell you this so you don't expect to link to these variables
  3305. externally. Currently, each macro expands to a member of an internal
  3306. struct, e.g.,
  3307.  
  3308.  
  3309.      #define yytext (((struct yyguts_t*)yyscanner)->yytext_r)
  3310.  
  3311.    One important thing to remember about `yytext' and friends is that
  3312. `yytext' is not a global variable in a reentrant scanner, you can not
  3313. access it directly from outside an action or from other functions. You
  3314. must use an accessor method, e.g., `yyget_text', to accomplish this.
  3315. (See below).
  3316.  
  3317. 
  3318. File: flex,  Node: Init and Destroy Functions,  Next: Accessor Methods,  Prev: Global Replacement,  Up: Reentrant Detail
  3319.  
  3320. 19.4.4 Init and Destroy Functions
  3321. ---------------------------------
  3322.  
  3323. `yylex_init' and `yylex_destroy' must be called before and after
  3324. `yylex', respectively.
  3325.  
  3326.  
  3327.          int yylex_init ( yyscan_t * ptr_yy_globals ) ;
  3328.          int yylex ( yyscan_t yyscanner ) ;
  3329.          int yylex_destroy ( yyscan_t yyscanner ) ;
  3330.  
  3331.    The function `yylex_init' must be called before calling any other
  3332. function. The argument to `yylex_init' is the address of an
  3333. uninitialized pointer to be filled in by `flex'. The contents of
  3334. `ptr_yy_globals' need not be initialized, since `flex' will overwrite
  3335. it anyway. The value stored in `ptr_yy_globals' should thereafter be
  3336. passed to `yylex()' and yylex_destroy().  Flex does not save the
  3337. argument passed to `yylex_init', so it is safe to pass the address of a
  3338. local pointer to `yylex_init'.  The function `yylex' should be familiar
  3339. to you by now. The reentrant version takes one argument, which is the
  3340. value returned (via an argument) by `yylex_init'.  Otherwise, it
  3341. behaves the same as the non-reentrant version of `yylex'.
  3342.  
  3343.    `yylex_init' returns 0 (zero) on success, or non-zero on failure, in
  3344. which case, errno is set to one of the following values:
  3345.  
  3346.    * ENOMEM Memory allocation error. *Note memory-management::.
  3347.  
  3348.    * EINVAL Invalid argument.
  3349.  
  3350.    The function `yylex_destroy' should be called to free resources used
  3351. by the scanner. After `yylex_destroy' is called, the contents of
  3352. `yyscanner' should not be used.  Of course, there is no need to destroy
  3353. a scanner if you plan to reuse it.  A `flex' scanner (both reentrant
  3354. and non-reentrant) may be restarted by calling `yyrestart'.
  3355.  
  3356.    Below is an example of a program that creates a scanner, uses it,
  3357. then destroys it when done:
  3358.  
  3359.  
  3360.          int main ()
  3361.          {
  3362.              yyscan_t scanner;
  3363.              int tok;
  3364.  
  3365.              yylex_init(&scanner);
  3366.  
  3367.              while ((tok=yylex()) > 0)
  3368.                  printf("tok=%d  yytext=%s\n", tok, yyget_text(scanner));
  3369.  
  3370.              yylex_destroy(scanner);
  3371.              return 0;
  3372.          }
  3373.  
  3374. 
  3375. File: flex,  Node: Accessor Methods,  Next: Extra Data,  Prev: Init and Destroy Functions,  Up: Reentrant Detail
  3376.  
  3377. 19.4.5 Accessing Variables with Reentrant Scanners
  3378. --------------------------------------------------
  3379.  
  3380. Accessor methods (get/set functions) provide access to common `flex'
  3381. variables.
  3382.  
  3383.    Many scanners that you build will be part of a larger project.
  3384. Portions of your project will need access to `flex' values, such as
  3385. `yytext'.  In a non-reentrant scanner, these values are global, so
  3386. there is no problem accessing them. However, in a reentrant scanner,
  3387. there are no global `flex' values. You can not access them directly.
  3388. Instead, you must access `flex' values using accessor methods (get/set
  3389. functions). Each accessor method is named `yyget_NAME' or `yyset_NAME',
  3390. where `NAME' is the name of the `flex' variable you want. For example:
  3391.  
  3392.  
  3393.          /* Set the last character of yytext to NULL. */
  3394.          void chop ( yyscan_t scanner )
  3395.          {
  3396.              int len = yyget_leng( scanner );
  3397.              yyget_text( scanner )[len - 1] = '\0';
  3398.          }
  3399.  
  3400.    The above code may be called from within an action like this:
  3401.  
  3402.  
  3403.          %%
  3404.          .+\n    { chop( yyscanner );}
  3405.  
  3406.    You may find that `%option header-file' is particularly useful for
  3407. generating prototypes of all the accessor functions. *Note
  3408. option-header::.
  3409.  
  3410. 
  3411. File: flex,  Node: Extra Data,  Next: About yyscan_t,  Prev: Accessor Methods,  Up: Reentrant Detail
  3412.  
  3413. 19.4.6 Extra Data
  3414. -----------------
  3415.  
  3416. User-specific data can be stored in `yyextra'.
  3417.  
  3418.    In a reentrant scanner, it is unwise to use global variables to
  3419. communicate with or maintain state between different pieces of your
  3420. program.  However, you may need access to external data or invoke
  3421. external functions from within the scanner actions.  Likewise, you may
  3422. need to pass information to your scanner (e.g., open file descriptors,
  3423. or database connections).  In a non-reentrant scanner, the only way to
  3424. do this would be through the use of global variables.  `Flex' allows
  3425. you to store arbitrary, "extra" data in a scanner.  This data is
  3426. accessible through the accessor methods `yyget_extra' and `yyset_extra'
  3427. from outside the scanner, and through the shortcut macro `yyextra' from
  3428. within the scanner itself. They are defined as follows:
  3429.  
  3430.  
  3431.          #define YY_EXTRA_TYPE  void*
  3432.          YY_EXTRA_TYPE  yyget_extra ( yyscan_t scanner );
  3433.          void           yyset_extra ( YY_EXTRA_TYPE arbitrary_data , yyscan_t scanner);
  3434.  
  3435.    By default, `YY_EXTRA_TYPE' is defined as type `void *'.  You will
  3436. have to cast `yyextra' and the return value from `yyget_extra' to the
  3437. appropriate value each time you access the extra data.  To avoid
  3438. casting, you may override the default type by defining `YY_EXTRA_TYPE'
  3439. in section 1 of your scanner:
  3440.  
  3441.  
  3442.          /* An example of overriding YY_EXTRA_TYPE. */
  3443.          %{
  3444.          #include <sys/stat.h>
  3445.          #include <unistd.h>
  3446.          #define YY_EXTRA_TYPE  struct stat*
  3447.          %}
  3448.          %option reentrant
  3449.          %%
  3450.  
  3451.          __filesize__     printf( "%ld", yyextra->st_size  );
  3452.          __lastmod__      printf( "%ld", yyextra->st_mtime );
  3453.          %%
  3454.          void scan_file( char* filename )
  3455.          {
  3456.              yyscan_t scanner;
  3457.              struct stat buf;
  3458.  
  3459.              yylex_init ( &scanner );
  3460.              yyset_in( fopen(filename,"r"), scanner );
  3461.  
  3462.              stat( filename, &buf);
  3463.              yyset_extra( &buf, scanner );
  3464.              yylex ( scanner );
  3465.              yylex_destroy( scanner );
  3466.         }
  3467.  
  3468. 
  3469. File: flex,  Node: About yyscan_t,  Prev: Extra Data,  Up: Reentrant Detail
  3470.  
  3471. 19.4.7 About yyscan_t
  3472. ---------------------
  3473.  
  3474. `yyscan_t' is defined as:
  3475.  
  3476.  
  3477.           typedef void* yyscan_t;
  3478.  
  3479.    It is initialized by `yylex_init()' to point to an internal
  3480. structure. You should never access this value directly. In particular,
  3481. you should never attempt to free it (use `yylex_destroy()' instead.)
  3482.  
  3483. 
  3484. File: flex,  Node: Reentrant Functions,  Prev: Reentrant Detail,  Up: Reentrant
  3485.  
  3486. 19.5 Functions and Macros Available in Reentrant C Scanners
  3487. ===========================================================
  3488.  
  3489. The following Functions are available in a reentrant scanner:
  3490.  
  3491.  
  3492.          char *yyget_text ( yyscan_t scanner );
  3493.          int yyget_leng ( yyscan_t scanner );
  3494.          FILE *yyget_in ( yyscan_t scanner );
  3495.          FILE *yyget_out ( yyscan_t scanner );
  3496.          int yyget_lineno ( yyscan_t scanner );
  3497.          YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
  3498.          int  yyget_debug ( yyscan_t scanner );
  3499.  
  3500.          void yyset_debug ( int flag, yyscan_t scanner );
  3501.          void yyset_in  ( FILE * in_str , yyscan_t scanner );
  3502.          void yyset_out  ( FILE * out_str , yyscan_t scanner );
  3503.          void yyset_lineno ( int line_number , yyscan_t scanner );
  3504.          void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t scanner );
  3505.  
  3506.    There are no "set" functions for yytext and yyleng. This is
  3507. intentional.
  3508.  
  3509.    The following Macro shortcuts are available in actions in a reentrant
  3510. scanner:
  3511.  
  3512.  
  3513.          yytext
  3514.          yyleng
  3515.          yyin
  3516.          yyout
  3517.          yylineno
  3518.          yyextra
  3519.          yy_flex_debug
  3520.  
  3521.    In a reentrant C scanner, support for yylineno is always present
  3522. (i.e., you may access yylineno), but the value is never modified by
  3523. `flex' unless `%option yylineno' is enabled. This is to allow the user
  3524. to maintain the line count independently of `flex'.
  3525.  
  3526.    The following functions and macros are made available when `%option
  3527. bison-bridge' (`--bison-bridge') is specified:
  3528.  
  3529.  
  3530.          YYSTYPE * yyget_lval ( yyscan_t scanner );
  3531.          void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner );
  3532.          yylval
  3533.  
  3534.    The following functions and macros are made available when `%option
  3535. bison-locations' (`--bison-locations') is specified:
  3536.  
  3537.  
  3538.          YYLTYPE *yyget_lloc ( yyscan_t scanner );
  3539.          void yyset_lloc ( YYLTYPE * yyllocp , yyscan_t scanner );
  3540.          yylloc
  3541.  
  3542.    Support for yylval assumes that `YYSTYPE' is a valid type.  Support
  3543. for yylloc assumes that `YYSLYPE' is a valid type.  Typically, these
  3544. types are generated by `bison', and are included in section 1 of the
  3545. `flex' input.
  3546.  
  3547. 
  3548. File: flex,  Node: Lex and Posix,  Next: Memory Management,  Prev: Reentrant,  Up: Top
  3549.  
  3550. 20 Incompatibilities with Lex and Posix
  3551. ***************************************
  3552.  
  3553. `flex' is a rewrite of the AT&T Unix _lex_ tool (the two
  3554. implementations do not share any code, though), with some extensions and
  3555. incompatibilities, both of which are of concern to those who wish to
  3556. write scanners acceptable to both implementations.  `flex' is fully
  3557. compliant with the POSIX `lex' specification, except that when using
  3558. `%pointer' (the default), a call to `unput()' destroys the contents of
  3559. `yytext', which is counter to the POSIX specification.  In this section
  3560. we discuss all of the known areas of incompatibility between `flex',
  3561. AT&T `lex', and the POSIX specification.  `flex''s `-l' option turns on
  3562. maximum compatibility with the original AT&T `lex' implementation, at
  3563. the cost of a major loss in the generated scanner's performance.  We
  3564. note below which incompatibilities can be overcome using the `-l'
  3565. option.  `flex' is fully compatible with `lex' with the following
  3566. exceptions:
  3567.  
  3568.    * The undocumented `lex' scanner internal variable `yylineno' is not
  3569.      supported unless `-l' or `%option yylineno' is used.
  3570.  
  3571.    * `yylineno' should be maintained on a per-buffer basis, rather than
  3572.      a per-scanner (single global variable) basis.
  3573.  
  3574.    * `yylineno' is not part of the POSIX specification.
  3575.  
  3576.    * The `input()' routine is not redefinable, though it may be called
  3577.      to read characters following whatever has been matched by a rule.
  3578.      If `input()' encounters an end-of-file the normal `yywrap()'
  3579.      processing is done.  A "real" end-of-file is returned by `input()'
  3580.      as `EOF'.
  3581.  
  3582.    * Input is instead controlled by defining the `YY_INPUT()' macro.
  3583.  
  3584.    * The `flex' restriction that `input()' cannot be redefined is in
  3585.      accordance with the POSIX specification, which simply does not
  3586.      specify any way of controlling the scanner's input other than by
  3587.      making an initial assignment to `yyin'.
  3588.  
  3589.    * The `unput()' routine is not redefinable.  This restriction is in
  3590.      accordance with POSIX.
  3591.  
  3592.    * `flex' scanners are not as reentrant as `lex' scanners.  In
  3593.      particular, if you have an interactive scanner and an interrupt
  3594.      handler which long-jumps out of the scanner, and the scanner is
  3595.      subsequently called again, you may get the following message:
  3596.  
  3597.  
  3598.               fatal @code{flex} scanner internal error--end of buffer missed
  3599.  
  3600.      To reenter the scanner, first use:
  3601.  
  3602.  
  3603.               yyrestart( yyin );
  3604.  
  3605.      Note that this call will throw away any buffered input; usually
  3606.      this isn't a problem with an interactive scanner. *Note
  3607.      Reentrant::, for `flex''s reentrant API.
  3608.  
  3609.    * Also note that `flex' C++ scanner classes _are_ reentrant, so if
  3610.      using C++ is an option for you, you should use them instead.
  3611.      *Note Cxx::, and *Note Reentrant::  for details.
  3612.  
  3613.    * `output()' is not supported.  Output from the ECHO macro is done
  3614.      to the file-pointer `yyout' (default `stdout)'.
  3615.  
  3616.    * `output()' is not part of the POSIX specification.
  3617.  
  3618.    * `lex' does not support exclusive start conditions (%x), though they
  3619.      are in the POSIX specification.
  3620.  
  3621.    * When definitions are expanded, `flex' encloses them in parentheses.
  3622.      With `lex', the following:
  3623.  
  3624.  
  3625.               NAME    [A-Z][A-Z0-9]*
  3626.               %%
  3627.               foo{NAME}?      printf( "Found it\n" );
  3628.               %%
  3629.  
  3630.      will not match the string `foo' because when the macro is expanded
  3631.      the rule is equivalent to `foo[A-Z][A-Z0-9]*?'  and the precedence
  3632.      is such that the `?' is associated with `[A-Z0-9]*'.  With `flex',
  3633.      the rule will be expanded to `foo([A-Z][A-Z0-9]*)?' and so the
  3634.      string `foo' will match.
  3635.  
  3636.    * Note that if the definition begins with `^' or ends with `$' then
  3637.      it is _not_ expanded with parentheses, to allow these operators to
  3638.      appear in definitions without losing their special meanings.  But
  3639.      the `<s>', `/', and `<<EOF>>' operators cannot be used in a `flex'
  3640.      definition.
  3641.  
  3642.    * Using `-l' results in the `lex' behavior of no parentheses around
  3643.      the definition.
  3644.  
  3645.    * The POSIX specification is that the definition be enclosed in
  3646.      parentheses.
  3647.  
  3648.    * Some implementations of `lex' allow a rule's action to begin on a
  3649.      separate line, if the rule's pattern has trailing whitespace:
  3650.  
  3651.  
  3652.               %%
  3653.               foo|bar<space here>
  3654.                 { foobar_action();}
  3655.  
  3656.      `flex' does not support this feature.
  3657.  
  3658.    * The `lex' `%r' (generate a Ratfor scanner) option is not
  3659.      supported.  It is not part of the POSIX specification.
  3660.  
  3661.    * After a call to `unput()', _yytext_ is undefined until the next
  3662.      token is matched, unless the scanner was built using `%array'.
  3663.      This is not the case with `lex' or the POSIX specification.  The
  3664.      `-l' option does away with this incompatibility.
  3665.  
  3666.    * The precedence of the `{,}' (numeric range) operator is different.
  3667.      The AT&T and POSIX specifications of `lex' interpret `abc{1,3}'
  3668.      as match one, two, or three occurrences of `abc'", whereas `flex'
  3669.      interprets it as "match `ab' followed by one, two, or three
  3670.      occurrences of `c'".  The `-l' and `--posix' options do away with
  3671.      this incompatibility.
  3672.  
  3673.    * The precedence of the `^' operator is different.  `lex' interprets
  3674.      `^foo|bar' as "match either 'foo' at the beginning of a line, or
  3675.      'bar' anywhere", whereas `flex' interprets it as "match either
  3676.      `foo' or `bar' if they come at the beginning of a line".  The
  3677.      latter is in agreement with the POSIX specification.
  3678.  
  3679.    * The special table-size declarations such as `%a' supported by
  3680.      `lex' are not required by `flex' scanners..  `flex' ignores them.
  3681.  
  3682.    * The name `FLEX_SCANNER' is `#define''d so scanners may be written
  3683.      for use with either `flex' or `lex'.  Scanners also include
  3684.      `YY_FLEX_MAJOR_VERSION',  `YY_FLEX_MINOR_VERSION' and
  3685.      `YY_FLEX_SUBMINOR_VERSION' indicating which version of `flex'
  3686.      generated the scanner. For example, for the 2.5.22 release, these
  3687.      defines would be 2,  5 and 22 respectively. If the version of
  3688.      `flex' being used is a beta version, then the symbol `FLEX_BETA'
  3689.      is defined.
  3690.  
  3691.    The following `flex' features are not included in `lex' or the POSIX
  3692. specification:
  3693.  
  3694.    * C++ scanners
  3695.  
  3696.    * %option
  3697.  
  3698.    * start condition scopes
  3699.  
  3700.    * start condition stacks
  3701.  
  3702.    * interactive/non-interactive scanners
  3703.  
  3704.    * yy_scan_string() and friends
  3705.  
  3706.    * yyterminate()
  3707.  
  3708.    * yy_set_interactive()
  3709.  
  3710.    * yy_set_bol()
  3711.  
  3712.    * YY_AT_BOL()    <<EOF>>
  3713.  
  3714.    * <*>
  3715.  
  3716.    * YY_DECL
  3717.  
  3718.    * YY_START
  3719.  
  3720.    * YY_USER_ACTION
  3721.  
  3722.    * YY_USER_INIT
  3723.  
  3724.    * #line directives
  3725.  
  3726.    * %{}'s around actions
  3727.  
  3728.    * reentrant C API
  3729.  
  3730.    * multiple actions on a line
  3731.  
  3732.    * almost all of the `flex' command-line options
  3733.  
  3734.    The feature "multiple actions on a line" refers to the fact that
  3735. with `flex' you can put multiple actions on the same line, separated
  3736. with semi-colons, while with `lex', the following:
  3737.  
  3738.  
  3739.          foo    handle_foo(); ++num_foos_seen;
  3740.  
  3741.    is (rather surprisingly) truncated to
  3742.  
  3743.  
  3744.          foo    handle_foo();
  3745.  
  3746.    `flex' does not truncate the action.  Actions that are not enclosed
  3747. in braces are simply terminated at the end of the line.
  3748.  
  3749. 
  3750. File: flex,  Node: Memory Management,  Next: Serialized Tables,  Prev: Lex and Posix,  Up: Top
  3751.  
  3752. 21 Memory Management
  3753. ********************
  3754.  
  3755. This chapter describes how flex handles dynamic memory, and how you can
  3756. override the default behavior.
  3757.  
  3758. * Menu:
  3759.  
  3760. * The Default Memory Management::
  3761. * Overriding The Default Memory Management::
  3762. * A Note About yytext And Memory::
  3763.  
  3764. 
  3765. File: flex,  Node: The Default Memory Management,  Next: Overriding The Default Memory Management,  Prev: Memory Management,  Up: Memory Management
  3766.  
  3767. 21.1 The Default Memory Management
  3768. ==================================
  3769.  
  3770. Flex allocates dynamic memory during initialization, and once in a
  3771. while from within a call to yylex(). Initialization takes place during
  3772. the first call to yylex(). Thereafter, flex may reallocate more memory
  3773. if it needs to enlarge a buffer. As of version 2.5.9 Flex will clean up
  3774. all memory when you call `yylex_destroy' *Note faq-memory-leak::.
  3775.  
  3776.    Flex allocates dynamic memory for four purposes, listed below (1)
  3777.  
  3778. 16kB for the input buffer.
  3779.      Flex allocates memory for the character buffer used to perform
  3780.      pattern matching.  Flex must read ahead from the input stream and
  3781.      store it in a large character buffer.  This buffer is typically
  3782.      the largest chunk of dynamic memory flex consumes. This buffer
  3783.      will grow if necessary, doubling the size each time.  Flex frees
  3784.      this memory when you call yylex_destroy().  The default size of
  3785.      this buffer (16384 bytes) is almost always too large.  The ideal
  3786.      size for this buffer is the length of the longest token expected.
  3787.      Flex will allocate a few extra bytes for housekeeping.
  3788.  
  3789. 16kb for the REJECT state. This will only be allocated if you use REJECT.
  3790.      The size is the same as the input buffer, so if you override the
  3791.      size of the input buffer, then you automatically override the size
  3792.      of this buffer as well.
  3793.  
  3794. 100 bytes for the start condition stack.
  3795.      Flex allocates memory for the start condition stack. This is the
  3796.      stack used for pushing start states, i.e., with yy_push_state().
  3797.      It will grow if necessary.  Since the states are simply integers,
  3798.      this stack doesn't consume much memory.  This stack is not present
  3799.      if `%option stack' is not specified.  You will rarely need to tune
  3800.      this buffer. The ideal size for this stack is the maximum depth
  3801.      expected.  The memory for this stack is automatically destroyed
  3802.      when you call yylex_destroy(). *Note option-stack::.
  3803.  
  3804. 40 bytes for each YY_BUFFER_STATE.
  3805.      Flex allocates memory for each YY_BUFFER_STATE. The buffer state
  3806.      itself is about 40 bytes, plus an additional large character
  3807.      buffer (described above.)  The initial buffer state is created
  3808.      during initialization, and with each call to yy_create_buffer().
  3809.      You can't tune the size of this, but you can tune the character
  3810.      buffer as described above. Any buffer state that you explicitly
  3811.      create by calling yy_create_buffer() is _NOT_ destroyed
  3812.      automatically. You must call yy_delete_buffer() to free the
  3813.      memory. The exception to this rule is that flex will delete the
  3814.      current buffer automatically when you call yylex_destroy(). If you
  3815.      delete the current buffer, be sure to set it to NULL.  That way,
  3816.      flex will not try to delete the buffer a second time (possibly
  3817.      crashing your program!) At the time of this writing, flex does not
  3818.      provide a growable stack for the buffer states.  You have to
  3819.      manage that yourself.  *Note Multiple Input Buffers::.
  3820.  
  3821. 84 bytes for the reentrant scanner guts
  3822.      Flex allocates about 84 bytes for the reentrant scanner structure
  3823.      when you call yylex_init(). It is destroyed when the user calls
  3824.      yylex_destroy().
  3825.  
  3826.  
  3827.    ---------- Footnotes ----------
  3828.  
  3829.    (1) The quantities given here are approximate, and may vary due to
  3830. host architecture, compiler configuration, or due to future
  3831. enhancements to flex.
  3832.  
  3833. 
  3834. File: flex,  Node: Overriding The Default Memory Management,  Next: A Note About yytext And Memory,  Prev: The Default Memory Management,  Up: Memory Management
  3835.  
  3836. 21.2 Overriding The Default Memory Management
  3837. =============================================
  3838.  
  3839. Flex calls the functions `yyalloc', `yyrealloc', and `yyfree' when it
  3840. needs to allocate or free memory. By default, these functions are
  3841. wrappers around the standard C functions, `malloc', `realloc', and
  3842. `free', respectively. You can override the default implementations by
  3843. telling flex that you will provide your own implementations.
  3844.  
  3845.    To override the default implementations, you must do two things:
  3846.  
  3847.   1. Suppress the default implementations by specifying one or more of
  3848.      the following options:
  3849.  
  3850.         * `%option noyyalloc'
  3851.  
  3852.         * `%option noyyrealloc'
  3853.  
  3854.         * `%option noyyfree'.
  3855.  
  3856.   2. Provide your own implementation of the following functions: (1)
  3857.  
  3858.  
  3859.           // For a non-reentrant scanner
  3860.           void * yyalloc (size_t bytes);
  3861.           void * yyrealloc (void * ptr, size_t bytes);
  3862.           void   yyfree (void * ptr);
  3863.  
  3864.           // For a reentrant scanner
  3865.           void * yyalloc (size_t bytes, void * yyscanner);
  3866.           void * yyrealloc (void * ptr, size_t bytes, void * yyscanner);
  3867.           void   yyfree (void * ptr, void * yyscanner);
  3868.  
  3869.  
  3870.    In the following example, we will override all three memory
  3871. routines. We assume that there is a custom allocator with garbage
  3872. collection. In order to make this example interesting, we will use a
  3873. reentrant scanner, passing a pointer to the custom allocator through
  3874. `yyextra'.
  3875.  
  3876.  
  3877.      %{
  3878.      #include "some_allocator.h"
  3879.      %}
  3880.  
  3881.      /* Suppress the default implementations. */
  3882.      %option noyyalloc noyyrealloc noyyfree
  3883.      %option reentrant
  3884.  
  3885.      /* Initialize the allocator. */
  3886.      #define YY_EXTRA_TYPE  struct allocator*
  3887.      #define YY_USER_INIT  yyextra = allocator_create();
  3888.  
  3889.      %%
  3890.      .|\n   ;
  3891.      %%
  3892.  
  3893.      /* Provide our own implementations. */
  3894.      void * yyalloc (size_t bytes, void* yyscanner) {
  3895.          return allocator_alloc (yyextra, bytes);
  3896.      }
  3897.  
  3898.      void * yyrealloc (void * ptr, size_t bytes, void* yyscanner) {
  3899.          return allocator_realloc (yyextra, bytes);
  3900.      }
  3901.  
  3902.      void yyfree (void * ptr, void * yyscanner) {
  3903.          /* Do nothing -- we leave it to the garbage collector. */
  3904.      }
  3905.  
  3906.    ---------- Footnotes ----------
  3907.  
  3908.    (1) It is not necessary to override all (or any) of the memory
  3909. management routines.  You may, for example, override `yyrealloc', but
  3910. not `yyfree' or `yyalloc'.
  3911.  
  3912. 
  3913. File: flex,  Node: A Note About yytext And Memory,  Prev: Overriding The Default Memory Management,  Up: Memory Management
  3914.  
  3915. 21.3 A Note About yytext And Memory
  3916. ===================================
  3917.  
  3918. When flex finds a match, `yytext' points to the first character of the
  3919. match in the input buffer. The string itself is part of the input
  3920. buffer, and is _NOT_ allocated separately. The value of yytext will be
  3921. overwritten the next time yylex() is called. In short, the value of
  3922. yytext is only valid from within the matched rule's action.
  3923.  
  3924.    Often, you want the value of yytext to persist for later processing,
  3925. i.e., by a parser with non-zero lookahead. In order to preserve yytext,
  3926. you will have to copy it with strdup() or a similar function. But this
  3927. introduces some headache because your parser is now responsible for
  3928. freeing the copy of yytext. If you use a yacc or bison parser,
  3929. (commonly used with flex), you will discover that the error recovery
  3930. mechanisms can cause memory to be leaked.
  3931.  
  3932.    To prevent memory leaks from strdup'd yytext, you will have to track
  3933. the memory somehow. Our experience has shown that a garbage collection
  3934. mechanism or a pooled memory mechanism will save you a lot of grief
  3935. when writing parsers.
  3936.  
  3937. 
  3938. File: flex,  Node: Serialized Tables,  Next: Diagnostics,  Prev: Memory Management,  Up: Top
  3939.  
  3940. 22 Serialized Tables
  3941. ********************
  3942.  
  3943. A `flex' scanner has the ability to save the DFA tables to a file, and
  3944. load them at runtime when needed.  The motivation for this feature is
  3945. to reduce the runtime memory footprint.  Traditionally, these tables
  3946. have been compiled into the scanner as C arrays, and are sometimes
  3947. quite large.  Since the tables are compiled into the scanner, the
  3948. memory used by the tables can never be freed.  This is a waste of
  3949. memory, especially if an application uses several scanners, but none of
  3950. them at the same time.
  3951.  
  3952.    The serialization feature allows the tables to be loaded at runtime,
  3953. before scanning begins. The tables may be discarded when scanning is
  3954. finished.
  3955.  
  3956. * Menu:
  3957.  
  3958. * Creating Serialized Tables::
  3959. * Loading and Unloading Serialized Tables::
  3960. * Tables File Format::
  3961.  
  3962. 
  3963. File: flex,  Node: Creating Serialized Tables,  Next: Loading and Unloading Serialized Tables,  Prev: Serialized Tables,  Up: Serialized Tables
  3964.  
  3965. 22.1 Creating Serialized Tables
  3966. ===============================
  3967.  
  3968. You may create a scanner with serialized tables by specifying:
  3969.  
  3970.  
  3971.          %option tables-file=FILE
  3972.      or
  3973.          --tables-file=FILE
  3974.  
  3975.    These options instruct flex to save the DFA tables to the file FILE.
  3976. The tables will _not_ be embedded in the generated scanner. The scanner
  3977. will not function on its own. The scanner will be dependent upon the
  3978. serialized tables. You must load the tables from this file at runtime
  3979. before you can scan anything.
  3980.  
  3981.    If you do not specify a filename to `--tables-file', the tables will
  3982. be saved to `lex.yy.tables', where `yy' is the appropriate prefix.
  3983.  
  3984.    If your project uses several different scanners, you can concatenate
  3985. the serialized tables into one file, and flex will find the correct set
  3986. of tables, using the scanner prefix as part of the lookup key. An
  3987. example follows:
  3988.  
  3989.  
  3990.      $ flex --tables-file --prefix=cpp cpp.l
  3991.      $ flex --tables-file --prefix=c   c.l
  3992.      $ cat lex.cpp.tables lex.c.tables  >  all.tables
  3993.  
  3994.    The above example created two scanners, `cpp', and `c'. Since we did
  3995. not specify a filename, the tables were serialized to `lex.c.tables' and
  3996. `lex.cpp.tables', respectively. Then, we concatenated the two files
  3997. together into `all.tables', which we will distribute with our project.
  3998. At runtime, we will open the file and tell flex to load the tables from
  3999. it.  Flex will find the correct tables automatically. (See next
  4000. section).
  4001.  
  4002. 
  4003. File: flex,  Node: Loading and Unloading Serialized Tables,  Next: Tables File Format,  Prev: Creating Serialized Tables,  Up: Serialized Tables
  4004.  
  4005. 22.2 Loading and Unloading Serialized Tables
  4006. ============================================
  4007.  
  4008. If you've built your scanner with `%option tables-file', then you must
  4009. load the scanner tables at runtime. This can be accomplished with the
  4010. following function:
  4011.  
  4012.  -- Function: int yytables_fload (FILE* FP [, yyscan_t SCANNER])
  4013.      Locates scanner tables in the stream pointed to by FP and loads
  4014.      them.  Memory for the tables is allocated via `yyalloc'.  You must
  4015.      call this function before the first call to `yylex'. The argument
  4016.      SCANNER only appears in the reentrant scanner.  This function
  4017.      returns `0' (zero) on success, or non-zero on error.
  4018.  
  4019.    The loaded tables are *not* automatically destroyed (unloaded) when
  4020. you call `yylex_destroy'. The reason is that you may create several
  4021. scanners of the same type (in a reentrant scanner), each of which needs
  4022. access to these tables.  To avoid a nasty memory leak, you must call
  4023. the following function:
  4024.  
  4025.  -- Function: int yytables_destroy ([yyscan_t SCANNER])
  4026.      Unloads the scanner tables. The tables must be loaded again before
  4027.      you can scan any more data.  The argument SCANNER only appears in
  4028.      the reentrant scanner.  This function returns `0' (zero) on
  4029.      success, or non-zero on error.
  4030.  
  4031.    *The functions `yytables_fload' and `yytables_destroy' are not
  4032. thread-safe.* You must ensure that these functions are called exactly
  4033. once (for each scanner type) in a threaded program, before any thread
  4034. calls `yylex'.  After the tables are loaded, they are never written to,
  4035. and no thread protection is required thereafter - until you destroy
  4036. them.
  4037.  
  4038. 
  4039. File: flex,  Node: Tables File Format,  Prev: Loading and Unloading Serialized Tables,  Up: Serialized Tables
  4040.  
  4041. 22.3 Tables File Format
  4042. =======================
  4043.  
  4044. This section defines the file format of serialized `flex' tables.
  4045.  
  4046.    The tables format allows for one or more sets of tables to be
  4047. specified, where each set corresponds to a given scanner. Scanners are
  4048. indexed by name, as described below. The file format is as follows:
  4049.  
  4050.  
  4051.                       TABLE SET 1
  4052.                      +-------------------------------+
  4053.              Header  | uint32          th_magic;     |
  4054.                      | uint32          th_hsize;     |
  4055.                      | uint32          th_ssize;     |
  4056.                      | uint16          th_flags;     |
  4057.                      | char            th_version[]; |
  4058.                      | char            th_name[];    |
  4059.                      | uint8           th_pad64[];   |
  4060.                      +-------------------------------+
  4061.              Table 1 | uint16          td_id;        |
  4062.                      | uint16          td_flags;     |
  4063.                      | uint32          td_lolen;     |
  4064.                      | uint32          td_hilen;     |
  4065.                      | void            td_data[];    |
  4066.                      | uint8           td_pad64[];   |
  4067.                      +-------------------------------+
  4068.              Table 2 |                               |
  4069.                 .    .                               .
  4070.                 .    .                               .
  4071.                 .    .                               .
  4072.                 .    .                               .
  4073.              Table n |                               |
  4074.                      +-------------------------------+
  4075.                       TABLE SET 2
  4076.                            .
  4077.                            .
  4078.                            .
  4079.                       TABLE SET N
  4080.  
  4081.    The above diagram shows that a complete set of tables consists of a
  4082. header followed by multiple individual tables. Furthermore, multiple
  4083. complete sets may be present in the same file, each set with its own
  4084. header and tables. The sets are contiguous in the file. The only way to
  4085. know if another set follows is to check the next four bytes for the
  4086. magic number (or check for EOF). The header and tables sections are
  4087. padded to 64-bit boundaries. Below we describe each field in detail.
  4088. This format does not specify how the scanner will expand the given
  4089. data, i.e., data may be serialized as int8, but expanded to an int32
  4090. array at runtime. This is to reduce the size of the serialized data
  4091. where possible.  Remember, _all integer values are in network byte
  4092. order_.
  4093.  
  4094. Fields of a table header:
  4095.  
  4096. `th_magic'
  4097.      Magic number, always 0xF13C57B1.
  4098.  
  4099. `th_hsize'
  4100.      Size of this entire header, in bytes, including all fields plus
  4101.      any padding.
  4102.  
  4103. `th_ssize'
  4104.      Size of this entire set, in bytes, including the header, all
  4105.      tables, plus any padding.
  4106.  
  4107. `th_flags'
  4108.      Bit flags for this table set. Currently unused.
  4109.  
  4110. `th_version[]'
  4111.      Flex version in NULL-termninated string format. e.g., `2.5.13a'.
  4112.      This is the version of flex that was used to create the serialized
  4113.      tables.
  4114.  
  4115. `th_name[]'
  4116.      Contains the name of this table set. The default is `yytables',
  4117.      and is prefixed accordingly, e.g., `footables'. Must be
  4118.      NULL-terminated.
  4119.  
  4120. `th_pad64[]'
  4121.      Zero or more NULL bytes, padding the entire header to the next
  4122.      64-bit boundary as calculated from the beginning of the header.
  4123.  
  4124. Fields of a table:
  4125.  
  4126. `td_id'
  4127.      Specifies the table identifier. Possible values are:
  4128.     `YYTD_ID_ACCEPT (0x01)'
  4129.           `yy_accept'
  4130.  
  4131.     `YYTD_ID_BASE   (0x02)'
  4132.           `yy_base'
  4133.  
  4134.     `YYTD_ID_CHK    (0x03)'
  4135.           `yy_chk'
  4136.  
  4137.     `YYTD_ID_DEF    (0x04)'
  4138.           `yy_def'
  4139.  
  4140.     `YYTD_ID_EC     (0x05)'
  4141.           `yy_ec '
  4142.  
  4143.     `YYTD_ID_META   (0x06)'
  4144.           `yy_meta'
  4145.  
  4146.     `YYTD_ID_NUL_TRANS (0x07)'
  4147.           `yy_NUL_trans'
  4148.  
  4149.     `YYTD_ID_NXT (0x08)'
  4150.           `yy_nxt'. This array may be two dimensional. See the
  4151.           `td_hilen' field below.
  4152.  
  4153.     `YYTD_ID_RULE_CAN_MATCH_EOL (0x09)'
  4154.           `yy_rule_can_match_eol'
  4155.  
  4156.     `YYTD_ID_START_STATE_LIST (0x0A)'
  4157.           `yy_start_state_list'. This array is handled specially
  4158.           because it is an array of pointers to structs. See the
  4159.           `td_flags' field below.
  4160.  
  4161.     `YYTD_ID_TRANSITION (0x0B)'
  4162.           `yy_transition'. This array is handled specially because it
  4163.           is an array of structs. See the `td_lolen' field below.
  4164.  
  4165.     `YYTD_ID_ACCLIST (0x0C)'
  4166.           `yy_acclist'
  4167.  
  4168. `td_flags'
  4169.      Bit flags describing how to interpret the data in `td_data'.  The
  4170.      data arrays are one-dimensional by default, but may be two
  4171.      dimensional as specified in the `td_hilen' field.
  4172.  
  4173.     `YYTD_DATA8 (0x01)'
  4174.           The data is serialized as an array of type int8.
  4175.  
  4176.     `YYTD_DATA16 (0x02)'
  4177.           The data is serialized as an array of type int16.
  4178.  
  4179.     `YYTD_DATA32 (0x04)'
  4180.           The data is serialized as an array of type int32.
  4181.  
  4182.     `YYTD_PTRANS (0x08)'
  4183.           The data is a list of indexes of entries in the expanded
  4184.           `yy_transition' array.  Each index should be expanded to a
  4185.           pointer to the corresponding entry in the `yy_transition'
  4186.           array. We count on the fact that the `yy_transition' array
  4187.           has already been seen.
  4188.  
  4189.     `YYTD_STRUCT (0x10)'
  4190.           The data is a list of yy_trans_info structs, each of which
  4191.           consists of two integers. There is no padding between struct
  4192.           elements or between structs.  The type of each member is
  4193.           determined by the `YYTD_DATA*' bits.
  4194.  
  4195. `td_lolen'
  4196.      Specifies the number of elements in the lowest dimension array. If
  4197.      this is a one-dimensional array, then it is simply the number of
  4198.      elements in this array.  The element size is determined by the
  4199.      `td_flags' field.
  4200.  
  4201. `td_hilen'
  4202.      If `td_hilen' is non-zero, then the data is a two-dimensional
  4203.      array.  Otherwise, the data is a one-dimensional array. `td_hilen'
  4204.      contains the number of elements in the higher dimensional array,
  4205.      and `td_lolen' contains the number of elements in the lowest
  4206.      dimension.
  4207.  
  4208.      Conceptually, `td_data' is either `sometype td_data[td_lolen]', or
  4209.      `sometype td_data[td_hilen][td_lolen]', where `sometype' is
  4210.      specified by the `td_flags' field.  It is possible for both
  4211.      `td_lolen' and `td_hilen' to be zero, in which case `td_data' is a
  4212.      zero length array, and no data is loaded, i.e., this table is
  4213.      simply skipped. Flex does not currently generate tables of zero
  4214.      length.
  4215.  
  4216. `td_data[]'
  4217.      The table data. This array may be a one- or two-dimensional array,
  4218.      of type `int8', `int16', `int32', `struct yy_trans_info', or
  4219.      `struct yy_trans_info*',  depending upon the values in the
  4220.      `td_flags', `td_lolen', and `td_hilen' fields.
  4221.  
  4222. `td_pad64[]'
  4223.      Zero or more NULL bytes, padding the entire table to the next
  4224.      64-bit boundary as calculated from the beginning of this table.
  4225.  
  4226. 
  4227. File: flex,  Node: Diagnostics,  Next: Limitations,  Prev: Serialized Tables,  Up: Top
  4228.  
  4229. 23 Diagnostics
  4230. **************
  4231.  
  4232. The following is a list of `flex' diagnostic messages:
  4233.  
  4234.    * `warning, rule cannot be matched' indicates that the given rule
  4235.      cannot be matched because it follows other rules that will always
  4236.      match the same text as it.  For example, in the following `foo'
  4237.      cannot be matched because it comes after an identifier "catch-all"
  4238.      rule:
  4239.  
  4240.  
  4241.               [a-z]+    got_identifier();
  4242.               foo       got_foo();
  4243.  
  4244.      Using `REJECT' in a scanner suppresses this warning.
  4245.  
  4246.    * `warning, -s option given but default rule can be matched' means
  4247.      that it is possible (perhaps only in a particular start condition)
  4248.      that the default rule (match any single character) is the only one
  4249.      that will match a particular input.  Since `-s' was given,
  4250.      presumably this is not intended.
  4251.  
  4252.    * `reject_used_but_not_detected undefined' or
  4253.      `yymore_used_but_not_detected undefined'. These errors can occur
  4254.      at compile time.  They indicate that the scanner uses `REJECT' or
  4255.      `yymore()' but that `flex' failed to notice the fact, meaning that
  4256.      `flex' scanned the first two sections looking for occurrences of
  4257.      these actions and failed to find any, but somehow you snuck some in
  4258.      (via a #include file, for example).  Use `%option reject' or
  4259.      `%option yymore' to indicate to `flex' that you really do use
  4260.      these features.
  4261.  
  4262.    * `flex scanner jammed'. a scanner compiled with `-s' has
  4263.      encountered an input string which wasn't matched by any of its
  4264.      rules.  This error can also occur due to internal problems.
  4265.  
  4266.    * `token too large, exceeds YYLMAX'. your scanner uses `%array' and
  4267.      one of its rules matched a string longer than the `YYLMAX'
  4268.      constant (8K bytes by default).  You can increase the value by
  4269.      #define'ing `YYLMAX' in the definitions section of your `flex'
  4270.      input.
  4271.  
  4272.    * `scanner requires -8 flag to use the character 'x''. Your scanner
  4273.      specification includes recognizing the 8-bit character `'x'' and
  4274.      you did not specify the -8 flag, and your scanner defaulted to
  4275.      7-bit because you used the `-Cf' or `-CF' table compression
  4276.      options.  See the discussion of the `-7' flag, *Note Scanner
  4277.      Options::, for details.
  4278.  
  4279.    * `flex scanner push-back overflow'. you used `unput()' to push back
  4280.      so much text that the scanner's buffer could not hold both the
  4281.      pushed-back text and the current token in `yytext'.  Ideally the
  4282.      scanner should dynamically resize the buffer in this case, but at
  4283.      present it does not.
  4284.  
  4285.    * `input buffer overflow, can't enlarge buffer because scanner uses
  4286.      REJECT'.  the scanner was working on matching an extremely large
  4287.      token and needed to expand the input buffer.  This doesn't work
  4288.      with scanners that use `REJECT'.
  4289.  
  4290.    * `fatal flex scanner internal error--end of buffer missed'. This can
  4291.      occur in a scanner which is reentered after a long-jump has jumped
  4292.      out (or over) the scanner's activation frame.  Before reentering
  4293.      the scanner, use:
  4294.  
  4295.               yyrestart( yyin );
  4296.      or, as noted above, switch to using the C++ scanner class.
  4297.  
  4298.    * `too many start conditions in <> construct!'  you listed more start
  4299.      conditions in a <> construct than exist (so you must have listed at
  4300.      least one of them twice).
  4301.  
  4302. 
  4303. File: flex,  Node: Limitations,  Next: Bibliography,  Prev: Diagnostics,  Up: Top
  4304.  
  4305. 24 Limitations
  4306. **************
  4307.  
  4308. Some trailing context patterns cannot be properly matched and generate
  4309. warning messages (`dangerous trailing context').  These are patterns
  4310. where the ending of the first part of the rule matches the beginning of
  4311. the second part, such as `zx*/xy*', where the 'x*' matches the 'x' at
  4312. the beginning of the trailing context.  (Note that the POSIX draft
  4313. states that the text matched by such patterns is undefined.)  For some
  4314. trailing context rules, parts which are actually fixed-length are not
  4315. recognized as such, leading to the abovementioned performance loss.  In
  4316. particular, parts using `|' or `{n}' (such as `foo{3}') are always
  4317. considered variable-length.  Combining trailing context with the
  4318. special `|' action can result in _fixed_ trailing context being turned
  4319. into the more expensive _variable_ trailing context.  For example, in
  4320. the following:
  4321.  
  4322.  
  4323.          %%
  4324.          abc      |
  4325.          xyz/def
  4326.  
  4327.    Use of `unput()' invalidates yytext and yyleng, unless the `%array'
  4328. directive or the `-l' option has been used.  Pattern-matching of `NUL's
  4329. is substantially slower than matching other characters.  Dynamic
  4330. resizing of the input buffer is slow, as it entails rescanning all the
  4331. text matched so far by the current (generally huge) token.  Due to both
  4332. buffering of input and read-ahead, you cannot intermix calls to
  4333. `<stdio.h>' routines, such as, getchar(), with `flex' rules and expect
  4334. it to work.  Call `input()' instead.  The total table entries listed by
  4335. the `-v' flag excludes the number of table entries needed to determine
  4336. what rule has been matched.  The number of entries is equal to the
  4337. number of DFA states if the scanner does not use `REJECT', and somewhat
  4338. greater than the number of states if it does.  `REJECT' cannot be used
  4339. with the `-f' or `-F' options.
  4340.  
  4341.    The `flex' internal algorithms need documentation.
  4342.  
  4343. 
  4344. File: flex,  Node: Bibliography,  Next: FAQ,  Prev: Limitations,  Up: Top
  4345.  
  4346. 25 Additional Reading
  4347. *********************
  4348.  
  4349. You may wish to read more about the following programs:
  4350.    * lex
  4351.  
  4352.    * yacc
  4353.  
  4354.    * sed
  4355.  
  4356.    * awk
  4357.  
  4358.    The following books may contain material of interest:
  4359.  
  4360.    John Levine, Tony Mason, and Doug Brown, _Lex & Yacc_, O'Reilly and
  4361. Associates.  Be sure to get the 2nd edition.
  4362.  
  4363.    M. E. Lesk and E. Schmidt, _LEX - Lexical Analyzer Generator_
  4364.  
  4365.    Alfred Aho, Ravi Sethi and Jeffrey Ullman, _Compilers: Principles,
  4366. Techniques and Tools_, Addison-Wesley (1986).  Describes the
  4367. pattern-matching techniques used by `flex' (deterministic finite
  4368. automata).
  4369.  
  4370. 
  4371. File: flex,  Node: FAQ,  Next: Appendices,  Prev: Bibliography,  Up: Top
  4372.  
  4373. FAQ
  4374. ***
  4375.  
  4376. From time to time, the `flex' maintainer receives certain questions.
  4377. Rather than repeat answers to well-understood problems, we publish them
  4378. here.
  4379.  
  4380. * Menu:
  4381.  
  4382. * When was flex born?::
  4383. * How do I expand \ escape sequences in C-style quoted strings?::
  4384. * Why do flex scanners call fileno if it is not ANSI compatible?::
  4385. * Does flex support recursive pattern definitions?::
  4386. * How do I skip huge chunks of input (tens of megabytes) while using flex?::
  4387. * Flex is not matching my patterns in the same order that I defined them.::
  4388. * My actions are executing out of order or sometimes not at all.::
  4389. * How can I have multiple input sources feed into the same scanner at the same time?::
  4390. * Can I build nested parsers that work with the same input file?::
  4391. * How can I match text only at the end of a file?::
  4392. * How can I make REJECT cascade across start condition boundaries?::
  4393. * Why cant I use fast or full tables with interactive mode?::
  4394. * How much faster is -F or -f than -C?::
  4395. * If I have a simple grammar cant I just parse it with flex?::
  4396. * Why doesnt yyrestart() set the start state back to INITIAL?::
  4397. * How can I match C-style comments?::
  4398. * The period isnt working the way I expected.::
  4399. * Can I get the flex manual in another format?::
  4400. * Does there exist a "faster" NDFA->DFA algorithm?::
  4401. * How does flex compile the DFA so quickly?::
  4402. * How can I use more than 8192 rules?::
  4403. * How do I abandon a file in the middle of a scan and switch to a new file?::
  4404. * How do I execute code only during initialization (only before the first scan)?::
  4405. * How do I execute code at termination?::
  4406. * Where else can I find help?::
  4407. * Can I include comments in the "rules" section of the file?::
  4408. * I get an error about undefined yywrap().::
  4409. * How can I change the matching pattern at run time?::
  4410. * How can I expand macros in the input?::
  4411. * How can I build a two-pass scanner?::
  4412. * How do I match any string not matched in the preceding rules?::
  4413. * I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
  4414. * Is there a way to make flex treat NULL like a regular character?::
  4415. * Whenever flex can not match the input it says "flex scanner jammed".::
  4416. * Why doesnt flex have non-greedy operators like perl does?::
  4417. * Memory leak - 16386 bytes allocated by malloc.::
  4418. * How do I track the byte offset for lseek()?::
  4419. * How do I use my own I/O classes in a C++ scanner?::
  4420. * How do I skip as many chars as possible?::
  4421. * deleteme00::
  4422. * Are certain equivalent patterns faster than others?::
  4423. * Is backing up a big deal?::
  4424. * Can I fake multi-byte character support?::
  4425. * deleteme01::
  4426. * Can you discuss some flex internals?::
  4427. * unput() messes up yy_at_bol::
  4428. * The | operator is not doing what I want::
  4429. * Why can't flex understand this variable trailing context pattern?::
  4430. * The ^ operator isn't working::
  4431. * Trailing context is getting confused with trailing optional patterns::
  4432. * Is flex GNU or not?::
  4433. * ERASEME53::
  4434. * I need to scan if-then-else blocks and while loops::
  4435. * ERASEME55::
  4436. * ERASEME56::
  4437. * ERASEME57::
  4438. * Is there a repository for flex scanners?::
  4439. * How can I conditionally compile or preprocess my flex input file?::
  4440. * Where can I find grammars for lex and yacc?::
  4441. * I get an end-of-buffer message for each character scanned.::
  4442. * unnamed-faq-62::
  4443. * unnamed-faq-63::
  4444. * unnamed-faq-64::
  4445. * unnamed-faq-65::
  4446. * unnamed-faq-66::
  4447. * unnamed-faq-67::
  4448. * unnamed-faq-68::
  4449. * unnamed-faq-69::
  4450. * unnamed-faq-70::
  4451. * unnamed-faq-71::
  4452. * unnamed-faq-72::
  4453. * unnamed-faq-73::
  4454. * unnamed-faq-74::
  4455. * unnamed-faq-75::
  4456. * unnamed-faq-76::
  4457. * unnamed-faq-77::
  4458. * unnamed-faq-78::
  4459. * unnamed-faq-79::
  4460. * unnamed-faq-80::
  4461. * unnamed-faq-81::
  4462. * unnamed-faq-82::
  4463. * unnamed-faq-83::
  4464. * unnamed-faq-84::
  4465. * unnamed-faq-85::
  4466. * unnamed-faq-86::
  4467. * unnamed-faq-87::
  4468. * unnamed-faq-88::
  4469. * unnamed-faq-90::
  4470. * unnamed-faq-91::
  4471. * unnamed-faq-92::
  4472. * unnamed-faq-93::
  4473. * unnamed-faq-94::
  4474. * unnamed-faq-95::
  4475. * unnamed-faq-96::
  4476. * unnamed-faq-97::
  4477. * unnamed-faq-98::
  4478. * unnamed-faq-99::
  4479. * unnamed-faq-100::
  4480. * unnamed-faq-101::
  4481.  
  4482. 
  4483. File: flex,  Node: When was flex born?,  Next: How do I expand \ escape sequences in C-style quoted strings?,  Up: FAQ
  4484.  
  4485. When was flex born?
  4486. ===================
  4487.  
  4488. Vern Paxson took over the `Software Tools' lex project from Jef
  4489. Poskanzer in 1982.  At that point it was written in Ratfor.  Around
  4490. 1987 or so, Paxson translated it into C, and a legend was born :-).
  4491.  
  4492. 
  4493. File: flex,  Node: How do I expand \ escape sequences in C-style quoted strings?,  Next: Why do flex scanners call fileno if it is not ANSI compatible?,  Prev: When was flex born?,  Up: FAQ
  4494.  
  4495. How do I expand \ escape sequences in C-style quoted strings?
  4496. =============================================================
  4497.  
  4498. A key point when scanning quoted strings is that you cannot (easily)
  4499. write a single rule that will precisely match the string if you allow
  4500. things like embedded escape sequences and newlines.  If you try to
  4501. match strings with a single rule then you'll wind up having to rescan
  4502. the string anyway to find any escape sequences.
  4503.  
  4504.    Instead you can use exclusive start conditions and a set of rules,
  4505. one for matching non-escaped text, one for matching a single escape,
  4506. one for matching an embedded newline, and one for recognizing the end
  4507. of the string.  Each of these rules is then faced with the question of
  4508. where to put its intermediary results.  The best solution is for the
  4509. rules to append their local value of `yytext' to the end of a "string
  4510. literal" buffer.  A rule like the escape-matcher will append to the
  4511. buffer the meaning of the escape sequence rather than the literal text
  4512. in `yytext'.  In this way, `yytext' does not need to be modified at all.
  4513.  
  4514. 
  4515. File: flex,  Node: Why do flex scanners call fileno if it is not ANSI compatible?,  Next: Does flex support recursive pattern definitions?,  Prev: How do I expand \ escape sequences in C-style quoted strings?,  Up: FAQ
  4516.  
  4517. Why do flex scanners call fileno if it is not ANSI compatible?
  4518. ==============================================================
  4519.  
  4520. Flex scanners call `fileno()' in order to get the file descriptor
  4521. corresponding to `yyin'. The file descriptor may be passed to
  4522. `isatty()' or `read()', depending upon which `%options' you specified.
  4523. If your system does not have `fileno()' support, to get rid of the
  4524. `read()' call, do not specify `%option read'. To get rid of the
  4525. `isatty()' call, you must specify one of `%option always-interactive' or
  4526. `%option never-interactive'.
  4527.  
  4528. 
  4529. File: flex,  Node: Does flex support recursive pattern definitions?,  Next: How do I skip huge chunks of input (tens of megabytes) while using flex?,  Prev: Why do flex scanners call fileno if it is not ANSI compatible?,  Up: FAQ
  4530.  
  4531. Does flex support recursive pattern definitions?
  4532. ================================================
  4533.  
  4534. e.g.,
  4535.  
  4536.  
  4537.      %%
  4538.      block   "{"({block}|{statement})*"}"
  4539.  
  4540.    No. You cannot have recursive definitions.  The pattern-matching
  4541. power of regular expressions in general (and therefore flex scanners,
  4542. too) is limited.  In particular, regular expressions cannot "balance"
  4543. parentheses to an arbitrary degree.  For example, it's impossible to
  4544. write a regular expression that matches all strings containing the same
  4545. number of '{'s as '}'s.  For more powerful pattern matching, you need a
  4546. parser, such as `GNU bison'.
  4547.  
  4548. 
  4549. File: flex,  Node: How do I skip huge chunks of input (tens of megabytes) while using flex?,  Next: Flex is not matching my patterns in the same order that I defined them.,  Prev: Does flex support recursive pattern definitions?,  Up: FAQ
  4550.  
  4551. How do I skip huge chunks of input (tens of megabytes) while using flex?
  4552. ========================================================================
  4553.  
  4554. Use `fseek()' (or `lseek()') to position yyin, then call `yyrestart()'.
  4555.  
  4556. 
  4557. File: flex,  Node: Flex is not matching my patterns in the same order that I defined them.,  Next: My actions are executing out of order or sometimes not at all.,  Prev: How do I skip huge chunks of input (tens of megabytes) while using flex?,  Up: FAQ
  4558.  
  4559. Flex is not matching my patterns in the same order that I defined them.
  4560. =======================================================================
  4561.  
  4562. `flex' picks the rule that matches the most text (i.e., the longest
  4563. possible input string).  This is because `flex' uses an entirely
  4564. different matching technique ("deterministic finite automata") that
  4565. actually does all of the matching simultaneously, in parallel.  (Seems
  4566. impossible, but it's actually a fairly simple technique once you
  4567. understand the principles.)
  4568.  
  4569.    A side-effect of this parallel matching is that when the input
  4570. matches more than one rule, `flex' scanners pick the rule that matched
  4571. the _most_ text. This is explained further in the manual, in the
  4572. section *Note Matching::.
  4573.  
  4574.    If you want `flex' to choose a shorter match, then you can work
  4575. around this behavior by expanding your short rule to match more text,
  4576. then put back the extra:
  4577.  
  4578.  
  4579.      data_.*        yyless( 5 ); BEGIN BLOCKIDSTATE;
  4580.  
  4581.    Another fix would be to make the second rule active only during the
  4582. `<BLOCKIDSTATE>' start condition, and make that start condition
  4583. exclusive by declaring it with `%x' instead of `%s'.
  4584.  
  4585.    A final fix is to change the input language so that the ambiguity for
  4586. `data_' is removed, by adding characters to it that don't match the
  4587. identifier rule, or by removing characters (such as `_') from the
  4588. identifier rule so it no longer matches `data_'.  (Of course, you might
  4589. also not have the option of changing the input language.)
  4590.  
  4591. 
  4592. File: flex,  Node: My actions are executing out of order or sometimes not at all.,  Next: How can I have multiple input sources feed into the same scanner at the same time?,  Prev: Flex is not matching my patterns in the same order that I defined them.,  Up: FAQ
  4593.  
  4594. My actions are executing out of order or sometimes not at all.
  4595. ==============================================================
  4596.  
  4597. Most likely, you have (in error) placed the opening `{' of the action
  4598. block on a different line than the rule, e.g.,
  4599.  
  4600.  
  4601.      ^(foo|bar)
  4602.      {  <<<--- WRONG!
  4603.  
  4604.      }
  4605.  
  4606.    `flex' requires that the opening `{' of an action associated with a
  4607. rule begin on the same line as does the rule.  You need instead to
  4608. write your rules as follows:
  4609.  
  4610.  
  4611.      ^(foo|bar)   {  // CORRECT!
  4612.  
  4613.      }
  4614.  
  4615. 
  4616. File: flex,  Node: How can I have multiple input sources feed into the same scanner at the same time?,  Next: Can I build nested parsers that work with the same input file?,  Prev: My actions are executing out of order or sometimes not at all.,  Up: FAQ
  4617.  
  4618. How can I have multiple input sources feed into the same scanner at the same time?
  4619. ==================================================================================
  4620.  
  4621. If ...
  4622.    * your scanner is free of backtracking (verified using `flex''s `-b'
  4623.      flag),
  4624.  
  4625.    * AND you run your scanner interactively (`-I' option; default
  4626.      unless using special table compression options),
  4627.  
  4628.    * AND you feed it one character at a time by redefining `YY_INPUT'
  4629.      to do so,
  4630.  
  4631.    then every time it matches a token, it will have exhausted its input
  4632. buffer (because the scanner is free of backtracking).  This means you
  4633. can safely use `select()' at the point and only call `yylex()' for
  4634. another token if `select()' indicates there's data available.
  4635.  
  4636.    That is, move the `select()' out from the input function to a point
  4637. where it determines whether `yylex()' gets called for the next token.
  4638.  
  4639.    With this approach, you will still have problems if your input can
  4640. arrive piecemeal; `select()' could inform you that the beginning of a
  4641. token is available, you call `yylex()' to get it, but it winds up
  4642. blocking waiting for the later characters in the token.
  4643.  
  4644.    Here's another way:  Move your input multiplexing inside of
  4645. `YY_INPUT'.  That is, whenever `YY_INPUT' is called, it `select()''s to
  4646. see where input is available.  If input is available for the scanner,
  4647. it reads and returns the next byte.  If input is available from another
  4648. source, it calls whatever function is responsible for reading from that
  4649. source.  (If no input is available, it blocks until some input is
  4650. available.)  I've used this technique in an interpreter I wrote that
  4651. both reads keyboard input using a `flex' scanner and IPC traffic from
  4652. sockets, and it works fine.
  4653.  
  4654. 
  4655. File: flex,  Node: Can I build nested parsers that work with the same input file?,  Next: How can I match text only at the end of a file?,  Prev: How can I have multiple input sources feed into the same scanner at the same time?,  Up: FAQ
  4656.  
  4657. Can I build nested parsers that work with the same input file?
  4658. ==============================================================
  4659.  
  4660. This is not going to work without some additional effort.  The reason is
  4661. that `flex' block-buffers the input it reads from `yyin'.  This means
  4662. that the "outermost" `yylex()', when called, will automatically slurp
  4663. up the first 8K of input available on yyin, and subsequent calls to
  4664. other `yylex()''s won't see that input.  You might be tempted to work
  4665. around this problem by redefining `YY_INPUT' to only return a small
  4666. amount of text, but it turns out that that approach is quite difficult.
  4667. Instead, the best solution is to combine all of your scanners into one
  4668. large scanner, using a different exclusive start condition for each.
  4669.  
  4670. 
  4671. File: flex,  Node: How can I match text only at the end of a file?,  Next: How can I make REJECT cascade across start condition boundaries?,  Prev: Can I build nested parsers that work with the same input file?,  Up: FAQ
  4672.  
  4673. How can I match text only at the end of a file?
  4674. ===============================================
  4675.  
  4676. There is no way to write a rule which is "match this text, but only if
  4677. it comes at the end of the file".  You can fake it, though, if you
  4678. happen to have a character lying around that you don't allow in your
  4679. input.  Then you redefine `YY_INPUT' to call your own routine which, if
  4680. it sees an `EOF', returns the magic character first (and remembers to
  4681. return a real `EOF' next time it's called).  Then you could write:
  4682.  
  4683.  
  4684.      <COMMENT>(.|\n)*{EOF_CHAR}    /* saw comment at EOF */
  4685.  
  4686. 
  4687. File: flex,  Node: How can I make REJECT cascade across start condition boundaries?,  Next: Why cant I use fast or full tables with interactive mode?,  Prev: How can I match text only at the end of a file?,  Up: FAQ
  4688.  
  4689. How can I make REJECT cascade across start condition boundaries?
  4690. ================================================================
  4691.  
  4692. You can do this as follows.  Suppose you have a start condition `A', and
  4693. after exhausting all of the possible matches in `<A>', you want to try
  4694. matches in `<INITIAL>'.  Then you could use the following:
  4695.  
  4696.  
  4697.      %x A
  4698.      %%
  4699.      <A>rule_that_is_long    ...; REJECT;
  4700.      <A>rule                 ...; REJECT; /* shorter rule */
  4701.      <A>etc.
  4702.      ...
  4703.      <A>.|\n  {
  4704.      /* Shortest and last rule in <A>, so
  4705.      * cascaded REJECT's will eventually
  4706.      * wind up matching this rule.  We want
  4707.      * to now switch to the initial state
  4708.      * and try matching from there instead.
  4709.      */
  4710.      yyless(0);    /* put back matched text */
  4711.      BEGIN(INITIAL);
  4712.      }
  4713.  
  4714. 
  4715. File: flex,  Node: Why cant I use fast or full tables with interactive mode?,  Next: How much faster is -F or -f than -C?,  Prev: How can I make REJECT cascade across start condition boundaries?,  Up: FAQ
  4716.  
  4717. Why can't I use fast or full tables with interactive mode?
  4718. ==========================================================
  4719.  
  4720. One of the assumptions flex makes is that interactive applications are
  4721. inherently slow (they're waiting on a human after all).  It has to do
  4722. with how the scanner detects that it must be finished scanning a token.
  4723. For interactive scanners, after scanning each character the current
  4724. state is looked up in a table (essentially) to see whether there's a
  4725. chance of another input character possibly extending the length of the
  4726. match.  If not, the scanner halts.  For non-interactive scanners, the
  4727. end-of-token test is much simpler, basically a compare with 0, so no
  4728. memory bus cycles.  Since the test occurs in the innermost scanning
  4729. loop, one would like to make it go as fast as possible.
  4730.  
  4731.    Still, it seems reasonable to allow the user to choose to trade off
  4732. a bit of performance in this area to gain the corresponding
  4733. flexibility.  There might be another reason, though, why fast scanners
  4734. don't support the interactive option.
  4735.  
  4736. 
  4737. File: flex,  Node: How much faster is -F or -f than -C?,  Next: If I have a simple grammar cant I just parse it with flex?,  Prev: Why cant I use fast or full tables with interactive mode?,  Up: FAQ
  4738.  
  4739. How much faster is -F or -f than -C?
  4740. ====================================
  4741.  
  4742. Much faster (factor of 2-3).
  4743.  
  4744. 
  4745. File: flex,  Node: If I have a simple grammar cant I just parse it with flex?,  Next: Why doesnt yyrestart() set the start state back to INITIAL?,  Prev: How much faster is -F or -f than -C?,  Up: FAQ
  4746.  
  4747. If I have a simple grammar can't I just parse it with flex?
  4748. ===========================================================
  4749.  
  4750. Is your grammar recursive? That's almost always a sign that you're
  4751. better off using a parser/scanner rather than just trying to use a
  4752. scanner alone.
  4753.  
  4754. 
  4755. File: flex,  Node: Why doesnt yyrestart() set the start state back to INITIAL?,  Next: How can I match C-style comments?,  Prev: If I have a simple grammar cant I just parse it with flex?,  Up: FAQ
  4756.  
  4757. Why doesn't yyrestart() set the start state back to INITIAL?
  4758. ============================================================
  4759.  
  4760. There are two reasons.  The first is that there might be programs that
  4761. rely on the start state not changing across file changes.  The second
  4762. is that beginning with `flex' version 2.4, use of `yyrestart()' is no
  4763. longer required, so fixing the problem there doesn't solve the more
  4764. general problem.
  4765.  
  4766. 
  4767. File: flex,  Node: How can I match C-style comments?,  Next: The period isnt working the way I expected.,  Prev: Why doesnt yyrestart() set the start state back to INITIAL?,  Up: FAQ
  4768.  
  4769. How can I match C-style comments?
  4770. =================================
  4771.  
  4772. You might be tempted to try something like this:
  4773.  
  4774.  
  4775.      "/*".*"*/"       // WRONG!
  4776.  
  4777.    or, worse, this:
  4778.  
  4779.  
  4780.      "/*"(.|\n)"*/"   // WRONG!
  4781.  
  4782.    The above rules will eat too much input, and blow up on things like:
  4783.  
  4784.  
  4785.      /* a comment */ do_my_thing( "oops */" );
  4786.  
  4787.    Here is one way which allows you to track line information:
  4788.  
  4789.  
  4790.      <INITIAL>{
  4791.      "/*"              BEGIN(IN_COMMENT);
  4792.      }
  4793.      <IN_COMMENT>{
  4794.      "*/"      BEGIN(INITIAL);
  4795.      [^*\n]+   // eat comment in chunks
  4796.      "*"       // eat the lone star
  4797.      \n        yylineno++;
  4798.      }
  4799.  
  4800. 
  4801. File: flex,  Node: The period isnt working the way I expected.,  Next: Can I get the flex manual in another format?,  Prev: How can I match C-style comments?,  Up: FAQ
  4802.  
  4803. The '.' isn't working the way I expected.
  4804. =========================================
  4805.  
  4806. Here are some tips for using `.':
  4807.  
  4808.    * A common mistake is to place the grouping parenthesis AFTER an
  4809.      operator, when you really meant to place the parenthesis BEFORE
  4810.      the operator, e.g., you probably want this `(foo|bar)+' and NOT
  4811.      this `(foo|bar+)'.
  4812.  
  4813.      The first pattern matches the words `foo' or `bar' any number of
  4814.      times, e.g., it matches the text `barfoofoobarfoo'. The second
  4815.      pattern matches a single instance of `foo' or a single instance of
  4816.      `bar' followed by one or more `r's, e.g., it matches the text
  4817.      `barrrr' .
  4818.  
  4819.    * A `.' inside `[]''s just means a literal`.' (period), and NOT "any
  4820.      character except newline".
  4821.  
  4822.    * Remember that `.' matches any character EXCEPT `\n' (and `EOF').
  4823.      If you really want to match ANY character, including newlines,
  4824.      then use `(.|\n)' Beware that the regex `(.|\n)+' will match your
  4825.      entire input!
  4826.  
  4827.    * Finally, if you want to match a literal `.' (a period), then use
  4828.      `[.]' or `"."'
  4829.  
  4830. 
  4831. File: flex,  Node: Can I get the flex manual in another format?,  Next: Does there exist a "faster" NDFA->DFA algorithm?,  Prev: The period isnt working the way I expected.,  Up: FAQ
  4832.  
  4833. Can I get the flex manual in another format?
  4834. ============================================
  4835.  
  4836. The `flex' source distribution  includes a texinfo manual. You are free
  4837. to convert that texinfo into whatever format you desire. The `texinfo'
  4838. package includes tools for conversion to a number of formats.
  4839.  
  4840. 
  4841. File: flex,  Node: Does there exist a "faster" NDFA->DFA algorithm?,  Next: How does flex compile the DFA so quickly?,  Prev: Can I get the flex manual in another format?,  Up: FAQ
  4842.  
  4843. Does there exist a "faster" NDFA->DFA algorithm?
  4844. ================================================
  4845.  
  4846. There's no way around the potential exponential running time - it can
  4847. take you exponential time just to enumerate all of the DFA states.  In
  4848. practice, though, the running time is closer to linear, or sometimes
  4849. quadratic.
  4850.  
  4851. 
  4852. File: flex,  Node: How does flex compile the DFA so quickly?,  Next: How can I use more than 8192 rules?,  Prev: Does there exist a "faster" NDFA->DFA algorithm?,  Up: FAQ
  4853.  
  4854. How does flex compile the DFA so quickly?
  4855. =========================================
  4856.  
  4857. There are two big speed wins that `flex' uses:
  4858.  
  4859.   1. It analyzes the input rules to construct equivalence classes for
  4860.      those characters that always make the same transitions.  It then
  4861.      rewrites the NFA using equivalence classes for transitions instead
  4862.      of characters.  This cuts down the NFA->DFA computation time
  4863.      dramatically, to the point where, for uncompressed DFA tables, the
  4864.      DFA generation is often I/O bound in writing out the tables.
  4865.  
  4866.   2. It maintains hash values for previously computed DFA states, so
  4867.      testing whether a newly constructed DFA state is equivalent to a
  4868.      previously constructed state can be done very quickly, by first
  4869.      comparing hash values.
  4870.  
  4871. 
  4872. File: flex,  Node: How can I use more than 8192 rules?,  Next: How do I abandon a file in the middle of a scan and switch to a new file?,  Prev: How does flex compile the DFA so quickly?,  Up: FAQ
  4873.  
  4874. How can I use more than 8192 rules?
  4875. ===================================
  4876.  
  4877. `Flex' is compiled with an upper limit of 8192 rules per scanner.  If
  4878. you need more than 8192 rules in your scanner, you'll have to recompile
  4879. `flex' with the following changes in `flexdef.h':
  4880.  
  4881.  
  4882.      <    #define YY_TRAILING_MASK 0x2000
  4883.      <    #define YY_TRAILING_HEAD_MASK 0x4000
  4884.      --
  4885.      >    #define YY_TRAILING_MASK 0x20000000
  4886.      >    #define YY_TRAILING_HEAD_MASK 0x40000000
  4887.  
  4888.    This should work okay as long as your C compiler uses 32 bit
  4889. integers.  But you might want to think about whether using such a huge
  4890. number of rules is the best way to solve your problem.
  4891.  
  4892.    The following may also be relevant:
  4893.  
  4894.    With luck, you should be able to increase the definitions in
  4895. flexdef.h for:
  4896.  
  4897.  
  4898.      #define JAMSTATE -32766 /* marks a reference to the state that always jams */
  4899.      #define MAXIMUM_MNS 31999
  4900.      #define BAD_SUBSCRIPT -32767
  4901.  
  4902.    recompile everything, and it'll all work.  Flex only has these
  4903. 16-bit-like values built into it because a long time ago it was
  4904. developed on a machine with 16-bit ints.  I've given this advice to
  4905. others in the past but haven't heard back from them whether it worked
  4906. okay or not...
  4907.  
  4908. 
  4909. File: flex,  Node: How do I abandon a file in the middle of a scan and switch to a new file?,  Next: How do I execute code only during initialization (only before the first scan)?,  Prev: How can I use more than 8192 rules?,  Up: FAQ
  4910.  
  4911. How do I abandon a file in the middle of a scan and switch to a new file?
  4912. =========================================================================
  4913.  
  4914. Just call `yyrestart(newfile)'. Be sure to reset the start state if you
  4915. want a "fresh start, since `yyrestart' does NOT reset the start state
  4916. back to `INITIAL'.
  4917.  
  4918. 
  4919. File: flex,  Node: How do I execute code only during initialization (only before the first scan)?,  Next: How do I execute code at termination?,  Prev: How do I abandon a file in the middle of a scan and switch to a new file?,  Up: FAQ
  4920.  
  4921. How do I execute code only during initialization (only before the first scan)?
  4922. ==============================================================================
  4923.  
  4924. You can specify an initial action by defining the macro `YY_USER_INIT'
  4925. (though note that `yyout' may not be available at the time this macro
  4926. is executed).  Or you can add to the beginning of your rules section:
  4927.  
  4928.  
  4929.      %%
  4930.      /* Must be indented! */
  4931.      static int did_init = 0;
  4932.  
  4933.      if ( ! did_init ){
  4934.      do_my_init();
  4935.      did_init = 1;
  4936.      }
  4937.  
  4938. 
  4939. File: flex,  Node: How do I execute code at termination?,  Next: Where else can I find help?,  Prev: How do I execute code only during initialization (only before the first scan)?,  Up: FAQ
  4940.  
  4941. How do I execute code at termination?
  4942. =====================================
  4943.  
  4944. You can specify an action for the `<<EOF>>' rule.
  4945.  
  4946. 
  4947. File: flex,  Node: Where else can I find help?,  Next: Can I include comments in the "rules" section of the file?,  Prev: How do I execute code at termination?,  Up: FAQ
  4948.  
  4949. Where else can I find help?
  4950. ===========================
  4951.  
  4952. You can find the flex homepage on the web at
  4953. `http://lex.sourceforge.net/'. See that page for details about flex
  4954. mailing lists as well.
  4955.  
  4956. 
  4957. File: flex,  Node: Can I include comments in the "rules" section of the file?,  Next: I get an error about undefined yywrap().,  Prev: Where else can I find help?,  Up: FAQ
  4958.  
  4959. Can I include comments in the "rules" section of the file?
  4960. ==========================================================
  4961.  
  4962. Yes, just about anywhere you want to. See the manual for the specific
  4963. syntax.
  4964.  
  4965. 
  4966. File: flex,  Node: I get an error about undefined yywrap().,  Next: How can I change the matching pattern at run time?,  Prev: Can I include comments in the "rules" section of the file?,  Up: FAQ
  4967.  
  4968. I get an error about undefined yywrap().
  4969. ========================================
  4970.  
  4971. You must supply a `yywrap()' function of your own, or link to `libfl.a'
  4972. (which provides one), or use
  4973.  
  4974.  
  4975.      %option noyywrap
  4976.  
  4977.    in your source to say you don't want a `yywrap()' function.
  4978.  
  4979. 
  4980. File: flex,  Node: How can I change the matching pattern at run time?,  Next: How can I expand macros in the input?,  Prev: I get an error about undefined yywrap().,  Up: FAQ
  4981.  
  4982. How can I change the matching pattern at run time?
  4983. ==================================================
  4984.  
  4985. You can't, it's compiled into a static table when flex builds the
  4986. scanner.
  4987.  
  4988. 
  4989. File: flex,  Node: How can I expand macros in the input?,  Next: How can I build a two-pass scanner?,  Prev: How can I change the matching pattern at run time?,  Up: FAQ
  4990.  
  4991. How can I expand macros in the input?
  4992. =====================================
  4993.  
  4994. The best way to approach this problem is at a higher level, e.g., in
  4995. the parser.
  4996.  
  4997.    However, you can do this using multiple input buffers.
  4998.  
  4999.  
  5000.      %%
  5001.      macro/[a-z]+    {
  5002.      /* Saw the macro "macro" followed by extra stuff. */
  5003.      main_buffer = YY_CURRENT_BUFFER;
  5004.      expansion_buffer = yy_scan_string(expand(yytext));
  5005.      yy_switch_to_buffer(expansion_buffer);
  5006.      }
  5007.  
  5008.      <<EOF>>    {
  5009.      if ( expansion_buffer )
  5010.      {
  5011.      // We were doing an expansion, return to where
  5012.      // we were.
  5013.      yy_switch_to_buffer(main_buffer);
  5014.      yy_delete_buffer(expansion_buffer);
  5015.      expansion_buffer = 0;
  5016.      }
  5017.      else
  5018.      yyterminate();
  5019.      }
  5020.  
  5021.    You probably will want a stack of expansion buffers to allow nested
  5022. macros.  From the above though hopefully the idea is clear.
  5023.  
  5024. 
  5025. File: flex,  Node: How can I build a two-pass scanner?,  Next: How do I match any string not matched in the preceding rules?,  Prev: How can I expand macros in the input?,  Up: FAQ
  5026.  
  5027. How can I build a two-pass scanner?
  5028. ===================================
  5029.  
  5030. One way to do it is to filter the first pass to a temporary file, then
  5031. process the temporary file on the second pass. You will probably see a
  5032. performance hit, do to all the disk I/O.
  5033.  
  5034.    When you need to look ahead far forward like this, it almost always
  5035. means that the right solution is to build a parse tree of the entire
  5036. input, then walk it after the parse in order to generate the output.
  5037. In a sense, this is a two-pass approach, once through the text and once
  5038. through the parse tree, but the performance hit for the latter is
  5039. usually an order of magnitude smaller, since everything is already
  5040. classified, in binary format, and residing in memory.
  5041.  
  5042. 
  5043. File: flex,  Node: How do I match any string not matched in the preceding rules?,  Next: I am trying to port code from AT&T lex that uses yysptr and yysbuf.,  Prev: How can I build a two-pass scanner?,  Up: FAQ
  5044.  
  5045. How do I match any string not matched in the preceding rules?
  5046. =============================================================
  5047.  
  5048. One way to assign precedence, is to place the more specific rules
  5049. first. If two rules would match the same input (same sequence of
  5050. characters) then the first rule listed in the `flex' input wins. e.g.,
  5051.  
  5052.  
  5053.      %%
  5054.      foo[a-zA-Z_]+    return FOO_ID;
  5055.      bar[a-zA-Z_]+    return BAR_ID;
  5056.      [a-zA-Z_]+       return GENERIC_ID;
  5057.  
  5058.    Note that the rule `[a-zA-Z_]+' must come *after* the others.  It
  5059. will match the same amount of text as the more specific rules, and in
  5060. that case the `flex' scanner will pick the first rule listed in your
  5061. scanner as the one to match.
  5062.  
  5063. 
  5064. File: flex,  Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf.,  Next: Is there a way to make flex treat NULL like a regular character?,  Prev: How do I match any string not matched in the preceding rules?,  Up: FAQ
  5065.  
  5066. I am trying to port code from AT&T lex that uses yysptr and yysbuf.
  5067. ===================================================================
  5068.  
  5069. Those are internal variables pointing into the AT&T scanner's input
  5070. buffer.  I imagine they're being manipulated in user versions of the
  5071. `input()' and `unput()' functions.  If so, what you need to do is
  5072. analyze those functions to figure out what they're doing, and then
  5073. replace `input()' with an appropriate definition of `YY_INPUT'.  You
  5074. shouldn't need to (and must not) replace `flex''s `unput()' function.
  5075.  
  5076. 
  5077. File: flex,  Node: Is there a way to make flex treat NULL like a regular character?,  Next: Whenever flex can not match the input it says "flex scanner jammed".,  Prev: I am trying to port code from AT&T lex that uses yysptr and yysbuf.,  Up: FAQ
  5078.  
  5079. Is there a way to make flex treat NULL like a regular character?
  5080. ================================================================
  5081.  
  5082. Yes, `\0' and `\x00' should both do the trick.  Perhaps you have an
  5083. ancient version of `flex'.  The latest release is version 2.5.31.
  5084.  
  5085. 
  5086. File: flex,  Node: Whenever flex can not match the input it says "flex scanner jammed".,  Next: Why doesnt flex have non-greedy operators like perl does?,  Prev: Is there a way to make flex treat NULL like a regular character?,  Up: FAQ
  5087.  
  5088. Whenever flex can not match the input it says "flex scanner jammed".
  5089. ====================================================================
  5090.  
  5091. You need to add a rule that matches the otherwise-unmatched text.  e.g.,
  5092.  
  5093.  
  5094.      %option yylineno
  5095.      %%
  5096.      [[a bunch of rules here]]
  5097.  
  5098.      .    printf("bad input character '%s' at line %d\n", yytext, yylineno);
  5099.  
  5100.    See `%option default' for more information.
  5101.  
  5102. 
  5103. File: flex,  Node: Why doesnt flex have non-greedy operators like perl does?,  Next: Memory leak - 16386 bytes allocated by malloc.,  Prev: Whenever flex can not match the input it says "flex scanner jammed".,  Up: FAQ
  5104.  
  5105. Why doesn't flex have non-greedy operators like perl does?
  5106. ==========================================================
  5107.  
  5108. A DFA can do a non-greedy match by stopping the first time it enters an
  5109. accepting state, instead of consuming input until it determines that no
  5110. further matching is possible (a "jam" state).  This is actually easier
  5111. to implement than longest leftmost match (which flex does).
  5112.  
  5113.    But it's also much less useful than longest leftmost match.  In
  5114. general, when you find yourself wishing for non-greedy matching, that's
  5115. usually a sign that you're trying to make the scanner do some parsing.
  5116. That's generally the wrong approach, since it lacks the power to do a
  5117. decent job.  Better is to either introduce a separate parser, or to
  5118. split the scanner into multiple scanners using (exclusive) start
  5119. conditions.
  5120.  
  5121.    You might have a separate start state once you've seen the `BEGIN'.
  5122. In that state, you might then have a regex that will match `END' (to
  5123. kick you out of the state), and perhaps `(.|\n)' to get a single
  5124. character within the chunk ...
  5125.  
  5126.    This approach also has much better error-reporting properties.
  5127.  
  5128. 
  5129. File: flex,  Node: Memory leak - 16386 bytes allocated by malloc.,  Next: How do I track the byte offset for lseek()?,  Prev: Why doesnt flex have non-greedy operators like perl does?,  Up: FAQ
  5130.  
  5131. Memory leak - 16386 bytes allocated by malloc.
  5132. ==============================================
  5133.  
  5134. UPDATED 2002-07-10: As of `flex' version 2.5.9, this leak means that
  5135. you did not call `yylex_destroy()'. If you are using an earlier version
  5136. of `flex', then read on.
  5137.  
  5138.    The leak is about 16426 bytes.  That is, (8192 * 2 + 2) for the
  5139. read-buffer, and about 40 for `struct yy_buffer_state' (depending upon
  5140. alignment). The leak is in the non-reentrant C scanner only (NOT in the
  5141. reentrant scanner, NOT in the C++ scanner). Since `flex' doesn't know
  5142. when you are done, the buffer is never freed.
  5143.  
  5144.    However, the leak won't multiply since the buffer is reused no
  5145. matter how many times you call `yylex()'.
  5146.  
  5147.    If you want to reclaim the memory when you are completely done
  5148. scanning, then you might try this:
  5149.  
  5150.  
  5151.      /* For non-reentrant C scanner only. */
  5152.      yy_delete_buffer(YY_CURRENT_BUFFER);
  5153.      yy_init = 1;
  5154.  
  5155.    Note: `yy_init' is an "internal variable", and hasn't been tested in
  5156. this situation. It is possible that some other globals may need
  5157. resetting as well.
  5158.  
  5159. 
  5160. File: flex,  Node: How do I track the byte offset for lseek()?,  Next: How do I use my own I/O classes in a C++ scanner?,  Prev: Memory leak - 16386 bytes allocated by malloc.,  Up: FAQ
  5161.  
  5162. How do I track the byte offset for lseek()?
  5163. ===========================================
  5164.  
  5165.  
  5166.      >   We thought that it would be possible to have this number through the
  5167.      >   evaluation of the following expression:
  5168.      >
  5169.      >   seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf
  5170.  
  5171.    While this is the right idea, it has two problems.  The first is that
  5172. it's possible that `flex' will request less than `YY_READ_BUF_SIZE'
  5173. during an invocation of `YY_INPUT' (or that your input source will
  5174. return less even though `YY_READ_BUF_SIZE' bytes were requested).  The
  5175. second problem is that when refilling its internal buffer, `flex' keeps
  5176. some characters from the previous buffer (because usually it's in the
  5177. middle of a match, and needs those characters to construct `yytext' for
  5178. the match once it's done).  Because of this, `yy_c_buf_p -
  5179. YY_CURRENT_BUFFER->yy_ch_buf' won't be exactly the number of characters
  5180. already read from the current buffer.
  5181.  
  5182.    An alternative solution is to count the number of characters you've
  5183. matched since starting to scan.  This can be done by using
  5184. `YY_USER_ACTION'.  For example,
  5185.  
  5186.  
  5187.      #define YY_USER_ACTION num_chars += yyleng;
  5188.  
  5189.    (You need to be careful to update your bookkeeping if you use
  5190. `yymore('), `yyless()', `unput()', or `input()'.)
  5191.  
  5192. 
  5193. File: flex,  Node: How do I use my own I/O classes in a C++ scanner?,  Next: How do I skip as many chars as possible?,  Prev: How do I track the byte offset for lseek()?,  Up: FAQ
  5194.  
  5195. How do I use my own I/O classes in a C++ scanner?
  5196. =================================================
  5197.  
  5198. When the flex C++ scanning class rewrite finally happens, then this
  5199. sort of thing should become much easier.
  5200.  
  5201.    You can do this by passing the various functions (such as
  5202. `LexerInput()' and `LexerOutput()') NULL `iostream*''s, and then
  5203. dealing with your own I/O classes surreptitiously (i.e., stashing them
  5204. in special member variables).  This works because the only assumption
  5205. about the lexer regarding what's done with the iostream's is that
  5206. they're ultimately passed to `LexerInput()' and `LexerOutput', which
  5207. then do whatever is necessary with them.
  5208.  
  5209. 
  5210. File: flex,  Node: How do I skip as many chars as possible?,  Next: deleteme00,  Prev: How do I use my own I/O classes in a C++ scanner?,  Up: FAQ
  5211.  
  5212. How do I skip as many chars as possible?
  5213. ========================================
  5214.  
  5215. How do I skip as many chars as possible - without interfering with the
  5216. other patterns?
  5217.  
  5218.    In the example below, we want to skip over characters until we see
  5219. the phrase "endskip". The following will _NOT_ work correctly (do you
  5220. see why not?)
  5221.  
  5222.  
  5223.      /* INCORRECT SCANNER */
  5224.      %x SKIP
  5225.      %%
  5226.      <INITIAL>startskip   BEGIN(SKIP);
  5227.      ...
  5228.      <SKIP>"endskip"       BEGIN(INITIAL);
  5229.      <SKIP>.*             ;
  5230.  
  5231.    The problem is that the pattern .* will eat up the word "endskip."
  5232. The simplest (but slow) fix is:
  5233.  
  5234.  
  5235.      <SKIP>"endskip"      BEGIN(INITIAL);
  5236.      <SKIP>.              ;
  5237.  
  5238.    The fix involves making the second rule match more, without making
  5239. it match "endskip" plus something else.  So for example:
  5240.  
  5241.  
  5242.      <SKIP>"endskip"     BEGIN(INITIAL);
  5243.      <SKIP>[^e]+         ;
  5244.      <SKIP>.                ;/* so you eat up e's, too */
  5245.  
  5246. 
  5247. File: flex,  Node: deleteme00,  Next: Are certain equivalent patterns faster than others?,  Prev: How do I skip as many chars as possible?,  Up: FAQ
  5248.  
  5249. deleteme00
  5250. ==========
  5251.  
  5252.  
  5253.      QUESTION:
  5254.      When was flex born?
  5255.  
  5256.      Vern Paxson took over
  5257.      the Software Tools lex project from Jef Poskanzer in 1982.  At that point it
  5258.      was written in Ratfor.  Around 1987 or so, Paxson translated it into C, and
  5259.      a legend was born :-).
  5260.  
  5261. 
  5262. File: flex,  Node: Are certain equivalent patterns faster than others?,  Next: Is backing up a big deal?,  Prev: deleteme00,  Up: FAQ
  5263.  
  5264. Are certain equivalent patterns faster than others?
  5265. ===================================================
  5266.  
  5267.  
  5268.      To: Adoram Rogel <adoram@orna.hybridge.com>
  5269.      Subject: Re: Flex 2.5.2 performance questions
  5270.      In-reply-to: Your message of Wed, 18 Sep 96 11:12:17 EDT.
  5271.      Date: Wed, 18 Sep 96 10:51:02 PDT
  5272.      From: Vern Paxson <vern>
  5273.  
  5274.      [Note, the most recent flex release is 2.5.4, which you can get from
  5275.      ftp.ee.lbl.gov.  It has bug fixes over 2.5.2 and 2.5.3.]
  5276.  
  5277.      > 1. Using the pattern
  5278.      >    ([Ff](oot)?)?[Nn](ote)?(\.)?
  5279.      >    instead of
  5280.      >    (((F|f)oot(N|n)ote)|((N|n)ote)|((N|n)\.)|((F|f)(N|n)(\.)))
  5281.      >    (in a very complicated flex program) caused the program to slow from
  5282.      >    300K+/min to 100K/min (no other changes were done).
  5283.  
  5284.      These two are not equivalent.  For example, the first can match "footnote."
  5285.      but the second can only match "footnote".  This is almost certainly the
  5286.      cause in the discrepancy - the slower scanner run is matching more tokens,
  5287.      and/or having to do more backing up.
  5288.  
  5289.      > 2. Which of these two are better: [Ff]oot or (F|f)oot ?
  5290.  
  5291.      From a performance point of view, they're equivalent (modulo presumably
  5292.      minor effects such as memory cache hit rates; and the presence of trailing
  5293.      context, see below).  From a space point of view, the first is slightly
  5294.      preferable.
  5295.  
  5296.      > 3. I have a pattern that look like this:
  5297.      >    pats {p1}|{p2}|{p3}|...|{p50}     (50 patterns ORd)
  5298.      >
  5299.      >    running yet another complicated program that includes the following rule:
  5300.      >    <snext>{and}/{no4}{bb}{pats}
  5301.      >
  5302.      >    gets me to "too complicated - over 32,000 states"...
  5303.  
  5304.      I can't tell from this example whether the trailing context is variable-length
  5305.      or fixed-length (it could be the latter if {and} is fixed-length).  If it's
  5306.      variable length, which flex -p will tell you, then this reflects a basic
  5307.      performance problem, and if you can eliminate it by restructuring your
  5308.      scanner, you will see significant improvement.
  5309.  
  5310.      >    so I divided {pats} to {pats1}, {pats2},..., {pats5} each consists of about
  5311.      >    10 patterns and changed the rule to be 5 rules.
  5312.      >    This did compile, but what is the rule of thumb here ?
  5313.  
  5314.      The rule is to avoid trailing context other than fixed-length, in which for
  5315.      a/b, either the 'a' pattern or the 'b' pattern have a fixed length.  Use
  5316.      of the '|' operator automatically makes the pattern variable length, so in
  5317.      this case '[Ff]oot' is preferred to '(F|f)oot'.
  5318.  
  5319.      > 4. I changed a rule that looked like this:
  5320.      >    <snext8>{and}{bb}/{ROMAN}[^A-Za-z] { BEGIN...
  5321.      >
  5322.      >    to the next 2 rules:
  5323.      >    <snext8>{and}{bb}/{ROMAN}[A-Za-z] { ECHO;}
  5324.      >    <snext8>{and}{bb}/{ROMAN}         { BEGIN...
  5325.      >
  5326.      >    Again, I understand the using [^...] will cause a great performance loss
  5327.  
  5328.      Actually, it doesn't cause any sort of performance loss.  It's a surprising
  5329.      fact about regular expressions that they always match in linear time
  5330.      regardless of how complex they are.
  5331.  
  5332.      >    but are there any specific rules about it ?
  5333.  
  5334.      See the "Performance Considerations" section of the man page, and also
  5335.      the example in MISC/fastwc/.
  5336.  
  5337.              Vern
  5338.  
  5339. 
  5340. File: flex,  Node: Is backing up a big deal?,  Next: Can I fake multi-byte character support?,  Prev: Are certain equivalent patterns faster than others?,  Up: FAQ
  5341.  
  5342. Is backing up a big deal?
  5343. =========================
  5344.  
  5345.  
  5346.      To: Adoram Rogel <adoram@hybridge.com>
  5347.      Subject: Re: Flex 2.5.2 performance questions
  5348.      In-reply-to: Your message of Thu, 19 Sep 96 10:16:04 EDT.
  5349.      Date: Thu, 19 Sep 96 09:58:00 PDT
  5350.      From: Vern Paxson <vern>
  5351.  
  5352.      > a lot about the backing up problem.
  5353.      > I believe that there lies my biggest problem, and I'll try to improve
  5354.      > it.
  5355.  
  5356.      Since you have variable trailing context, this is a bigger performance
  5357.      problem.  Fixing it is usually easier than fixing backing up, which in a
  5358.      complicated scanner (yours seems to fit the bill) can be extremely
  5359.      difficult to do correctly.
  5360.  
  5361.      You also don't mention what flags you are using for your scanner.
  5362.      -f makes a large speed difference, and -Cfe buys you nearly as much
  5363.      speed but the resulting scanner is considerably smaller.
  5364.  
  5365.      > I have an | operator in {and} and in {pats} so both of them are variable
  5366.      > length.
  5367.  
  5368.      -p should have reported this.
  5369.  
  5370.      > Is changing one of them to fixed-length is enough ?
  5371.  
  5372.      Yes.
  5373.  
  5374.      > Is it possible to change the 32,000 states limit ?
  5375.  
  5376.      Yes.  I've appended instructions on how.  Before you make this change,
  5377.      though, you should think about whether there are ways to fundamentally
  5378.      simplify your scanner - those are certainly preferable!
  5379.  
  5380.              Vern
  5381.  
  5382.      To increase the 32K limit (on a machine with 32 bit integers), you increase
  5383.      the magnitude of the following in flexdef.h:
  5384.  
  5385.      #define JAMSTATE -32766 /* marks a reference to the state that always jams */
  5386.      #define MAXIMUM_MNS 31999
  5387.      #define BAD_SUBSCRIPT -32767
  5388.      #define MAX_SHORT 32700
  5389.  
  5390.      Adding a 0 or two after each should do the trick.
  5391.  
  5392. 
  5393. File: flex,  Node: Can I fake multi-byte character support?,  Next: deleteme01,  Prev: Is backing up a big deal?,  Up: FAQ
  5394.  
  5395. Can I fake multi-byte character support?
  5396. ========================================
  5397.  
  5398.  
  5399.      To: Heeman_Lee@hp.com
  5400.      Subject: Re: flex - multi-byte support?
  5401.      In-reply-to: Your message of Thu, 03 Oct 1996 17:24:04 PDT.
  5402.      Date: Fri, 04 Oct 1996 11:42:18 PDT
  5403.      From: Vern Paxson <vern>
  5404.  
  5405.      >      I assume as long as my *.l file defines the
  5406.      >      range of expected character code values (in octal format), flex will
  5407.      >      scan the file and read multi-byte characters correctly. But I have no
  5408.      >      confidence in this assumption.
  5409.  
  5410.      Your lack of confidence is justified - this won't work.
  5411.  
  5412.      Flex has in it a widespread assumption that the input is processed
  5413.      one byte at a time.  Fixing this is on the to-do list, but is involved,
  5414.      so it won't happen any time soon.  In the interim, the best I can suggest
  5415.      (unless you want to try fixing it yourself) is to write your rules in
  5416.      terms of pairs of bytes, using definitions in the first section:
  5417.  
  5418.          X    \xfe\xc2
  5419.          ...
  5420.          %%
  5421.          foo{X}bar    found_foo_fe_c2_bar();
  5422.  
  5423.      etc.  Definitely a pain - sorry about that.
  5424.  
  5425.      By the way, the email address you used for me is ancient, indicating you
  5426.      have a very old version of flex.  You can get the most recent, 2.5.4, from
  5427.      ftp.ee.lbl.gov.
  5428.  
  5429.              Vern
  5430.  
  5431. 
  5432. File: flex,  Node: deleteme01,  Next: Can you discuss some flex internals?,  Prev: Can I fake multi-byte character support?,  Up: FAQ
  5433.  
  5434. deleteme01
  5435. ==========
  5436.  
  5437.  
  5438.      To: moleary@primus.com
  5439.      Subject: Re: Flex / Unicode compatibility question
  5440.      In-reply-to: Your message of Tue, 22 Oct 1996 10:15:42 PDT.
  5441.      Date: Tue, 22 Oct 1996 11:06:13 PDT
  5442.      From: Vern Paxson <vern>
  5443.  
  5444.      Unfortunately flex at the moment has a widespread assumption within it
  5445.      that characters are processed 8 bits at a time.  I don't see any easy
  5446.      fix for this (other than writing your rules in terms of double characters -
  5447.      a pain).  I also don't know of a wider lex, though you might try surfing
  5448.      the Plan 9 stuff because I know it's a Unicode system, and also the PCCT
  5449.      toolkit (try searching say Alta Vista for "Purdue Compiler Construction
  5450.      Toolkit").
  5451.  
  5452.      Fixing flex to handle wider characters is on the long-term to-do list.
  5453.      But since flex is a strictly spare-time project these days, this probably
  5454.      won't happen for quite a while, unless someone else does it first.
  5455.  
  5456.              Vern
  5457.  
  5458. 
  5459. File: flex,  Node: Can you discuss some flex internals?,  Next: unput() messes up yy_at_bol,  Prev: deleteme01,  Up: FAQ
  5460.  
  5461. Can you discuss some flex internals?
  5462. ====================================
  5463.  
  5464.  
  5465.      To: Johan Linde <jl@theophys.kth.se>
  5466.      Subject: Re: translation of flex
  5467.      In-reply-to: Your message of Sun, 10 Nov 1996 09:16:36 PST.
  5468.      Date: Mon, 11 Nov 1996 10:33:50 PST
  5469.      From: Vern Paxson <vern>
  5470.  
  5471.      > I'm working for the Swedish team translating GNU program, and I'm currently
  5472.      > working with flex. I have a few questions about some of the messages which
  5473.      > I hope you can answer.
  5474.  
  5475.      All of the things you're wondering about, by the way, concerning flex
  5476.      internals - probably the only person who understands what they mean in
  5477.      English is me!  So I wouldn't worry too much about getting them right.
  5478.      That said ...
  5479.  
  5480.      > #: main.c:545
  5481.      > msgid "  %d protos created\n"
  5482.      >
  5483.      > Does proto mean prototype?
  5484.  
  5485.      Yes - prototypes of state compression tables.
  5486.  
  5487.      > #: main.c:539
  5488.      > msgid "  %d/%d (peak %d) template nxt-chk entries created\n"
  5489.      >
  5490.      > Here I'm mainly puzzled by 'nxt-chk'. I guess it means 'next-check'. (?)
  5491.      > However, 'template next-check entries' doesn't make much sense to me. To be
  5492.      > able to find a good translation I need to know a little bit more about it.
  5493.  
  5494.      There is a scheme in the Aho/Sethi/Ullman compiler book for compressing
  5495.      scanner tables.  It involves creating two pairs of tables.  The first has
  5496.      "base" and "default" entries, the second has "next" and "check" entries.
  5497.      The "base" entry is indexed by the current state and yields an index into
  5498.      the next/check table.  The "default" entry gives what to do if the state
  5499.      transition isn't found in next/check.  The "next" entry gives the next
  5500.      state to enter, but only if the "check" entry verifies that this entry is
  5501.      correct for the current state.  Flex creates templates of series of
  5502.      next/check entries and then encodes differences from these templates as a
  5503.      way to compress the tables.
  5504.  
  5505.      > #: main.c:533
  5506.      > msgid "  %d/%d base-def entries created\n"
  5507.      >
  5508.      > The same problem here for 'base-def'.
  5509.  
  5510.      See above.
  5511.  
  5512.              Vern
  5513.  
  5514. 
  5515. File: flex,  Node: unput() messes up yy_at_bol,  Next: The | operator is not doing what I want,  Prev: Can you discuss some flex internals?,  Up: FAQ
  5516.  
  5517. unput() messes up yy_at_bol
  5518. ===========================
  5519.  
  5520.  
  5521.      To: Xinying Li <xli@npac.syr.edu>
  5522.      Subject: Re: FLEX ?
  5523.      In-reply-to: Your message of Wed, 13 Nov 1996 17:28:38 PST.
  5524.      Date: Wed, 13 Nov 1996 19:51:54 PST
  5525.      From: Vern Paxson <vern>
  5526.  
  5527.      > "unput()" them to input flow, question occurs. If I do this after I scan
  5528.      > a carriage, the variable "YY_CURRENT_BUFFER->yy_at_bol" is changed. That
  5529.      > means the carriage flag has gone.
  5530.  
  5531.      You can control this by calling yy_set_bol().  It's described in the manual.
  5532.  
  5533.      >      And if in pre-reading it goes to the end of file, is anything done
  5534.      > to control the end of curren buffer and end of file?
  5535.  
  5536.      No, there's no way to put back an end-of-file.
  5537.  
  5538.      >      By the way I am using flex 2.5.2 and using the "-l".
  5539.  
  5540.      The latest release is 2.5.4, by the way.  It fixes some bugs in 2.5.2 and
  5541.      2.5.3.  You can get it from ftp.ee.lbl.gov.
  5542.  
  5543.              Vern
  5544.  
  5545. 
  5546. File: flex,  Node: The | operator is not doing what I want,  Next: Why can't flex understand this variable trailing context pattern?,  Prev: unput() messes up yy_at_bol,  Up: FAQ
  5547.  
  5548. The | operator is not doing what I want
  5549. =======================================
  5550.  
  5551.  
  5552.      To: Alain.ISSARD@st.com
  5553.      Subject: Re: Start condition with FLEX
  5554.      In-reply-to: Your message of Mon, 18 Nov 1996 09:45:02 PST.
  5555.      Date: Mon, 18 Nov 1996 10:41:34 PST
  5556.      From: Vern Paxson <vern>
  5557.  
  5558.      > I am not able to use the start condition scope and to use the | (OR) with
  5559.      > rules having start conditions.
  5560.  
  5561.      The problem is that if you use '|' as a regular expression operator, for
  5562.      example "a|b" meaning "match either 'a' or 'b'", then it must *not* have
  5563.      any blanks around it.  If you instead want the special '|' *action* (which
  5564.      from your scanner appears to be the case), which is a way of giving two
  5565.      different rules the same action:
  5566.  
  5567.          foo    |
  5568.          bar    matched_foo_or_bar();
  5569.  
  5570.      then '|' *must* be separated from the first rule by whitespace and *must*
  5571.      be followed by a new line.  You *cannot* write it as:
  5572.  
  5573.          foo | bar    matched_foo_or_bar();
  5574.  
  5575.      even though you might think you could because yacc supports this syntax.
  5576.      The reason for this unfortunately incompatibility is historical, but it's
  5577.      unlikely to be changed.
  5578.  
  5579.      Your problems with start condition scope are simply due to syntax errors
  5580.      from your use of '|' later confusing flex.
  5581.  
  5582.      Let me know if you still have problems.
  5583.  
  5584.              Vern
  5585.  
  5586. 
  5587. File: flex,  Node: Why can't flex understand this variable trailing context pattern?,  Next: The ^ operator isn't working,  Prev: The | operator is not doing what I want,  Up: FAQ
  5588.  
  5589. Why can't flex understand this variable trailing context pattern?
  5590. =================================================================
  5591.  
  5592.  
  5593.      To: Gregory Margo <gmargo@newton.vip.best.com>
  5594.      Subject: Re: flex-2.5.3 bug report
  5595.      In-reply-to: Your message of Sat, 23 Nov 1996 16:50:09 PST.
  5596.      Date: Sat, 23 Nov 1996 17:07:32 PST
  5597.      From: Vern Paxson <vern>
  5598.  
  5599.      > Enclosed is a lex file that "real" lex will process, but I cannot get
  5600.      > flex to process it.  Could you try it and maybe point me in the right direction?
  5601.  
  5602.      Your problem is that some of the definitions in the scanner use the '/'
  5603.      trailing context operator, and have it enclosed in ()'s.  Flex does not
  5604.      allow this operator to be enclosed in ()'s because doing so allows undefined
  5605.      regular expressions such as "(a/b)+".  So the solution is to remove the
  5606.      parentheses.  Note that you must also be building the scanner with the -l
  5607.      option for AT&T lex compatibility.  Without this option, flex automatically
  5608.      encloses the definitions in parentheses.
  5609.  
  5610.              Vern
  5611.  
  5612. 
  5613. File: flex,  Node: The ^ operator isn't working,  Next: Trailing context is getting confused with trailing optional patterns,  Prev: Why can't flex understand this variable trailing context pattern?,  Up: FAQ
  5614.  
  5615. The ^ operator isn't working
  5616. ============================
  5617.  
  5618.  
  5619.      To: Thomas Hadig <hadig@toots.physik.rwth-aachen.de>
  5620.      Subject: Re: Flex Bug ?
  5621.      In-reply-to: Your message of Tue, 26 Nov 1996 14:35:01 PST.
  5622.      Date: Tue, 26 Nov 1996 11:15:05 PST
  5623.      From: Vern Paxson <vern>
  5624.  
  5625.      > In my lexer code, i have the line :
  5626.      > ^\*.*          { }
  5627.      >
  5628.      > Thus all lines starting with an astrix (*) are comment lines.
  5629.      > This does not work !
  5630.  
  5631.      I can't get this problem to reproduce - it works fine for me.  Note
  5632.      though that if what you have is slightly different:
  5633.  
  5634.          COMMENT    ^\*.*
  5635.          %%
  5636.          {COMMENT}    { }
  5637.  
  5638.      then it won't work, because flex pushes back macro definitions enclosed
  5639.      in ()'s, so the rule becomes
  5640.  
  5641.          (^\*.*)        { }
  5642.  
  5643.      and now that the '^' operator is not at the immediate beginning of the
  5644.      line, it's interpreted as just a regular character.  You can avoid this
  5645.      behavior by using the "-l" lex-compatibility flag, or "%option lex-compat".
  5646.  
  5647.              Vern
  5648.  
  5649. 
  5650. File: flex,  Node: Trailing context is getting confused with trailing optional patterns,  Next: Is flex GNU or not?,  Prev: The ^ operator isn't working,  Up: FAQ
  5651.  
  5652. Trailing context is getting confused with trailing optional patterns
  5653. ====================================================================
  5654.  
  5655.  
  5656.      To: Adoram Rogel <adoram@hybridge.com>
  5657.      Subject: Re: Flex 2.5.4 BOF ???
  5658.      In-reply-to: Your message of Tue, 26 Nov 1996 16:10:41 PST.
  5659.      Date: Wed, 27 Nov 1996 10:56:25 PST
  5660.      From: Vern Paxson <vern>
  5661.  
  5662.      >     Organization(s)?/[a-z]
  5663.      >
  5664.      > This matched "Organizations" (looking in debug mode, the trailing s
  5665.      > was matched with trailing context instead of the optional (s) in the
  5666.      > end of the word.
  5667.  
  5668.      That should only happen with lex.  Flex can properly match this pattern.
  5669.      (That might be what you're saying, I'm just not sure.)
  5670.  
  5671.      > Is there a way to avoid this dangerous trailing context problem ?
  5672.  
  5673.      Unfortunately, there's no easy way.  On the other hand, I don't see why
  5674.      it should be a problem.  Lex's matching is clearly wrong, and I'd hope
  5675.      that usually the intent remains the same as expressed with the pattern,
  5676.      so flex's matching will be correct.
  5677.  
  5678.              Vern
  5679.  
  5680. 
  5681. File: flex,  Node: Is flex GNU or not?,  Next: ERASEME53,  Prev: Trailing context is getting confused with trailing optional patterns,  Up: FAQ
  5682.  
  5683. Is flex GNU or not?
  5684. ===================
  5685.  
  5686.  
  5687.      To: Cameron MacKinnon <mackin@interlog.com>
  5688.      Subject: Re: Flex documentation bug
  5689.      In-reply-to: Your message of Mon, 02 Dec 1996 00:07:08 PST.
  5690.      Date: Sun, 01 Dec 1996 22:29:39 PST
  5691.      From: Vern Paxson <vern>
  5692.  
  5693.      > I'm not sure how or where to submit bug reports (documentation or
  5694.      > otherwise) for the GNU project stuff ...
  5695.  
  5696.      Well, strictly speaking flex isn't part of the GNU project.  They just
  5697.      distribute it because no one's written a decent GPL'd lex replacement.
  5698.      So you should send bugs directly to me.  Those sent to the GNU folks
  5699.      sometimes find there way to me, but some may drop between the cracks.
  5700.  
  5701.      > In GNU Info, under the section 'Start Conditions', and also in the man
  5702.      > page (mine's dated April '95) is a nice little snippet showing how to
  5703.      > parse C quoted strings into a buffer, defined to be MAX_STR_CONST in
  5704.      > size. Unfortunately, no overflow checking is ever done ...
  5705.  
  5706.      This is already mentioned in the manual:
  5707.  
  5708.      Finally, here's an example of how to  match  C-style  quoted
  5709.      strings using exclusive start conditions, including expanded
  5710.      escape sequences (but not including checking  for  a  string
  5711.      that's too long):
  5712.  
  5713.      The reason for not doing the overflow checking is that it will needlessly
  5714.      clutter up an example whose main purpose is just to demonstrate how to
  5715.      use flex.
  5716.  
  5717.      The latest release is 2.5.4, by the way, available from ftp.ee.lbl.gov.
  5718.  
  5719.              Vern
  5720.  
  5721. 
  5722. File: flex,  Node: ERASEME53,  Next: I need to scan if-then-else blocks and while loops,  Prev: Is flex GNU or not?,  Up: FAQ
  5723.  
  5724. ERASEME53
  5725. =========
  5726.  
  5727.  
  5728.      To: tsv@cs.UManitoba.CA
  5729.      Subject: Re: Flex (reg)..
  5730.      In-reply-to: Your message of Thu, 06 Mar 1997 23:50:16 PST.
  5731.      Date: Thu, 06 Mar 1997 15:54:19 PST
  5732.      From: Vern Paxson <vern>
  5733.  
  5734.      > [:alpha:] ([:alnum:] | \\_)*
  5735.  
  5736.      If your rule really has embedded blanks as shown above, then it won't
  5737.      work, as the first blank delimits the rule from the action.  (It wouldn't
  5738.      even compile ...)  You need instead:
  5739.  
  5740.      [:alpha:]([:alnum:]|\\_)*
  5741.  
  5742.      and that should work fine - there's no restriction on what can go inside
  5743.      of ()'s except for the trailing context operator, '/'.
  5744.  
  5745.              Vern
  5746.  
  5747. 
  5748. File: flex,  Node: I need to scan if-then-else blocks and while loops,  Next: ERASEME55,  Prev: ERASEME53,  Up: FAQ
  5749.  
  5750. I need to scan if-then-else blocks and while loops
  5751. ==================================================
  5752.  
  5753.  
  5754.      To: "Mike Stolnicki" <mstolnic@ford.com>
  5755.      Subject: Re: FLEX help
  5756.      In-reply-to: Your message of Fri, 30 May 1997 13:33:27 PDT.
  5757.      Date: Fri, 30 May 1997 10:46:35 PDT
  5758.      From: Vern Paxson <vern>
  5759.  
  5760.      > We'd like to add "if-then-else", "while", and "for" statements to our
  5761.      > language ...
  5762.      > We've investigated many possible solutions.  The one solution that seems
  5763.      > the most reasonable involves knowing the position of a TOKEN in yyin.
  5764.  
  5765.      I strongly advise you to instead build a parse tree (abstract syntax tree)
  5766.      and loop over that instead.  You'll find this has major benefits in keeping
  5767.      your interpreter simple and extensible.
  5768.  
  5769.      That said, the functionality you mention for get_position and set_position
  5770.      have been on the to-do list for a while.  As flex is a purely spare-time
  5771.      project for me, no guarantees when this will be added (in particular, it
  5772.      for sure won't be for many months to come).
  5773.  
  5774.              Vern
  5775.  
  5776. 
  5777. File: flex,  Node: ERASEME55,  Next: ERASEME56,  Prev: I need to scan if-then-else blocks and while loops,  Up: FAQ
  5778.  
  5779. ERASEME55
  5780. =========
  5781.  
  5782.  
  5783.      To: Colin Paul Adams <colin@colina.demon.co.uk>
  5784.      Subject: Re: Flex C++ classes and Bison
  5785.      In-reply-to: Your message of 09 Aug 1997 17:11:41 PDT.
  5786.      Date: Fri, 15 Aug 1997 10:48:19 PDT
  5787.      From: Vern Paxson <vern>
  5788.  
  5789.      > #define YY_DECL   int yylex (YYSTYPE *lvalp, struct parser_control
  5790.      > *parm)
  5791.      >
  5792.      > I have been trying  to get this to work as a C++ scanner, but it does
  5793.      > not appear to be possible (warning that it matches no declarations in
  5794.      > yyFlexLexer, or something like that).
  5795.      >
  5796.      > Is this supposed to be possible, or is it being worked on (I DID
  5797.      > notice the comment that scanner classes are still experimental, so I'm
  5798.      > not too hopeful)?
  5799.  
  5800.      What you need to do is derive a subclass from yyFlexLexer that provides
  5801.      the above yylex() method, squirrels away lvalp and parm into member
  5802.      variables, and then invokes yyFlexLexer::yylex() to do the regular scanning.
  5803.  
  5804.              Vern
  5805.  
  5806. 
  5807. File: flex,  Node: ERASEME56,  Next: ERASEME57,  Prev: ERASEME55,  Up: FAQ
  5808.  
  5809. ERASEME56
  5810. =========
  5811.  
  5812.  
  5813.      To: Mikael.Latvala@lmf.ericsson.se
  5814.      Subject: Re: Possible mistake in Flex v2.5 document
  5815.      In-reply-to: Your message of Fri, 05 Sep 1997 16:07:24 PDT.
  5816.      Date: Fri, 05 Sep 1997 10:01:54 PDT
  5817.      From: Vern Paxson <vern>
  5818.  
  5819.      > In that example you show how to count comment lines when using
  5820.      > C style /* ... */ comments. My question is, shouldn't you take into
  5821.      > account a scenario where end of a comment marker occurs inside
  5822.      > character or string literals?
  5823.  
  5824.      The scanner certainly needs to also scan character and string literals.
  5825.      However it does that (there's an example in the man page for strings), the
  5826.      lexer will recognize the beginning of the literal before it runs across the
  5827.      embedded "/*".  Consequently, it will finish scanning the literal before it
  5828.      even considers the possibility of matching "/*".
  5829.  
  5830.      Example:
  5831.  
  5832.          '([^']*|{ESCAPE_SEQUENCE})'
  5833.  
  5834.      will match all the text between the ''s (inclusive).  So the lexer
  5835.      considers this as a token beginning at the first ', and doesn't even
  5836.      attempt to match other tokens inside it.
  5837.  
  5838.      I thinnk this subtlety is not worth putting in the manual, as I suspect
  5839.      it would confuse more people than it would enlighten.
  5840.  
  5841.              Vern
  5842.  
  5843. 
  5844. File: flex,  Node: ERASEME57,  Next: Is there a repository for flex scanners?,  Prev: ERASEME56,  Up: FAQ
  5845.  
  5846. ERASEME57
  5847. =========
  5848.  
  5849.  
  5850.      To: "Marty Leisner" <leisner@sdsp.mc.xerox.com>
  5851.      Subject: Re: flex limitations
  5852.      In-reply-to: Your message of Sat, 06 Sep 1997 11:27:21 PDT.
  5853.      Date: Mon, 08 Sep 1997 11:38:08 PDT
  5854.      From: Vern Paxson <vern>
  5855.  
  5856.      > %%
  5857.      > [a-zA-Z]+       /* skip a line */
  5858.      >                 {  printf("got %s\n", yytext); }
  5859.      > %%
  5860.  
  5861.      What version of flex are you using?  If I feed this to 2.5.4, it complains:
  5862.  
  5863.          "bug.l", line 5: EOF encountered inside an action
  5864.          "bug.l", line 5: unrecognized rule
  5865.          "bug.l", line 5: fatal parse error
  5866.  
  5867.      Not the world's greatest error message, but it manages to flag the problem.
  5868.  
  5869.      (With the introduction of start condition scopes, flex can't accommodate
  5870.      an action on a separate line, since it's ambiguous with an indented rule.)
  5871.  
  5872.      You can get 2.5.4 from ftp.ee.lbl.gov.
  5873.  
  5874.              Vern
  5875.  
  5876. 
  5877. File: flex,  Node: Is there a repository for flex scanners?,  Next: How can I conditionally compile or preprocess my flex input file?,  Prev: ERASEME57,  Up: FAQ
  5878.  
  5879. Is there a repository for flex scanners?
  5880. ========================================
  5881.  
  5882. Not that we know of. You might try asking on comp.compilers.
  5883.  
  5884. 
  5885. File: flex,  Node: How can I conditionally compile or preprocess my flex input file?,  Next: Where can I find grammars for lex and yacc?,  Prev: Is there a repository for flex scanners?,  Up: FAQ
  5886.  
  5887. How can I conditionally compile or preprocess my flex input file?
  5888. =================================================================
  5889.  
  5890. Flex doesn't have a preprocessor like C does.  You might try using m4,
  5891. or the C preprocessor plus a sed script to clean up the result.
  5892.  
  5893. 
  5894. File: flex,  Node: Where can I find grammars for lex and yacc?,  Next: I get an end-of-buffer message for each character scanned.,  Prev: How can I conditionally compile or preprocess my flex input file?,  Up: FAQ
  5895.  
  5896. Where can I find grammars for lex and yacc?
  5897. ===========================================
  5898.  
  5899. In the sources for flex and bison.
  5900.  
  5901. 
  5902. File: flex,  Node: I get an end-of-buffer message for each character scanned.,  Next: unnamed-faq-62,  Prev: Where can I find grammars for lex and yacc?,  Up: FAQ
  5903.  
  5904. I get an end-of-buffer message for each character scanned.
  5905. ==========================================================
  5906.  
  5907. This will happen if your LexerInput() function returns only one
  5908. character at a time, which can happen either if you're scanner is
  5909. "interactive", or if the streams library on your platform always
  5910. returns 1 for yyin->gcount().
  5911.  
  5912.    Solution: override LexerInput() with a version that returns whole
  5913. buffers.
  5914.  
  5915. 
  5916. File: flex,  Node: unnamed-faq-62,  Next: unnamed-faq-63,  Prev: I get an end-of-buffer message for each character scanned.,  Up: FAQ
  5917.  
  5918. unnamed-faq-62
  5919. ==============
  5920.  
  5921.  
  5922.      To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
  5923.      Subject: Re: Flex maximums
  5924.      In-reply-to: Your message of Mon, 17 Nov 1997 17:16:06 PST.
  5925.      Date: Mon, 17 Nov 1997 17:16:15 PST
  5926.      From: Vern Paxson <vern>
  5927.  
  5928.      > I took a quick look into the flex-sources and altered some #defines in
  5929.      > flexdefs.h:
  5930.      >
  5931.      >     #define INITIAL_MNS 64000
  5932.      >     #define MNS_INCREMENT 1024000
  5933.      >     #define MAXIMUM_MNS 64000
  5934.  
  5935.      The things to fix are to add a couple of zeroes to:
  5936.  
  5937.      #define JAMSTATE -32766 /* marks a reference to the state that always jams */
  5938.      #define MAXIMUM_MNS 31999
  5939.      #define BAD_SUBSCRIPT -32767
  5940.      #define MAX_SHORT 32700
  5941.  
  5942.      and, if you get complaints about too many rules, make the following change too:
  5943.  
  5944.          #define YY_TRAILING_MASK 0x200000
  5945.          #define YY_TRAILING_HEAD_MASK 0x400000
  5946.  
  5947.      - Vern
  5948.  
  5949. 
  5950. File: flex,  Node: unnamed-faq-63,  Next: unnamed-faq-64,  Prev: unnamed-faq-62,  Up: FAQ
  5951.  
  5952. unnamed-faq-63
  5953. ==============
  5954.  
  5955.  
  5956.      To: jimmey@lexis-nexis.com (Jimmey Todd)
  5957.      Subject: Re: FLEX question regarding istream vs ifstream
  5958.      In-reply-to: Your message of Mon, 08 Dec 1997 15:54:15 PST.
  5959.      Date: Mon, 15 Dec 1997 13:21:35 PST
  5960.      From: Vern Paxson <vern>
  5961.  
  5962.      >         stdin_handle = YY_CURRENT_BUFFER;
  5963.      >         ifstream fin( "aFile" );
  5964.      >         yy_switch_to_buffer( yy_create_buffer( fin, YY_BUF_SIZE ) );
  5965.      >
  5966.      > What I'm wanting to do, is pass the contents of a file thru one set
  5967.      > of rules and then pass stdin thru another set... It works great if, I
  5968.      > don't use the C++ classes. But since everything else that I'm doing is
  5969.      > in C++, I thought I'd be consistent.
  5970.      >
  5971.      > The problem is that 'yy_create_buffer' is expecting an istream* as it's
  5972.      > first argument (as stated in the man page). However, fin is a ifstream
  5973.      > object. Any ideas on what I might be doing wrong? Any help would be
  5974.      > appreciated. Thanks!!
  5975.  
  5976.      You need to pass &fin, to turn it into an ifstream* instead of an ifstream.
  5977.      Then its type will be compatible with the expected istream*, because ifstream
  5978.      is derived from istream.
  5979.  
  5980.              Vern
  5981.  
  5982. 
  5983. File: flex,  Node: unnamed-faq-64,  Next: unnamed-faq-65,  Prev: unnamed-faq-63,  Up: FAQ
  5984.  
  5985. unnamed-faq-64
  5986. ==============
  5987.  
  5988.  
  5989.      To: Enda Fadian <fadiane@piercom.ie>
  5990.      Subject: Re: Question related to Flex man page?
  5991.      In-reply-to: Your message of Tue, 16 Dec 1997 15:17:34 PST.
  5992.      Date: Tue, 16 Dec 1997 14:17:09 PST
  5993.      From: Vern Paxson <vern>
  5994.  
  5995.      > Can you explain to me what is ment by a long-jump in relation to flex?
  5996.  
  5997.      Using the longjmp() function while inside yylex() or a routine called by it.
  5998.  
  5999.      > what is the flex activation frame.
  6000.  
  6001.      Just yylex()'s stack frame.
  6002.  
  6003.      > As far as I can see yyrestart will bring me back to the sart of the input
  6004.      > file and using flex++ isnot really an option!
  6005.  
  6006.      No, yyrestart() doesn't imply a rewind, even though its name might sound
  6007.      like it does.  It tells the scanner to flush its internal buffers and
  6008.      start reading from the given file at its present location.
  6009.  
  6010.              Vern
  6011.  
  6012. 
  6013. File: flex,  Node: unnamed-faq-65,  Next: unnamed-faq-66,  Prev: unnamed-faq-64,  Up: FAQ
  6014.  
  6015. unnamed-faq-65
  6016. ==============
  6017.  
  6018.  
  6019.      To: hassan@larc.info.uqam.ca (Hassan Alaoui)
  6020.      Subject: Re: Need urgent Help
  6021.      In-reply-to: Your message of Sat, 20 Dec 1997 19:38:19 PST.
  6022.      Date: Sun, 21 Dec 1997 21:30:46 PST
  6023.      From: Vern Paxson <vern>
  6024.  
  6025.      > /usr/lib/yaccpar: In function `int yyparse()':
  6026.      > /usr/lib/yaccpar:184: warning: implicit declaration of function `int yylex(...)'
  6027.      >
  6028.      > ld: Undefined symbol
  6029.      >    _yylex
  6030.      >    _yyparse
  6031.      >    _yyin
  6032.  
  6033.      This is a known problem with Solaris C++ (and/or Solaris yacc).  I believe
  6034.      the fix is to explicitly insert some 'extern "C"' statements for the
  6035.      corresponding routines/symbols.
  6036.  
  6037.              Vern
  6038.  
  6039. 
  6040. File: flex,  Node: unnamed-faq-66,  Next: unnamed-faq-67,  Prev: unnamed-faq-65,  Up: FAQ
  6041.  
  6042. unnamed-faq-66
  6043. ==============
  6044.  
  6045.  
  6046.      To: mc0307@mclink.it
  6047.      Cc: gnu@prep.ai.mit.edu
  6048.      Subject: Re: [mc0307@mclink.it: Help request]
  6049.      In-reply-to: Your message of Fri, 12 Dec 1997 17:57:29 PST.
  6050.      Date: Sun, 21 Dec 1997 22:33:37 PST
  6051.      From: Vern Paxson <vern>
  6052.  
  6053.      > This is my definition for float and integer types:
  6054.      > . . .
  6055.      > NZD          [1-9]
  6056.      > ...
  6057.      > I've tested my program on other lex version (on UNIX Sun Solaris an HP
  6058.      > UNIX) and it work well, so I think that my definitions are correct.
  6059.      > There are any differences between Lex and Flex?
  6060.  
  6061.      There are indeed differences, as discussed in the man page.  The one
  6062.      you are probably running into is that when flex expands a name definition,
  6063.      it puts parentheses around the expansion, while lex does not.  There's
  6064.      an example in the man page of how this can lead to different matching.
  6065.      Flex's behavior complies with the POSIX standard (or at least with the
  6066.      last POSIX draft I saw).
  6067.  
  6068.              Vern
  6069.  
  6070. 
  6071. File: flex,  Node: unnamed-faq-67,  Next: unnamed-faq-68,  Prev: unnamed-faq-66,  Up: FAQ
  6072.  
  6073. unnamed-faq-67
  6074. ==============
  6075.  
  6076.  
  6077.      To: hassan@larc.info.uqam.ca (Hassan Alaoui)
  6078.      Subject: Re: Thanks
  6079.      In-reply-to: Your message of Mon, 22 Dec 1997 16:06:35 PST.
  6080.      Date: Mon, 22 Dec 1997 14:35:05 PST
  6081.      From: Vern Paxson <vern>
  6082.  
  6083.      > Thank you very much for your help. I compile and link well with C++ while
  6084.      > declaring 'yylex ...' extern, But a little problem remains. I get a
  6085.      > segmentation default when executing ( I linked with lfl library) while it
  6086.      > works well when using LEX instead of flex. Do you have some ideas about the
  6087.      > reason for this ?
  6088.  
  6089.      The one possible reason for this that comes to mind is if you've defined
  6090.      yytext as "extern char yytext[]" (which is what lex uses) instead of
  6091.      "extern char *yytext" (which is what flex uses).  If it's not that, then
  6092.      I'm afraid I don't know what the problem might be.
  6093.  
  6094.              Vern
  6095.  
  6096. 
  6097. File: flex,  Node: unnamed-faq-68,  Next: unnamed-faq-69,  Prev: unnamed-faq-67,  Up: FAQ
  6098.  
  6099. unnamed-faq-68
  6100. ==============
  6101.  
  6102.  
  6103.      To: "Bart Niswonger" <NISWONGR@almaden.ibm.com>
  6104.      Subject: Re: flex 2.5: c++ scanners & start conditions
  6105.      In-reply-to: Your message of Tue, 06 Jan 1998 10:34:21 PST.
  6106.      Date: Tue, 06 Jan 1998 19:19:30 PST
  6107.      From: Vern Paxson <vern>
  6108.  
  6109.      > The problem is that when I do this (using %option c++) start
  6110.      > conditions seem to not apply.
  6111.  
  6112.      The BEGIN macro modifies the yy_start variable.  For C scanners, this
  6113.      is a static with scope visible through the whole file.  For C++ scanners,
  6114.      it's a member variable, so it only has visible scope within a member
  6115.      function.  Your lexbegin() routine is not a member function when you
  6116.      build a C++ scanner, so it's not modifying the correct yy_start.  The
  6117.      diagnostic that indicates this is that you found you needed to add
  6118.      a declaration of yy_start in order to get your scanner to compile when
  6119.      using C++; instead, the correct fix is to make lexbegin() a member
  6120.      function (by deriving from yyFlexLexer).
  6121.  
  6122.              Vern
  6123.  
  6124. 
  6125. File: flex,  Node: unnamed-faq-69,  Next: unnamed-faq-70,  Prev: unnamed-faq-68,  Up: FAQ
  6126.  
  6127. unnamed-faq-69
  6128. ==============
  6129.  
  6130.  
  6131.      To: "Boris Zinin" <boris@ippe.rssi.ru>
  6132.      Subject: Re: current position in flex buffer
  6133.      In-reply-to: Your message of Mon, 12 Jan 1998 18:58:23 PST.
  6134.      Date: Mon, 12 Jan 1998 12:03:15 PST
  6135.      From: Vern Paxson <vern>
  6136.  
  6137.      > The problem is how to determine the current position in flex active
  6138.      > buffer when a rule is matched....
  6139.  
  6140.      You will need to keep track of this explicitly, such as by redefining
  6141.      YY_USER_ACTION to count the number of characters matched.
  6142.  
  6143.      The latest flex release, by the way, is 2.5.4, available from ftp.ee.lbl.gov.
  6144.  
  6145.              Vern
  6146.  
  6147. 
  6148. File: flex,  Node: unnamed-faq-70,  Next: unnamed-faq-71,  Prev: unnamed-faq-69,  Up: FAQ
  6149.  
  6150. unnamed-faq-70
  6151. ==============
  6152.  
  6153.  
  6154.      To: Bik.Dhaliwal@bis.org
  6155.      Subject: Re: Flex question
  6156.      In-reply-to: Your message of Mon, 26 Jan 1998 13:05:35 PST.
  6157.      Date: Tue, 27 Jan 1998 22:41:52 PST
  6158.      From: Vern Paxson <vern>
  6159.  
  6160.      > That requirement involves knowing
  6161.      > the character position at which a particular token was matched
  6162.      > in the lexer.
  6163.  
  6164.      The way you have to do this is by explicitly keeping track of where
  6165.      you are in the file, by counting the number of characters scanned
  6166.      for each token (available in yyleng).  It may prove convenient to
  6167.      do this by redefining YY_USER_ACTION, as described in the manual.
  6168.  
  6169.              Vern
  6170.  
  6171. 
  6172. File: flex,  Node: unnamed-faq-71,  Next: unnamed-faq-72,  Prev: unnamed-faq-70,  Up: FAQ
  6173.  
  6174. unnamed-faq-71
  6175. ==============
  6176.  
  6177.  
  6178.      To: Vladimir Alexiev <vladimir@cs.ualberta.ca>
  6179.      Subject: Re: flex: how to control start condition from parser?
  6180.      In-reply-to: Your message of Mon, 26 Jan 1998 05:50:16 PST.
  6181.      Date: Tue, 27 Jan 1998 22:45:37 PST
  6182.      From: Vern Paxson <vern>
  6183.  
  6184.      > It seems useful for the parser to be able to tell the lexer about such
  6185.      > context dependencies, because then they don't have to be limited to
  6186.      > local or sequential context.
  6187.  
  6188.      One way to do this is to have the parser call a stub routine that's
  6189.      included in the scanner's .l file, and consequently that has access ot
  6190.      BEGIN.  The only ugliness is that the parser can't pass in the state
  6191.      it wants, because those aren't visible - but if you don't have many
  6192.      such states, then using a different set of names doesn't seem like
  6193.      to much of a burden.
  6194.  
  6195.      While generating a .h file like you suggests is certainly cleaner,
  6196.      flex development has come to a virtual stand-still :-(, so a workaround
  6197.      like the above is much more pragmatic than waiting for a new feature.
  6198.  
  6199.              Vern
  6200.  
  6201. 
  6202. File: flex,  Node: unnamed-faq-72,  Next: unnamed-faq-73,  Prev: unnamed-faq-71,  Up: FAQ
  6203.  
  6204. unnamed-faq-72
  6205. ==============
  6206.  
  6207.  
  6208.      To: Barbara Denny <denny@3com.com>
  6209.      Subject: Re: freebsd flex bug?
  6210.      In-reply-to: Your message of Fri, 30 Jan 1998 12:00:43 PST.
  6211.      Date: Fri, 30 Jan 1998 12:42:32 PST
  6212.      From: Vern Paxson <vern>
  6213.  
  6214.      > lex.yy.c:1996: parse error before `='
  6215.  
  6216.      This is the key, identifying this error.  (It may help to pinpoint
  6217.      it by using flex -L, so it doesn't generate #line directives in its
  6218.      output.)  I will bet you heavy money that you have a start condition
  6219.      name that is also a variable name, or something like that; flex spits
  6220.      out #define's for each start condition name, mapping them to a number,
  6221.      so you can wind up with:
  6222.  
  6223.          %x foo
  6224.          %%
  6225.              ...
  6226.          %%
  6227.          void bar()
  6228.              {
  6229.              int foo = 3;
  6230.              }
  6231.  
  6232.      and the penultimate will turn into "int 1 = 3" after C preprocessing,
  6233.      since flex will put "#define foo 1" in the generated scanner.
  6234.  
  6235.              Vern
  6236.  
  6237. 
  6238. File: flex,  Node: unnamed-faq-73,  Next: unnamed-faq-74,  Prev: unnamed-faq-72,  Up: FAQ
  6239.  
  6240. unnamed-faq-73
  6241. ==============
  6242.  
  6243.  
  6244.      To: Maurice Petrie <mpetrie@infoscigroup.com>
  6245.      Subject: Re: Lost flex .l file
  6246.      In-reply-to: Your message of Mon, 02 Feb 1998 14:10:01 PST.
  6247.      Date: Mon, 02 Feb 1998 11:15:12 PST
  6248.      From: Vern Paxson <vern>
  6249.  
  6250.      > I am curious as to
  6251.      > whether there is a simple way to backtrack from the generated source to
  6252.      > reproduce the lost list of tokens we are searching on.
  6253.  
  6254.      In theory, it's straight-forward to go from the DFA representation
  6255.      back to a regular-expression representation - the two are isomorphic.
  6256.      In practice, a huge headache, because you have to unpack all the tables
  6257.      back into a single DFA representation, and then write a program to munch
  6258.      on that and translate it into an RE.
  6259.  
  6260.      Sorry for the less-than-happy news ...
  6261.  
  6262.              Vern
  6263.  
  6264. 
  6265. File: flex,  Node: unnamed-faq-74,  Next: unnamed-faq-75,  Prev: unnamed-faq-73,  Up: FAQ
  6266.  
  6267. unnamed-faq-74
  6268. ==============
  6269.  
  6270.  
  6271.      To: jimmey@lexis-nexis.com (Jimmey Todd)
  6272.      Subject: Re: Flex performance question
  6273.      In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
  6274.      Date: Thu, 19 Feb 1998 08:48:51 PST
  6275.      From: Vern Paxson <vern>
  6276.  
  6277.      > What I have found, is that the smaller the data chunk, the faster the
  6278.      > program executes. This is the opposite of what I expected. Should this be
  6279.      > happening this way?
  6280.  
  6281.      This is exactly what will happen if your input file has embedded NULs.
  6282.      From the man page:
  6283.  
  6284.      A final note: flex is slow when matching NUL's, particularly
  6285.      when  a  token  contains multiple NUL's.  It's best to write
  6286.      rules which match short amounts of text if it's  anticipated
  6287.      that the text will often include NUL's.
  6288.  
  6289.      So that's the first thing to look for.
  6290.  
  6291.              Vern
  6292.  
  6293. 
  6294. File: flex,  Node: unnamed-faq-75,  Next: unnamed-faq-76,  Prev: unnamed-faq-74,  Up: FAQ
  6295.  
  6296. unnamed-faq-75
  6297. ==============
  6298.  
  6299.  
  6300.      To: jimmey@lexis-nexis.com (Jimmey Todd)
  6301.      Subject: Re: Flex performance question
  6302.      In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
  6303.      Date: Thu, 19 Feb 1998 15:42:25 PST
  6304.      From: Vern Paxson <vern>
  6305.  
  6306.      So there are several problems.
  6307.  
  6308.      First, to go fast, you want to match as much text as possible, which
  6309.      your scanners don't in the case that what they're scanning is *not*
  6310.      a <RN> tag.  So you want a rule like:
  6311.  
  6312.          [^<]+
  6313.  
  6314.      Second, C++ scanners are particularly slow if they're interactive,
  6315.      which they are by default.  Using -B speeds it up by a factor of 3-4
  6316.      on my workstation.
  6317.  
  6318.      Third, C++ scanners that use the istream interface are slow, because
  6319.      of how poorly implemented istream's are.  I built two versions of
  6320.      the following scanner:
  6321.  
  6322.          %%
  6323.          .*\n
  6324.          .*
  6325.          %%
  6326.  
  6327.      and the C version inhales a 2.5MB file on my workstation in 0.8 seconds.
  6328.      The C++ istream version, using -B, takes 3.8 seconds.
  6329.  
  6330.              Vern
  6331.  
  6332. 
  6333. File: flex,  Node: unnamed-faq-76,  Next: unnamed-faq-77,  Prev: unnamed-faq-75,  Up: FAQ
  6334.  
  6335. unnamed-faq-76
  6336. ==============
  6337.  
  6338.  
  6339.      To: "Frescatore, David (CRD, TAD)" <frescatore@exc01crdge.crd.ge.com>
  6340.      Subject: Re: FLEX 2.5 & THE YEAR 2000
  6341.      In-reply-to: Your message of Wed, 03 Jun 1998 11:26:22 PDT.
  6342.      Date: Wed, 03 Jun 1998 10:22:26 PDT
  6343.      From: Vern Paxson <vern>
  6344.  
  6345.      > I am researching the Y2K problem with General Electric R&D
  6346.      > and need to know if there are any known issues concerning
  6347.      > the above mentioned software and Y2K regardless of version.
  6348.  
  6349.      There shouldn't be, all it ever does with the date is ask the system
  6350.      for it and then print it out.
  6351.  
  6352.              Vern
  6353.  
  6354. 
  6355. File: flex,  Node: unnamed-faq-77,  Next: unnamed-faq-78,  Prev: unnamed-faq-76,  Up: FAQ
  6356.  
  6357. unnamed-faq-77
  6358. ==============
  6359.  
  6360.  
  6361.      To: "Hans Dermot Doran" <htd@ibhdoran.com>
  6362.      Subject: Re: flex problem
  6363.      In-reply-to: Your message of Wed, 15 Jul 1998 21:30:13 PDT.
  6364.      Date: Tue, 21 Jul 1998 14:23:34 PDT
  6365.      From: Vern Paxson <vern>
  6366.  
  6367.      > To overcome this, I gets() the stdin into a string and lex the string. The
  6368.      > string is lexed OK except that the end of string isn't lexed properly
  6369.      > (yy_scan_string()), that is the lexer dosn't recognise the end of string.
  6370.  
  6371.      Flex doesn't contain mechanisms for recognizing buffer endpoints.  But if
  6372.      you use fgets instead (which you should anyway, to protect against buffer
  6373.      overflows), then the final \n will be preserved in the string, and you can
  6374.      scan that in order to find the end of the string.
  6375.  
  6376.              Vern
  6377.  
  6378. 
  6379. File: flex,  Node: unnamed-faq-78,  Next: unnamed-faq-79,  Prev: unnamed-faq-77,  Up: FAQ
  6380.  
  6381. unnamed-faq-78
  6382. ==============
  6383.  
  6384.  
  6385.      To: soumen@almaden.ibm.com
  6386.      Subject: Re: Flex++ 2.5.3 instance member vs. static member
  6387.      In-reply-to: Your message of Mon, 27 Jul 1998 02:10:04 PDT.
  6388.      Date: Tue, 28 Jul 1998 01:10:34 PDT
  6389.      From: Vern Paxson <vern>
  6390.  
  6391.      > %{
  6392.      > int mylineno = 0;
  6393.      > %}
  6394.      > ws      [ \t]+
  6395.      > alpha   [A-Za-z]
  6396.      > dig     [0-9]
  6397.      > %%
  6398.      >
  6399.      > Now you'd expect mylineno to be a member of each instance of class
  6400.      > yyFlexLexer, but is this the case?  A look at the lex.yy.cc file seems to
  6401.      > indicate otherwise; unless I am missing something the declaration of
  6402.      > mylineno seems to be outside any class scope.
  6403.      >
  6404.      > How will this work if I want to run a multi-threaded application with each
  6405.      > thread creating a FlexLexer instance?
  6406.  
  6407.      Derive your own subclass and make mylineno a member variable of it.
  6408.  
  6409.              Vern
  6410.  
  6411. 
  6412. File: flex,  Node: unnamed-faq-79,  Next: unnamed-faq-80,  Prev: unnamed-faq-78,  Up: FAQ
  6413.  
  6414. unnamed-faq-79
  6415. ==============
  6416.  
  6417.  
  6418.      To: Adoram Rogel <adoram@hybridge.com>
  6419.      Subject: Re: More than 32K states change hangs
  6420.      In-reply-to: Your message of Tue, 04 Aug 1998 16:55:39 PDT.
  6421.      Date: Tue, 04 Aug 1998 22:28:45 PDT
  6422.      From: Vern Paxson <vern>
  6423.  
  6424.      > Vern Paxson,
  6425.      >
  6426.      > I followed your advice, posted on Usenet bu you, and emailed to me
  6427.      > personally by you, on how to overcome the 32K states limit. I'm running
  6428.      > on Linux machines.
  6429.      > I took the full source of version 2.5.4 and did the following changes in
  6430.      > flexdef.h:
  6431.      > #define JAMSTATE -327660
  6432.      > #define MAXIMUM_MNS 319990
  6433.      > #define BAD_SUBSCRIPT -327670
  6434.      > #define MAX_SHORT 327000
  6435.      >
  6436.      > and compiled.
  6437.      > All looked fine, including check and bigcheck, so I installed.
  6438.  
  6439.      Hmmm, you shouldn't increase MAX_SHORT, though looking through my email
  6440.      archives I see that I did indeed recommend doing so.  Try setting it back
  6441.      to 32700; that should suffice that you no longer need -Ca.  If it still
  6442.      hangs, then the interesting question is - where?
  6443.  
  6444.      > Compiling the same hanged program with a out-of-the-box (RedHat 4.2
  6445.      > distribution of Linux)
  6446.      > flex 2.5.4 binary works.
  6447.  
  6448.      Since Linux comes with source code, you should diff it against what
  6449.      you have to see what problems they missed.
  6450.  
  6451.      > Should I always compile with the -Ca option now ? even short and simple
  6452.      > filters ?
  6453.  
  6454.      No, definitely not.  It's meant to be for those situations where you
  6455.      absolutely must squeeze every last cycle out of your scanner.
  6456.  
  6457.              Vern
  6458.  
  6459. 
  6460. File: flex,  Node: unnamed-faq-80,  Next: unnamed-faq-81,  Prev: unnamed-faq-79,  Up: FAQ
  6461.  
  6462. unnamed-faq-80
  6463. ==============
  6464.  
  6465.  
  6466.      To: "Schmackpfeffer, Craig" <Craig.Schmackpfeffer@usa.xerox.com>
  6467.      Subject: Re: flex output for static code portion
  6468.      In-reply-to: Your message of Tue, 11 Aug 1998 11:55:30 PDT.
  6469.      Date: Mon, 17 Aug 1998 23:57:42 PDT
  6470.      From: Vern Paxson <vern>
  6471.  
  6472.      > I would like to use flex under the hood to generate a binary file
  6473.      > containing the data structures that control the parse.
  6474.  
  6475.      This has been on the wish-list for a long time.  In principle it's
  6476.      straight-forward - you redirect mkdata() et al's I/O to another file,
  6477.      and modify the skeleton to have a start-up function that slurps these
  6478.      into dynamic arrays.  The concerns are (1) the scanner generation code
  6479.      is hairy and full of corner cases, so it's easy to get surprised when
  6480.      going down this path :-( ; and (2) being careful about buffering so
  6481.      that when the tables change you make sure the scanner starts in the
  6482.      correct state and reading at the right point in the input file.
  6483.  
  6484.      > I was wondering if you know of anyone who has used flex in this way.
  6485.  
  6486.      I don't - but it seems like a reasonable project to undertake (unlike
  6487.      numerous other flex tweaks :-).
  6488.  
  6489.              Vern
  6490.  
  6491. 
  6492. File: flex,  Node: unnamed-faq-81,  Next: unnamed-faq-82,  Prev: unnamed-faq-80,  Up: FAQ
  6493.  
  6494. unnamed-faq-81
  6495. ==============
  6496.  
  6497.  
  6498.      Received: from 131.173.17.11 (131.173.17.11 [131.173.17.11])
  6499.          by ee.lbl.gov (8.9.1/8.9.1) with ESMTP id AAA03838
  6500.          for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 00:47:57 -0700 (PDT)
  6501.      Received: from hal.cl-ki.uni-osnabrueck.de (hal.cl-ki.Uni-Osnabrueck.DE [131.173.141.2])
  6502.          by deimos.rz.uni-osnabrueck.de (8.8.7/8.8.8) with ESMTP id JAA34694
  6503.          for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 09:47:55 +0200
  6504.      Received: (from georg@localhost) by hal.cl-ki.uni-osnabrueck.de (8.6.12/8.6.12) id JAA34834 for vern@ee.lbl.gov; Thu, 20 Aug 1998 09:47:54 +0200
  6505.      From: Georg Rehm <georg@hal.cl-ki.uni-osnabrueck.de>
  6506.      Message-Id: <199808200747.JAA34834@hal.cl-ki.uni-osnabrueck.de>
  6507.      Subject: "flex scanner push-back overflow"
  6508.      To: vern@ee.lbl.gov
  6509.      Date: Thu, 20 Aug 1998 09:47:54 +0200 (MEST)
  6510.      Reply-To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
  6511.      X-NoJunk: Do NOT send commercial mail, spam or ads to this address!
  6512.      X-URL: http://www.cl-ki.uni-osnabrueck.de/~georg/
  6513.      X-Mailer: ELM [version 2.4ME+ PL28 (25)]
  6514.      MIME-Version: 1.0
  6515.      Content-Type: text/plain; charset=US-ASCII
  6516.      Content-Transfer-Encoding: 7bit
  6517.  
  6518.      Hi Vern,
  6519.  
  6520.      Yesterday, I encountered a strange problem: I use the macro processor m4
  6521.      to include some lengthy lists into a .l file. Following is a flex macro
  6522.      definition that causes some serious pain in my neck:
  6523.  
  6524.      AUTHOR           ("A. Boucard / L. Boucard"|"A. Dastarac / M. Levent"|"A.Boucaud / L.Boucaud"|"Abderrahim Lamchichi"|"Achmat Dangor"|"Adeline Toullier"|"Adewale Maja-Pearce"|"Ahmed Ziri"|"Akram Ellyas"|"Alain Bihr"|"Alain Gresh"|"Alain Guillemoles"|"Alain Joxe"|"Alain Morice"|"Alain Renon"|"Alain Zecchini"|"Albert Memmi"|"Alberto Manguel"|"Alex De Waal"|"Alfonso Artico"| [...])
  6525.  
  6526.      The complete list contains about 10kB. When I try to "flex" this file
  6527.      (on a Solaris 2.6 machine, using a modified flex 2.5.4 (I only increased
  6528.      some of the predefined values in flexdefs.h) I get the error:
  6529.  
  6530.      myflex/flex -8  sentag.tmp.l
  6531.      flex scanner push-back overflow
  6532.  
  6533.      When I remove the slashes in the macro definition everything works fine.
  6534.      As I understand it, the double quotes escape the slash-character so it
  6535.      really means "/" and not "trailing context". Furthermore, I tried to
  6536.      escape the slashes with backslashes, but with no use, the same error message
  6537.      appeared when flexing the code.
  6538.  
  6539.      Do you have an idea what's going on here?
  6540.  
  6541.      Greetings from Germany,
  6542.          Georg
  6543.      --
  6544.      Georg Rehm                                     georg@cl-ki.uni-osnabrueck.de
  6545.      Institute for Semantic Information Processing, University of Osnabrueck, FRG
  6546.  
  6547. 
  6548. File: flex,  Node: unnamed-faq-82,  Next: unnamed-faq-83,  Prev: unnamed-faq-81,  Up: FAQ
  6549.  
  6550. unnamed-faq-82
  6551. ==============
  6552.  
  6553.  
  6554.      To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
  6555.      Subject: Re: "flex scanner push-back overflow"
  6556.      In-reply-to: Your message of Thu, 20 Aug 1998 09:47:54 PDT.
  6557.      Date: Thu, 20 Aug 1998 07:05:35 PDT
  6558.      From: Vern Paxson <vern>
  6559.  
  6560.      > myflex/flex -8  sentag.tmp.l
  6561.      > flex scanner push-back overflow
  6562.  
  6563.      Flex itself uses a flex scanner.  That scanner is running out of buffer
  6564.      space when it tries to unput() the humongous macro you've defined.  When
  6565.      you remove the '/'s, you make it small enough so that it fits in the buffer;
  6566.      removing spaces would do the same thing.
  6567.  
  6568.      The fix is to either rethink how come you're using such a big macro and
  6569.      perhaps there's another/better way to do it; or to rebuild flex's own
  6570.      scan.c with a larger value for
  6571.  
  6572.          #define YY_BUF_SIZE 16384
  6573.  
  6574.      - Vern
  6575.  
  6576. 
  6577. File: flex,  Node: unnamed-faq-83,  Next: unnamed-faq-84,  Prev: unnamed-faq-82,  Up: FAQ
  6578.  
  6579. unnamed-faq-83
  6580. ==============
  6581.  
  6582.  
  6583.      To: Jan Kort <jan@research.techforce.nl>
  6584.      Subject: Re: Flex
  6585.      In-reply-to: Your message of Fri, 04 Sep 1998 12:18:43 +0200.
  6586.      Date: Sat, 05 Sep 1998 00:59:49 PDT
  6587.      From: Vern Paxson <vern>
  6588.  
  6589.      > %%
  6590.      >
  6591.      > "TEST1\n"       { fprintf(stderr, "TEST1\n"); yyless(5); }
  6592.      > ^\n             { fprintf(stderr, "empty line\n"); }
  6593.      > .               { }
  6594.      > \n              { fprintf(stderr, "new line\n"); }
  6595.      >
  6596.      > %%
  6597.      > -- input ---------------------------------------
  6598.      > TEST1
  6599.      > -- output --------------------------------------
  6600.      > TEST1
  6601.      > empty line
  6602.      > ------------------------------------------------
  6603.  
  6604.      IMHO, it's not clear whether or not this is in fact a bug.  It depends
  6605.      on whether you view yyless() as backing up in the input stream, or as
  6606.      pushing new characters onto the beginning of the input stream.  Flex
  6607.      interprets it as the latter (for implementation convenience, I'll admit),
  6608.      and so considers the newline as in fact matching at the beginning of a
  6609.      line, as after all the last token scanned an entire line and so the
  6610.      scanner is now at the beginning of a new line.
  6611.  
  6612.      I agree that this is counter-intuitive for yyless(), given its
  6613.      functional description (it's less so for unput(), depending on whether
  6614.      you're unput()'ing new text or scanned text).  But I don't plan to
  6615.      change it any time soon, as it's a pain to do so.  Consequently,
  6616.      you do indeed need to use yy_set_bol() and YY_AT_BOL() to tweak
  6617.      your scanner into the behavior you desire.
  6618.  
  6619.      Sorry for the less-than-completely-satisfactory answer.
  6620.  
  6621.              Vern
  6622.  
  6623. 
  6624. File: flex,  Node: unnamed-faq-84,  Next: unnamed-faq-85,  Prev: unnamed-faq-83,  Up: FAQ
  6625.  
  6626. unnamed-faq-84
  6627. ==============
  6628.  
  6629.  
  6630.      To: Patrick Krusenotto <krusenot@mac-info-link.de>
  6631.      Subject: Re: Problems with restarting flex-2.5.2-generated scanner
  6632.      In-reply-to: Your message of Thu, 24 Sep 1998 10:14:07 PDT.
  6633.      Date: Thu, 24 Sep 1998 23:28:43 PDT
  6634.      From: Vern Paxson <vern>
  6635.  
  6636.      > I am using flex-2.5.2 and bison 1.25 for Solaris and I am desperately
  6637.      > trying to make my scanner restart with a new file after my parser stops
  6638.      > with a parse error. When my compiler restarts, the parser always
  6639.      > receives the token after the token (in the old file!) that caused the
  6640.      > parser error.
  6641.  
  6642.      I suspect the problem is that your parser has read ahead in order
  6643.      to attempt to resolve an ambiguity, and when it's restarted it picks
  6644.      up with that token rather than reading a fresh one.  If you're using
  6645.      yacc, then the special "error" production can sometimes be used to
  6646.      consume tokens in an attempt to get the parser into a consistent state.
  6647.  
  6648.              Vern
  6649.  
  6650. 
  6651. File: flex,  Node: unnamed-faq-85,  Next: unnamed-faq-86,  Prev: unnamed-faq-84,  Up: FAQ
  6652.  
  6653. unnamed-faq-85
  6654. ==============
  6655.  
  6656.  
  6657.      To: Henric Jungheim <junghelh@pe-nelson.com>
  6658.      Subject: Re: flex 2.5.4a
  6659.      In-reply-to: Your message of Tue, 27 Oct 1998 16:41:42 PST.
  6660.      Date: Tue, 27 Oct 1998 16:50:14 PST
  6661.      From: Vern Paxson <vern>
  6662.  
  6663.      > This brings up a feature request:  How about a command line
  6664.      > option to specify the filename when reading from stdin?  That way one
  6665.      > doesn't need to create a temporary file in order to get the "#line"
  6666.      > directives to make sense.
  6667.  
  6668.      Use -o combined with -t (per the man page description of -o).
  6669.  
  6670.      > P.S., Is there any simple way to use non-blocking IO to parse multiple
  6671.      > streams?
  6672.  
  6673.      Simple, no.
  6674.  
  6675.      One approach might be to return a magic character on EWOULDBLOCK and
  6676.      have a rule
  6677.  
  6678.          .*<magic-character>    // put back .*, eat magic character
  6679.  
  6680.      This is off the top of my head, not sure it'll work.
  6681.  
  6682.              Vern
  6683.  
  6684. 
  6685. File: flex,  Node: unnamed-faq-86,  Next: unnamed-faq-87,  Prev: unnamed-faq-85,  Up: FAQ
  6686.  
  6687. unnamed-faq-86
  6688. ==============
  6689.  
  6690.  
  6691.      To: "Repko, Billy D" <billy.d.repko@intel.com>
  6692.      Subject: Re: Compiling scanners
  6693.      In-reply-to: Your message of Wed, 13 Jan 1999 10:52:47 PST.
  6694.      Date: Thu, 14 Jan 1999 00:25:30 PST
  6695.      From: Vern Paxson <vern>
  6696.  
  6697.      > It appears that maybe it cannot find the lfl library.
  6698.  
  6699.      The Makefile in the distribution builds it, so you should have it.
  6700.      It's exceedingly trivial, just a main() that calls yylex() and
  6701.      a yyrap() that always returns 1.
  6702.  
  6703.      > %%
  6704.      >       \n      ++num_lines; ++num_chars;
  6705.      >       .       ++num_chars;
  6706.  
  6707.      You can't indent your rules like this - that's where the errors are coming
  6708.      from.  Flex copies indented text to the output file, it's how you do things
  6709.      like
  6710.  
  6711.          int num_lines_seen = 0;
  6712.  
  6713.      to declare local variables.
  6714.  
  6715.              Vern
  6716.  
  6717. 
  6718. File: flex,  Node: unnamed-faq-87,  Next: unnamed-faq-88,  Prev: unnamed-faq-86,  Up: FAQ
  6719.  
  6720. unnamed-faq-87
  6721. ==============
  6722.  
  6723.  
  6724.      To: Erick Branderhorst <Erick.Branderhorst@asml.nl>
  6725.      Subject: Re: flex input buffer
  6726.      In-reply-to: Your message of Tue, 09 Feb 1999 13:53:46 PST.
  6727.      Date: Tue, 09 Feb 1999 21:03:37 PST
  6728.      From: Vern Paxson <vern>
  6729.  
  6730.      > In the flex.skl file the size of the default input buffers is set.  Can you
  6731.      > explain why this size is set and why it is such a high number.
  6732.  
  6733.      It's large to optimize performance when scanning large files.  You can
  6734.      safely make it a lot lower if needed.
  6735.  
  6736.              Vern
  6737.  
  6738. 
  6739. File: flex,  Node: unnamed-faq-88,  Next: unnamed-faq-90,  Prev: unnamed-faq-87,  Up: FAQ
  6740.  
  6741. unnamed-faq-88
  6742. ==============
  6743.  
  6744.  
  6745.      To: "Guido Minnen" <guidomi@cogs.susx.ac.uk>
  6746.      Subject: Re: Flex error message
  6747.      In-reply-to: Your message of Wed, 24 Feb 1999 15:31:46 PST.
  6748.      Date: Thu, 25 Feb 1999 00:11:31 PST
  6749.      From: Vern Paxson <vern>
  6750.  
  6751.      > I'm extending a larger scanner written in Flex and I keep running into
  6752.      > problems. More specifically, I get the error message:
  6753.      > "flex: input rules are too complicated (>= 32000 NFA states)"
  6754.  
  6755.      Increase the definitions in flexdef.h for:
  6756.  
  6757.      #define JAMSTATE -32766 /* marks a reference to the state that always j
  6758.      ams */
  6759.      #define MAXIMUM_MNS 31999
  6760.      #define BAD_SUBSCRIPT -32767
  6761.  
  6762.      recompile everything, and it should all work.
  6763.  
  6764.              Vern
  6765.  
  6766. 
  6767. File: flex,  Node: unnamed-faq-90,  Next: unnamed-faq-91,  Prev: unnamed-faq-88,  Up: FAQ
  6768.  
  6769. unnamed-faq-90
  6770. ==============
  6771.  
  6772.  
  6773.      To: "Dmitriy Goldobin" <gold@ems.chel.su>
  6774.      Subject: Re: FLEX trouble
  6775.      In-reply-to: Your message of Mon, 31 May 1999 18:44:49 PDT.
  6776.      Date: Tue, 01 Jun 1999 00:15:07 PDT
  6777.      From: Vern Paxson <vern>
  6778.  
  6779.      >   I have a trouble with FLEX. Why rule "/*".*"*/" work properly,=20
  6780.      > but rule "/*"(.|\n)*"*/" don't work ?
  6781.  
  6782.      The second of these will have to scan the entire input stream (because
  6783.      "(.|\n)*" matches an arbitrary amount of any text) in order to see if
  6784.      it ends with "*/", terminating the comment.  That potentially will overflow
  6785.      the input buffer.
  6786.  
  6787.      >   More complex rule "/*"([^*]|(\*/[^/]))*"*/ give an error
  6788.      > 'unrecognized rule'.
  6789.  
  6790.      You can't use the '/' operator inside parentheses.  It's not clear
  6791.      what "(a/b)*" actually means.
  6792.  
  6793.      >   I now use workaround with state <comment>, but single-rule is
  6794.      > better, i think.
  6795.  
  6796.      Single-rule is nice but will always have the problem of either setting
  6797.      restrictions on comments (like not allowing multi-line comments) and/or
  6798.      running the risk of consuming the entire input stream, as noted above.
  6799.  
  6800.              Vern
  6801.  
  6802. 
  6803. File: flex,  Node: unnamed-faq-91,  Next: unnamed-faq-92,  Prev: unnamed-faq-90,  Up: FAQ
  6804.  
  6805. unnamed-faq-91
  6806. ==============
  6807.  
  6808.  
  6809.      Received: from mc-qout4.whowhere.com (mc-qout4.whowhere.com [209.185.123.18])
  6810.          by ee.lbl.gov (8.9.3/8.9.3) with SMTP id IAA05100
  6811.          for <vern@ee.lbl.gov>; Tue, 15 Jun 1999 08:56:06 -0700 (PDT)
  6812.      Received: from Unknown/Local ([?.?.?.?]) by my-deja.com; Tue Jun 15 08:55:43 1999
  6813.      To: vern@ee.lbl.gov
  6814.      Date: Tue, 15 Jun 1999 08:55:43 -0700
  6815.      From: "Aki Niimura" <neko@my-deja.com>
  6816.      Message-ID: <KNONDOHDOBGAEAAA@my-deja.com>
  6817.      Mime-Version: 1.0
  6818.      Cc:
  6819.      X-Sent-Mail: on
  6820.      Reply-To:
  6821.      X-Mailer: MailCity Service
  6822.      Subject: A question on flex C++ scanner
  6823.      X-Sender-Ip: 12.72.207.61
  6824.      Organization: My Deja Email  (http://www.my-deja.com:80)
  6825.      Content-Type: text/plain; charset=us-ascii
  6826.      Content-Transfer-Encoding: 7bit
  6827.  
  6828.      Dear Dr. Paxon,
  6829.  
  6830.      I have been using flex for years.
  6831.      It works very well on many projects.
  6832.      Most case, I used it to generate a scanner on C language.
  6833.      However, one project I needed to generate  a scanner
  6834.      on C++ lanuage. Thanks to your enhancement, flex did
  6835.      the job.
  6836.  
  6837.      Currently, I'm working on enhancing my previous project.
  6838.      I need to deal with multiple input streams (recursive
  6839.      inclusion) in this scanner (C++).
  6840.      I did similar thing for another scanner (C) as you
  6841.      explained in your documentation.
  6842.  
  6843.      The generated scanner (C++) has necessary methods:
  6844.      - switch_to_buffer(struct yy_buffer_state *b)
  6845.      - yy_create_buffer(istream *is, int sz)
  6846.      - yy_delete_buffer(struct yy_buffer_state *b)
  6847.  
  6848.      However, I couldn't figure out how to access current
  6849.      buffer (yy_current_buffer).
  6850.  
  6851.      yy_current_buffer is a protected member of yyFlexLexer.
  6852.      I can't access it directly.
  6853.      Then, I thought yy_create_buffer() with is = 0 might
  6854.      return current stream buffer. But it seems not as far
  6855.      as I checked the source. (flex 2.5.4)
  6856.  
  6857.      I went through the Web in addition to Flex documentation.
  6858.      However, it hasn't been successful, so far.
  6859.  
  6860.      It is not my intention to bother you, but, can you
  6861.      comment about how to obtain the current stream buffer?
  6862.  
  6863.      Your response would be highly appreciated.
  6864.  
  6865.      Best regards,
  6866.      Aki Niimura
  6867.  
  6868.      --== Sent via Deja.com http://www.deja.com/ ==--
  6869.      Share what you know. Learn what you don't.
  6870.  
  6871. 
  6872. File: flex,  Node: unnamed-faq-92,  Next: unnamed-faq-93,  Prev: unnamed-faq-91,  Up: FAQ
  6873.  
  6874. unnamed-faq-92
  6875. ==============
  6876.  
  6877.  
  6878.      To: neko@my-deja.com
  6879.      Subject: Re: A question on flex C++ scanner
  6880.      In-reply-to: Your message of Tue, 15 Jun 1999 08:55:43 PDT.
  6881.      Date: Tue, 15 Jun 1999 09:04:24 PDT
  6882.      From: Vern Paxson <vern>
  6883.  
  6884.      > However, I couldn't figure out how to access current
  6885.      > buffer (yy_current_buffer).
  6886.  
  6887.      Derive your own subclass from yyFlexLexer.
  6888.  
  6889.              Vern
  6890.  
  6891. 
  6892. File: flex,  Node: unnamed-faq-93,  Next: unnamed-faq-94,  Prev: unnamed-faq-92,  Up: FAQ
  6893.  
  6894. unnamed-faq-93
  6895. ==============
  6896.  
  6897.  
  6898.      To: "Stones, Darren" <Darren.Stones@nectech.co.uk>
  6899.      Subject: Re: You're the man to see?
  6900.      In-reply-to: Your message of Wed, 23 Jun 1999 11:10:29 PDT.
  6901.      Date: Wed, 23 Jun 1999 09:01:40 PDT
  6902.      From: Vern Paxson <vern>
  6903.  
  6904.      > I hope you can help me.  I am using Flex and Bison to produce an interpreted
  6905.      > language.  However all goes well until I try to implement an IF statement or
  6906.      > a WHILE.  I cannot get this to work as the parser parses all the conditions
  6907.      > eg. the TRUE and FALSE conditons to check for a rule match.  So I cannot
  6908.      > make a decision!!
  6909.  
  6910.      You need to use the parser to build a parse tree (= abstract syntax trwee),
  6911.      and when that's all done you recursively evaluate the tree, binding variables
  6912.      to values at that time.
  6913.  
  6914.              Vern
  6915.  
  6916. 
  6917. File: flex,  Node: unnamed-faq-94,  Next: unnamed-faq-95,  Prev: unnamed-faq-93,  Up: FAQ
  6918.  
  6919. unnamed-faq-94
  6920. ==============
  6921.  
  6922.  
  6923.      To: Petr Danecek <petr@ics.cas.cz>
  6924.      Subject: Re: flex - question
  6925.      In-reply-to: Your message of Mon, 28 Jun 1999 19:21:41 PDT.
  6926.      Date: Fri, 02 Jul 1999 16:52:13 PDT
  6927.      From: Vern Paxson <vern>
  6928.  
  6929.      > file, it takes an enormous amount of time. It is funny, because the
  6930.      > source code has only 12 rules!!! I think it looks like an exponencial
  6931.      > growth.
  6932.  
  6933.      Right, that's the problem - some patterns (those with a lot of
  6934.      ambiguity, where yours has because at any given time the scanner can
  6935.      be in the middle of all sorts of combinations of the different
  6936.      rules) blow up exponentially.
  6937.  
  6938.      For your rules, there is an easy fix.  Change the ".*" that comes fater
  6939.      the directory name to "[^ ]*".  With that in place, the rules are no
  6940.      longer nearly so ambiguous, because then once one of the directories
  6941.      has been matched, no other can be matched (since they all require a
  6942.      leading blank).
  6943.  
  6944.      If that's not an acceptable solution, then you can enter a start state
  6945.      to pick up the .*\n after each directory is matched.
  6946.  
  6947.      Also note that for speed, you'll want to add a ".*" rule at the end,
  6948.      otherwise rules that don't match any of the patterns will be matched
  6949.      very slowly, a character at a time.
  6950.  
  6951.              Vern
  6952.  
  6953. 
  6954. File: flex,  Node: unnamed-faq-95,  Next: unnamed-faq-96,  Prev: unnamed-faq-94,  Up: FAQ
  6955.  
  6956. unnamed-faq-95
  6957. ==============
  6958.  
  6959.  
  6960.      To: Tielman Koekemoer <tielman@spi.co.za>
  6961.      Subject: Re: Please help.
  6962.      In-reply-to: Your message of Thu, 08 Jul 1999 13:20:37 PDT.
  6963.      Date: Thu, 08 Jul 1999 08:20:39 PDT
  6964.      From: Vern Paxson <vern>
  6965.  
  6966.      > I was hoping you could help me with my problem.
  6967.      >
  6968.      > I tried compiling (gnu)flex on a Solaris 2.4 machine
  6969.      > but when I ran make (after configure) I got an error.
  6970.      >
  6971.      > --------------------------------------------------------------
  6972.      > gcc -c -I. -I. -g -O parse.c
  6973.      > ./flex -t -p  ./scan.l >scan.c
  6974.      > sh: ./flex: not found
  6975.      > *** Error code 1
  6976.      > make: Fatal error: Command failed for target `scan.c'
  6977.      > -------------------------------------------------------------
  6978.      >
  6979.      > What's strange to me is that I'm only
  6980.      > trying to install flex now. I then edited the Makefile to
  6981.      > and changed where it says "FLEX = flex" to "FLEX = lex"
  6982.      > ( lex: the native Solaris one ) but then it complains about
  6983.      > the "-p" option. Is there any way I can compile flex without
  6984.      > using flex or lex?
  6985.      >
  6986.      > Thanks so much for your time.
  6987.  
  6988.      You managed to step on the bootstrap sequence, which first copies
  6989.      initscan.c to scan.c in order to build flex.  Try fetching a fresh
  6990.      distribution from ftp.ee.lbl.gov.  (Or you can first try removing
  6991.      ".bootstrap" and doing a make again.)
  6992.  
  6993.              Vern
  6994.  
  6995. 
  6996. File: flex,  Node: unnamed-faq-96,  Next: unnamed-faq-97,  Prev: unnamed-faq-95,  Up: FAQ
  6997.  
  6998. unnamed-faq-96
  6999. ==============
  7000.  
  7001.  
  7002.      To: Tielman Koekemoer <tielman@spi.co.za>
  7003.      Subject: Re: Please help.
  7004.      In-reply-to: Your message of Fri, 09 Jul 1999 09:16:14 PDT.
  7005.      Date: Fri, 09 Jul 1999 00:27:20 PDT
  7006.      From: Vern Paxson <vern>
  7007.  
  7008.      > First I removed .bootstrap (and ran make) - no luck. I downloaded the
  7009.      > software but I still have the same problem. Is there anything else I
  7010.      > could try.
  7011.  
  7012.      Try:
  7013.  
  7014.          cp initscan.c scan.c
  7015.          touch scan.c
  7016.          make scan.o
  7017.  
  7018.      If this last tries to first build scan.c from scan.l using ./flex, then
  7019.      your "make" is broken, in which case compile scan.c to scan.o by hand.
  7020.  
  7021.              Vern
  7022.  
  7023. 
  7024. File: flex,  Node: unnamed-faq-97,  Next: unnamed-faq-98,  Prev: unnamed-faq-96,  Up: FAQ
  7025.  
  7026. unnamed-faq-97
  7027. ==============
  7028.  
  7029.  
  7030.      To: Sumanth Kamenani <skamenan@crl.nmsu.edu>
  7031.      Subject: Re: Error
  7032.      In-reply-to: Your message of Mon, 19 Jul 1999 23:08:41 PDT.
  7033.      Date: Tue, 20 Jul 1999 00:18:26 PDT
  7034.      From: Vern Paxson <vern>
  7035.  
  7036.      > I am getting a compilation error. The error is given as "unknown symbol- yylex".
  7037.  
  7038.      The parser relies on calling yylex(), but you're instead using the C++ scanning
  7039.      class, so you need to supply a yylex() "glue" function that calls an instance
  7040.      scanner of the scanner (e.g., "scanner->yylex()").
  7041.  
  7042.              Vern
  7043.  
  7044. 
  7045. File: flex,  Node: unnamed-faq-98,  Next: unnamed-faq-99,  Prev: unnamed-faq-97,  Up: FAQ
  7046.  
  7047. unnamed-faq-98
  7048. ==============
  7049.  
  7050.  
  7051.      To: daniel@synchrods.synchrods.COM (Daniel Senderowicz)
  7052.      Subject: Re: lex
  7053.      In-reply-to: Your message of Mon, 22 Nov 1999 11:19:04 PST.
  7054.      Date: Tue, 23 Nov 1999 15:54:30 PST
  7055.      From: Vern Paxson <vern>
  7056.  
  7057.      Well, your problem is the
  7058.  
  7059.      switch (yybgin-yysvec-1) {      /* witchcraft */
  7060.  
  7061.      at the beginning of lex rules.  "witchcraft" == "non-portable".  It's
  7062.      assuming knowledge of the AT&T lex's internal variables.
  7063.  
  7064.      For flex, you can probably do the equivalent using a switch on YYSTATE.
  7065.  
  7066.              Vern
  7067.  
  7068. 
  7069. File: flex,  Node: unnamed-faq-99,  Next: unnamed-faq-100,  Prev: unnamed-faq-98,  Up: FAQ
  7070.  
  7071. unnamed-faq-99
  7072. ==============
  7073.  
  7074.  
  7075.      To: archow@hss.hns.com
  7076.      Subject: Re: Regarding distribution of flex and yacc based grammars
  7077.      In-reply-to: Your message of Sun, 19 Dec 1999 17:50:24 +0530.
  7078.      Date: Wed, 22 Dec 1999 01:56:24 PST
  7079.      From: Vern Paxson <vern>
  7080.  
  7081.      > When we provide the customer with an object code distribution, is it
  7082.      > necessary for us to provide source
  7083.      > for the generated C files from flex and bison since they are generated by
  7084.      > flex and bison ?
  7085.  
  7086.      For flex, no.  I don't know what the current state of this is for bison.
  7087.  
  7088.      > Also, is there any requrirement for us to neccessarily  provide source for
  7089.      > the grammar files which are fed into flex and bison ?
  7090.  
  7091.      Again, for flex, no.
  7092.  
  7093.      See the file "COPYING" in the flex distribution for the legalese.
  7094.  
  7095.              Vern
  7096.  
  7097. 
  7098. File: flex,  Node: unnamed-faq-100,  Next: unnamed-faq-101,  Prev: unnamed-faq-99,  Up: FAQ
  7099.  
  7100. unnamed-faq-100
  7101. ===============
  7102.  
  7103.  
  7104.      To: Martin Gallwey <gallweym@hyperion.moe.ul.ie>
  7105.      Subject: Re: Flex, and self referencing rules
  7106.      In-reply-to: Your message of Sun, 20 Feb 2000 01:01:21 PST.
  7107.      Date: Sat, 19 Feb 2000 18:33:16 PST
  7108.      From: Vern Paxson <vern>
  7109.  
  7110.      > However, I do not use unput anywhere. I do use self-referencing
  7111.      > rules like this:
  7112.      >
  7113.      > UnaryExpr               ({UnionExpr})|("-"{UnaryExpr})
  7114.  
  7115.      You can't do this - flex is *not* a parser like yacc (which does indeed
  7116.      allow recursion), it is a scanner that's confined to regular expressions.
  7117.  
  7118.              Vern
  7119.  
  7120. 
  7121. File: flex,  Node: unnamed-faq-101,  Prev: unnamed-faq-100,  Up: FAQ
  7122.  
  7123. unnamed-faq-101
  7124. ===============
  7125.  
  7126.  
  7127.      To: slg3@lehigh.edu (SAMUEL L. GULDEN)
  7128.      Subject: Re: Flex problem
  7129.      In-reply-to: Your message of Thu, 02 Mar 2000 12:29:04 PST.
  7130.      Date: Thu, 02 Mar 2000 23:00:46 PST
  7131.      From: Vern Paxson <vern>
  7132.  
  7133.      If this is exactly your program:
  7134.  
  7135.      > digit [0-9]
  7136.      > digits {digit}+
  7137.      > whitespace [ \t\n]+
  7138.      >
  7139.      > %%
  7140.      > "[" { printf("open_brac\n");}
  7141.      > "]" { printf("close_brac\n");}
  7142.      > "+" { printf("addop\n");}
  7143.      > "*" { printf("multop\n");}
  7144.      > {digits} { printf("NUMBER = %s\n", yytext);}
  7145.      > whitespace ;
  7146.  
  7147.      then the problem is that the last rule needs to be "{whitespace}" !
  7148.  
  7149.              Vern
  7150.  
  7151. 
  7152. File: flex,  Node: Appendices,  Next: Indices,  Prev: FAQ,  Up: Top
  7153.  
  7154. Appendix A Appendices
  7155. *********************
  7156.  
  7157. * Menu:
  7158.  
  7159. * Makefiles and Flex::
  7160. * Bison Bridge::
  7161. * M4 Dependency::
  7162.  
  7163. 
  7164. File: flex,  Node: Makefiles and Flex,  Next: Bison Bridge,  Prev: Appendices,  Up: Appendices
  7165.  
  7166. A.1 Makefiles and Flex
  7167. ======================
  7168.  
  7169. In this appendix, we provide tips for writing Makefiles to build your
  7170. scanners.
  7171.  
  7172.    In a traditional build environment, we say that the `.c' files are
  7173. the sources, and the `.o' files are the intermediate files. When using
  7174. `flex', however, the `.l' files are the sources, and the generated `.c'
  7175. files (along with the `.o' files) are the intermediate files.  This
  7176. requires you to carefully plan your Makefile.
  7177.  
  7178.    Modern `make' programs understand that `foo.l' is intended to
  7179. generate `lex.yy.c' or `foo.c', and will behave accordingly(1).  The
  7180. following Makefile does not explicitly instruct `make' how to build
  7181. `foo.c' from `foo.l'. Instead, it relies on the implicit rules of the
  7182. `make' program to build the intermediate file, `scan.c':
  7183.  
  7184.  
  7185.          # Basic Makefile -- relies on implicit rules
  7186.          # Creates "myprogram" from "scan.l" and "myprogram.c"
  7187.          #
  7188.          LEX=flex
  7189.          myprogram: scan.o myprogram.o
  7190.          scan.o: scan.l
  7191.  
  7192.    For simple cases, the above may be sufficient. For other cases, you
  7193. may have to explicitly instruct `make' how to build your scanner.  The
  7194. following is an example of a Makefile containing explicit rules:
  7195.  
  7196.  
  7197.          # Basic Makefile -- provides explicit rules
  7198.          # Creates "myprogram" from "scan.l" and "myprogram.c"
  7199.          #
  7200.          LEX=flex
  7201.          myprogram: scan.o myprogram.o
  7202.                  $(CC) -o $@  $(LDFLAGS) $^
  7203.  
  7204.          myprogram.o: myprogram.c
  7205.                  $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
  7206.  
  7207.          scan.o: scan.c
  7208.                  $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
  7209.  
  7210.          scan.c: scan.l
  7211.                  $(LEX) $(LFLAGS) -o $@ $^
  7212.  
  7213.          clean:
  7214.                  $(RM) *.o scan.c
  7215.  
  7216.    Notice in the above example that `scan.c' is in the `clean' target.
  7217. This is because we consider the file `scan.c' to be an intermediate
  7218. file.
  7219.  
  7220.    Finally, we provide a realistic example of a `flex' scanner used
  7221. with a `bison' parser(2).  There is a tricky problem we have to deal
  7222. with. Since a `flex' scanner will typically include a header file
  7223. (e.g., `y.tab.h') generated by the parser, we need to be sure that the
  7224. header file is generated BEFORE the scanner is compiled. We handle this
  7225. case in the following example:
  7226.  
  7227.  
  7228.          # Makefile example -- scanner and parser.
  7229.          # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
  7230.          #
  7231.          LEX     = flex
  7232.          YACC    = bison -y
  7233.          YFLAGS  = -d
  7234.          objects = scan.o parse.o myprogram.o
  7235.  
  7236.          myprogram: $(objects)
  7237.          scan.o: scan.l parse.c
  7238.          parse.o: parse.y
  7239.          myprogram.o: myprogram.c
  7240.  
  7241.    In the above example, notice the line,
  7242.  
  7243.  
  7244.          scan.o: scan.l parse.c
  7245.  
  7246.    , which lists the file `parse.c' (the generated parser) as a
  7247. dependency of `scan.o'. We want to ensure that the parser is created
  7248. before the scanner is compiled, and the above line seems to do the
  7249. trick. Feel free to experiment with your specific implementation of
  7250. `make'.
  7251.  
  7252.    For more details on writing Makefiles, see *Note Top: (make)Top.
  7253.  
  7254.    ---------- Footnotes ----------
  7255.  
  7256.    (1) GNU `make' and GNU `automake' are two such programs that provide
  7257. implicit rules for flex-generated scanners.
  7258.  
  7259.    (2) This example also applies to yacc parsers.
  7260.  
  7261. 
  7262. File: flex,  Node: Bison Bridge,  Next: M4 Dependency,  Prev: Makefiles and Flex,  Up: Appendices
  7263.  
  7264. A.2 C Scanners with Bison Parsers
  7265. =================================
  7266.  
  7267. This section describes the `flex' features useful when integrating
  7268. `flex' with `GNU bison'(1).  Skip this section if you are not using
  7269. `bison' with your scanner.  Here we discuss only the `flex' half of the
  7270. `flex' and `bison' pair.  We do not discuss `bison' in any detail.  For
  7271. more information about generating `bison' parsers, see *Note Top:
  7272. (bison)Top.
  7273.  
  7274.    A compatible `bison' scanner is generated by declaring `%option
  7275. bison-bridge' or by supplying `--bison-bridge' when invoking `flex'
  7276. from the command line.  This instructs `flex' that the macro `yylval'
  7277. may be used. The data type for `yylval', `YYSTYPE', is typically
  7278. defined in a header file, included in section 1 of the `flex' input
  7279. file.  For a list of functions and macros available, *Note
  7280. bison-functions::.
  7281.  
  7282.    The declaration of yylex becomes,
  7283.  
  7284.  
  7285.            int yylex ( YYSTYPE * lvalp, yyscan_t scanner );
  7286.  
  7287.    If `%option bison-locations' is specified, then the declaration
  7288. becomes,
  7289.  
  7290.  
  7291.            int yylex ( YYSTYPE * lvalp, YYLTYPE * llocp, yyscan_t scanner );
  7292.  
  7293.    Note that the macros `yylval' and `yylloc' evaluate to pointers.
  7294. Support for `yylloc' is optional in `bison', so it is optional in
  7295. `flex' as well. The following is an example of a `flex' scanner that is
  7296. compatible with `bison'.
  7297.  
  7298.  
  7299.          /* Scanner for "C" assignment statements... sort of. */
  7300.          %{
  7301.          #include "y.tab.h"  /* Generated by bison. */
  7302.          %}
  7303.  
  7304.          %option bison-bridge bison-locations
  7305.          %
  7306.  
  7307.          [[:digit:]]+  { yylval->num = atoi(yytext);   return NUMBER;}
  7308.          [[:alnum:]]+  { yylval->str = strdup(yytext); return STRING;}
  7309.          "="|";"       { return yytext[0];}
  7310.          .  {}
  7311.          %
  7312.  
  7313.    As you can see, there really is no magic here. We just use `yylval'
  7314. as we would any other variable. The data type of `yylval' is generated
  7315. by `bison', and included in the file `y.tab.h'. Here is the
  7316. corresponding `bison' parser:
  7317.  
  7318.  
  7319.          /* Parser to convert "C" assignments to lisp. */
  7320.          %{
  7321.          /* Pass the argument to yyparse through to yylex. */
  7322.          #define YYPARSE_PARAM scanner
  7323.          #define YYLEX_PARAM   scanner
  7324.          %}
  7325.          %locations
  7326.          %pure_parser
  7327.          %union {
  7328.              int num;
  7329.              char* str;
  7330.          }
  7331.          %token <str> STRING
  7332.          %token <num> NUMBER
  7333.          %%
  7334.          assignment:
  7335.              STRING '=' NUMBER ';' {
  7336.                  printf( "(setf %s %d)", $1, $3 );
  7337.             }
  7338.          ;
  7339.  
  7340.    ---------- Footnotes ----------
  7341.  
  7342.    (1) The features described here are purely optional, and are by no
  7343. means the only way to use flex with bison.  We merely provide some glue
  7344. to ease development of your parser-scanner pair.
  7345.  
  7346. 
  7347. File: flex,  Node: M4 Dependency,  Prev: Bison Bridge,  Up: Appendices
  7348.  
  7349. A.3 M4 Dependency
  7350. =================
  7351.  
  7352. The macro processor `m4'(1) must be installed wherever flex is
  7353. installed.  `flex' invokes `m4', found by searching the directories in
  7354. the `PATH' environment variable. Any code you place in section 1 or in
  7355. the actions will be sent through m4. Please follow these rules to
  7356. protect your code from unwanted `m4' processing.
  7357.  
  7358.    * Do not use symbols that begin with, `m4_', such as, `m4_define',
  7359.      or `m4_include', since those are reserved for `m4' macro names.
  7360.  
  7361.    * Do not use the strings `[[' or `]]' anywhere in your code. The
  7362.      former is not valid in C, except within comments, but the latter
  7363.      is valid in code such as `x[y[z]]'.
  7364.  
  7365.  
  7366.    `m4' is only required at the time you run `flex'. The generated
  7367. scanner is ordinary C or C++, and does _not_ require `m4'.
  7368.  
  7369.    ---------- Footnotes ----------
  7370.  
  7371.    (1) The use of m4 is subject to change in future revisions of flex.
  7372.  
  7373. 
  7374. File: flex,  Node: Indices,  Prev: Appendices,  Up: Top
  7375.  
  7376. Indices
  7377. *******
  7378.  
  7379. * Menu:
  7380.  
  7381. * Concept Index::
  7382. * Index of Functions and Macros::
  7383. * Index of Variables::
  7384. * Index of Data Types::
  7385. * Index of Hooks::
  7386. * Index of Scanner Options::
  7387.  
  7388. 
  7389. File: flex,  Node: Concept Index,  Next: Index of Functions and Macros,  Prev: Indices,  Up: Indices
  7390.  
  7391. Concept Index
  7392. =============
  7393.  
  7394. [index]
  7395. * Menu:
  7396.  
  7397. * $ as normal character in patterns:     Patterns.            (line 210)
  7398. * %array, advantages of:                 Matching.            (line  44)
  7399. * %array, use of:                        Matching.            (line  30)
  7400. * %array, with C++:                      Matching.            (line  67)
  7401. * %option nowrap:                        Generated Scanner.   (line  96)
  7402. * %pointer, and unput():                 Actions.             (line 170)
  7403. * %pointer, use of:                      Matching.            (line  30)
  7404. * %top:                                  Definitions Section. (line  48)
  7405. * %{ and %}, in Definitions Section:     Definitions Section. (line  44)
  7406. * %{ and %}, in Rules Section:           Actions.             (line  28)
  7407. * <<EOF>>, use of:                       EOF.                 (line  34)
  7408. * [] in patterns:                        Patterns.            (line  15)
  7409. * ^ as non-special character in patterns: Patterns.           (line 210)
  7410. * accessor functions, use of:            Accessor Methods.    (line  18)
  7411. * actions:                               Actions.             (line   6)
  7412. * actions, embedded C strings:           Actions.             (line  28)
  7413. * actions, redefining YY_BREAK:          Misc Macros.         (line  51)
  7414. * actions, use of { and }:               Actions.             (line  28)
  7415. * aliases, how to define:                Definitions Section. (line  10)
  7416. * arguments, command-line:               Scanner Options.     (line   6)
  7417. * array, default size for yytext:        User Values.         (line  13)
  7418. * backing up, eliminating:               Performance.         (line  56)
  7419. * backing up, eliminating by adding error rules: Performance. (line 108)
  7420. * backing up, eliminating with catch-all rule: Performance.   (line 123)
  7421. * backing up, example of eliminating:    Performance.         (line  51)
  7422. * BEGIN:                                 Actions.             (line  60)
  7423. * BEGIN, explanation:                    Start Conditions.    (line  90)
  7424. * beginning of line, in patterns:        Patterns.            (line  88)
  7425. * bison, bridging with flex:             Bison Bridge.        (line   6)
  7426. * bison, parser:                         Bison Bridge.        (line  57)
  7427. * bison, scanner to be called from bison: Bison Bridge.       (line  37)
  7428. * BOL, checking the BOL flag:            Misc Macros.         (line  48)
  7429. * BOL, in patterns:                      Patterns.            (line  88)
  7430. * BOL, setting it:                       Misc Macros.         (line  42)
  7431. * braces in patterns:                    Patterns.            (line  39)
  7432. * bugs, reporting:                       Reporting Bugs.      (line   6)
  7433. * C code in flex input:                  Definitions Section. (line  44)
  7434. * C++:                                   Cxx.                 (line   9)
  7435. * C++ and %array:                        User Values.         (line  23)
  7436. * C++ I/O, customizing:                  How do I use my own I/O classes in a C++ scanner?.
  7437.                                                               (line   9)
  7438. * C++ scanners, including multiple scanners: Cxx.             (line 186)
  7439. * C++ scanners, use of:                  Cxx.                 (line 122)
  7440. * c++, experimental form of scanner class: Cxx.               (line   6)
  7441. * C++, multiple different scanners:      Cxx.                 (line 180)
  7442. * C-strings, in actions:                 Actions.             (line  28)
  7443. * case-insensitive, effect on character classes: Patterns.    (line 179)
  7444. * character classes in patterns:         Patterns.            (line 151)
  7445. * character classes in patterns, syntax of: Patterns.         (line  15)
  7446. * character classes, equivalence of:     Patterns.            (line 171)
  7447. * clearing an input buffer:              Multiple Input Buffers.
  7448.                                                               (line  66)
  7449. * command-line options:                  Scanner Options.     (line   6)
  7450. * comments in flex input:                Definitions Section. (line  41)
  7451. * comments in the input:                 Comments in the Input.
  7452.                                                               (line  25)
  7453. * comments, discarding:                  Actions.             (line 184)
  7454. * comments, example of scanning C comments: Start Conditions. (line 148)
  7455. * comments, in actions:                  Actions.             (line  28)
  7456. * comments, in rules section:            Comments in the Input.
  7457.                                                               (line  11)
  7458. * comments, syntax of:                   Comments in the Input.
  7459.                                                               (line   6)
  7460. * comments, valid uses of:               Comments in the Input.
  7461.                                                               (line  25)
  7462. * compressing whitespace:                Actions.             (line  23)
  7463. * concatenation, in patterns:            Patterns.            (line  72)
  7464. * copyright of flex:                     Copyright.           (line   6)
  7465. * counting characters and lines:         Simple Examples.     (line  25)
  7466. * customizing I/O in C++ scanners:       How do I use my own I/O classes in a C++ scanner?.
  7467.                                                               (line   9)
  7468. * default rule <1>:                      Matching.            (line  20)
  7469. * default rule:                          Simple Examples.     (line  16)
  7470. * defining pattern aliases:              Definitions Section. (line  22)
  7471. * Definitions, in flex input:            Definitions Section. (line   6)
  7472. * deleting lines from input:             Actions.             (line  13)
  7473. * discarding C comments:                 Actions.             (line 184)
  7474. * distributing flex:                     Copyright.           (line   6)
  7475. * ECHO:                                  Actions.             (line  57)
  7476. * ECHO, and yyout:                       Generated Scanner.   (line 104)
  7477. * embedding C code in flex input:        Definitions Section. (line  44)
  7478. * end of file, in patterns:              Patterns.            (line 111)
  7479. * end of line, in negated character classes: Patterns.        (line 200)
  7480. * end of line, in patterns:              Patterns.            (line  92)
  7481. * end-of-file, and yyrestart():          Generated Scanner.   (line  44)
  7482. * EOF and yyrestart():                   Generated Scanner.   (line  44)
  7483. * EOF in patterns, syntax of:            Patterns.            (line 111)
  7484. * EOF, example using multiple input buffers: Multiple Input Buffers.
  7485.                                                               (line  81)
  7486. * EOF, explanation:                      EOF.                 (line   6)
  7487. * EOF, pushing back:                     Actions.             (line 178)
  7488. * EOL, in negated character classes:     Patterns.            (line 200)
  7489. * EOL, in patterns:                      Patterns.            (line  92)
  7490. * error messages, end of buffer missed:  Lex and Posix.       (line  50)
  7491. * error reporting, diagnostic messages:  Diagnostics.         (line   6)
  7492. * error reporting, in C++:               Cxx.                 (line 106)
  7493. * error rules, to eliminate backing up:  Performance.         (line 106)
  7494. * escape sequences in patterns, syntax of: Patterns.          (line  54)
  7495. * exiting with yyterminate():            Actions.             (line 221)
  7496. * experimental form of c++ scanner class: Cxx.                (line   6)
  7497. * extended scope of start conditions:    Start Conditions.    (line 283)
  7498. * file format:                           Format.              (line   6)
  7499. * file format, serialized tables:        Tables File Format.  (line   6)
  7500. * flushing an input buffer:              Multiple Input Buffers.
  7501.                                                               (line  66)
  7502. * flushing the internal buffer:          Actions.             (line 215)
  7503. * format of flex input:                  Format.              (line   6)
  7504. * format of input file:                  Format.              (line   9)
  7505. * freeing tables:                        Loading and Unloading Serialized Tables.
  7506.                                                               (line   6)
  7507. * getting current start state with YY_START: Start Conditions.
  7508.                                                               (line 199)
  7509. * halting with yyterminate():            Actions.             (line 221)
  7510. * handling include files with multiple input buffers: Multiple Input Buffers.
  7511.                                                               (line  87)
  7512. * header files, with C++:                Cxx.                 (line 186)
  7513. * include files, with C++:               Cxx.                 (line 186)
  7514. * input file, Definitions section:       Definitions Section. (line   6)
  7515. * input file, Rules Section:             Rules Section.       (line   6)
  7516. * input file, user code Section:         User Code Section.   (line   6)
  7517. * input():                               Actions.             (line 181)
  7518. * input(), and C++:                      Actions.             (line 211)
  7519. * input, format of:                      Format.              (line   6)
  7520. * input, matching:                       Matching.            (line   6)
  7521. * keywords, for performance:             Performance.         (line 211)
  7522. * lex (traditional) and POSIX:           Lex and Posix.       (line   6)
  7523. * LexerInput, overriding:                How do I use my own I/O classes in a C++ scanner?.
  7524.                                                               (line   9)
  7525. * LexerOutput, overriding:               How do I use my own I/O classes in a C++ scanner?.
  7526.                                                               (line   9)
  7527. * limitations of flex:                   Limitations.         (line   6)
  7528. * literal text in patterns, syntax of:   Patterns.            (line  51)
  7529. * loading tables at runtime:             Loading and Unloading Serialized Tables.
  7530.                                                               (line   6)
  7531. * m4:                                    M4 Dependency.       (line   6)
  7532. * Makefile, example of implicit rules:   Makefiles and Flex.  (line  21)
  7533. * Makefile, explicit example:            Makefiles and Flex.  (line  33)
  7534. * Makefile, syntax:                      Makefiles and Flex.  (line   6)
  7535. * matching C-style double-quoted strings: Start Conditions.   (line 214)
  7536. * matching, and trailing context:        Matching.            (line   6)
  7537. * matching, length of:                   Matching.            (line   6)
  7538. * matching, multiple matches:            Matching.            (line   6)
  7539. * member functions, C++:                 Cxx.                 (line   9)
  7540. * memory management:                     Memory Management.   (line   6)
  7541. * memory, allocating input buffers:      Multiple Input Buffers.
  7542.                                                               (line  19)
  7543. * memory, considerations for reentrant scanners: Init and Destroy Functions.
  7544.                                                               (line   6)
  7545. * memory, deleting input buffers:        Multiple Input Buffers.
  7546.                                                               (line  46)
  7547. * memory, for start condition stacks:    Start Conditions.    (line 316)
  7548. * memory, serialized tables <1>:         Loading and Unloading Serialized Tables.
  7549.                                                               (line   6)
  7550. * memory, serialized tables:             Serialized Tables.   (line   6)
  7551. * methods, c++:                          Cxx.                 (line   9)
  7552. * minimal scanner:                       Matching.            (line  24)
  7553. * multiple input streams:                Multiple Input Buffers.
  7554.                                                               (line   6)
  7555. * name definitions, not POSIX:           Lex and Posix.       (line  77)
  7556. * negating ranges in patterns:           Patterns.            (line  23)
  7557. * newline, matching in patterns:         Patterns.            (line  96)
  7558. * non-POSIX features of flex:            Lex and Posix.       (line 144)
  7559. * nowrap, %option:                       Generated Scanner.   (line  96)
  7560. * NULL character in patterns, syntax of: Patterns.            (line  59)
  7561. * octal characters in patterns:          Patterns.            (line  62)
  7562. * options, command-line:                 Scanner Options.     (line   6)
  7563. * overriding LexerInput:                 How do I use my own I/O classes in a C++ scanner?.
  7564.                                                               (line   9)
  7565. * overriding LexerOutput:                How do I use my own I/O classes in a C++ scanner?.
  7566.                                                               (line   9)
  7567. * overriding the memory routines:        Overriding The Default Memory Management.
  7568.                                                               (line  43)
  7569. * Pascal-like language:                  Simple Examples.     (line  51)
  7570. * pattern aliases, defining:             Definitions Section. (line  22)
  7571. * pattern aliases, expansion of:         Patterns.            (line  48)
  7572. * pattern aliases, how to define:        Definitions Section. (line  10)
  7573. * pattern aliases, use of:               Definitions Section. (line  30)
  7574. * patterns and actions on different lines: Lex and Posix.     (line 104)
  7575. * patterns, character class equivalence: Patterns.            (line 171)
  7576. * patterns, end of line:                 Patterns.            (line 237)
  7577. * patterns, grouping and precedence:     Patterns.            (line 128)
  7578. * patterns, in rules section:            Patterns.            (line   6)
  7579. * patterns, invalid trailing context:    Patterns.            (line 220)
  7580. * patterns, matching:                    Matching.            (line   6)
  7581. * patterns, precedence of operators:     Patterns.            (line 122)
  7582. * patterns, repetitions with grouping:   Patterns.            (line 148)
  7583. * patterns, special characters treated as non-special: Patterns.
  7584.                                                               (line 229)
  7585. * patterns, syntax:                      Patterns.            (line   9)
  7586. * patterns, tuning for performance:      Performance.         (line  51)
  7587. * patterns, valid character classes:     Patterns.            (line 157)
  7588. * performance optimization, matching longer tokens: Performance.
  7589.                                                               (line 176)
  7590. * performance optimization, recognizing keywords: Performance.
  7591.                                                               (line 216)
  7592. * performance, backing up:               Performance.         (line  51)
  7593. * performance, considerations:           Performance.         (line   6)
  7594. * performance, using keywords:           Performance.         (line 211)
  7595. * popping an input buffer:               Multiple Input Buffers.
  7596.                                                               (line  60)
  7597. * POSIX and lex:                         Lex and Posix.       (line   6)
  7598. * POSIX comp;compliance:                 Lex and Posix.       (line 144)
  7599. * POSIX, character classes in patterns, syntax of: Patterns.  (line  15)
  7600. * preprocessor macros, for use in actions: Actions.           (line  53)
  7601. * pushing an input buffer:               Multiple Input Buffers.
  7602.                                                               (line  52)
  7603. * pushing back characters with unput:    Actions.             (line 150)
  7604. * pushing back characters with unput():  Actions.             (line 154)
  7605. * pushing back characters with yyless:   Actions.             (line 137)
  7606. * pushing back EOF:                      Actions.             (line 178)
  7607. * ranges in patterns:                    Patterns.            (line  19)
  7608. * ranges in patterns, negating:          Patterns.            (line  23)
  7609. * recognizing C comments:                Start Conditions.    (line 151)
  7610. * reentrant scanners, multiple interleaved scanners: Reentrant Uses.
  7611.                                                               (line  10)
  7612. * reentrant scanners, recursive invocation: Reentrant Uses.   (line  31)
  7613. * reentrant, accessing flex variables:   Global Replacement.  (line   6)
  7614. * reentrant, accessor functions:         Accessor Methods.    (line   6)
  7615. * reentrant, API explanation:            Reentrant Overview.  (line   6)
  7616. * reentrant, calling functions:          Extra Reentrant Argument.
  7617.                                                               (line   6)
  7618. * reentrant, example of:                 Reentrant Example.   (line   6)
  7619. * reentrant, explanation:                Reentrant.           (line   6)
  7620. * reentrant, extra data:                 Extra Data.          (line   6)
  7621. * reentrant, initialization:             Init and Destroy Functions.
  7622.                                                               (line   6)
  7623. * regular expressions, in patterns:      Patterns.            (line   6)
  7624. * REJECT:                                Actions.             (line  64)
  7625. * REJECT, calling multiple times:        Actions.             (line  87)
  7626. * REJECT, performance costs:             Performance.         (line  12)
  7627. * reporting bugs:                        Reporting Bugs.      (line   6)
  7628. * restarting the scanner:                Lex and Posix.       (line  55)
  7629. * RETURN, within actions:                Generated Scanner.   (line  59)
  7630. * rules, default:                        Simple Examples.     (line  16)
  7631. * rules, in flex input:                  Rules Section.       (line   6)
  7632. * scanner, definition of:                Introduction.        (line   6)
  7633. * sections of flex input:                Format.              (line   6)
  7634. * serialization:                         Serialized Tables.   (line   6)
  7635. * serialization of tables:               Creating Serialized Tables.
  7636.                                                               (line   6)
  7637. * serialized tables, multiple scanners:  Creating Serialized Tables.
  7638.                                                               (line  27)
  7639. * stack, input buffer pop:               Multiple Input Buffers.
  7640.                                                               (line  60)
  7641. * stack, input buffer push:              Multiple Input Buffers.
  7642.                                                               (line  52)
  7643. * stacks, routines for manipulating:     Start Conditions.    (line 301)
  7644. * start condition, applying to multiple patterns: Start Conditions.
  7645.                                                               (line 270)
  7646. * start conditions:                      Start Conditions.    (line   6)
  7647. * start conditions, behavior of default rule: Start Conditions.
  7648.                                                               (line  87)
  7649. * start conditions, exclusive:           Start Conditions.    (line  56)
  7650. * start conditions, for different interpretations of same input: Start Conditions.
  7651.                                                               (line 119)
  7652. * start conditions, in patterns:         Patterns.            (line 101)
  7653. * start conditions, inclusive:           Start Conditions.    (line  46)
  7654. * start conditions, inclusive v.s. exclusive: Start Conditions.
  7655.                                                               (line  26)
  7656. * start conditions, integer values:      Start Conditions.    (line 172)
  7657. * start conditions, multiple:            Start Conditions.    (line  18)
  7658. * start conditions, special wildcard condition: Start Conditions.
  7659.                                                               (line  72)
  7660. * start conditions, use of a stack:      Start Conditions.    (line 301)
  7661. * start conditions, use of wildcard condition (<*>): Start Conditions.
  7662.                                                               (line  76)
  7663. * start conditions, using BEGIN:         Start Conditions.    (line 101)
  7664. * stdin, default for yyin:               Generated Scanner.   (line  39)
  7665. * stdout, as default for yyout:          Generated Scanner.   (line 104)
  7666. * strings, scanning strings instead of files: Multiple Input Buffers.
  7667.                                                               (line 177)
  7668. * tables, creating serialized:           Creating Serialized Tables.
  7669.                                                               (line   6)
  7670. * tables, file format:                   Tables File Format.  (line   6)
  7671. * tables, freeing:                       Loading and Unloading Serialized Tables.
  7672.                                                               (line   6)
  7673. * tables, loading and unloading:         Loading and Unloading Serialized Tables.
  7674.                                                               (line   6)
  7675. * terminating with yyterminate():        Actions.             (line 221)
  7676. * token:                                 Matching.            (line  14)
  7677. * trailing context, in patterns:         Patterns.            (line  79)
  7678. * trailing context, limits of:           Patterns.            (line 210)
  7679. * trailing context, matching:            Matching.            (line   6)
  7680. * trailing context, performance costs:   Performance.         (line  12)
  7681. * trailing context, variable length:     Performance.         (line 147)
  7682. * unput():                               Actions.             (line 150)
  7683. * unput(), and %pointer:                 Actions.             (line 170)
  7684. * unput(), pushing back characters:      Actions.             (line 154)
  7685. * user code, in flex input:              User Code Section.   (line   6)
  7686. * username expansion:                    Simple Examples.     (line   8)
  7687. * using integer values of start condition names: Start Conditions.
  7688.                                                               (line 172)
  7689. * verbatim text in patterns, syntax of:  Patterns.            (line  51)
  7690. * warning, dangerous trailing context:   Limitations.         (line  20)
  7691. * warning, rule cannot be matched:       Diagnostics.         (line  14)
  7692. * warnings, diagnostic messages:         Diagnostics.         (line   6)
  7693. * whitespace, compressing:               Actions.             (line  23)
  7694. * yacc interface:                        Yacc.                (line  17)
  7695. * yacc, interface:                       Yacc.                (line   6)
  7696. * YY_CURRENT_BUFFER, and multiple buffers Finally, the macro: Multiple Input Buffers.
  7697.                                                               (line  78)
  7698. * YY_EXTRA_TYPE, defining your own type: Extra Data.          (line  31)
  7699. * YY_FLUSH_BUFFER():                     Actions.             (line 215)
  7700. * YY_INPUT:                              Generated Scanner.   (line  63)
  7701. * YY_INPUT, overriding:                  Generated Scanner.   (line  73)
  7702. * YY_START, example:                     Start Conditions.    (line 195)
  7703. * YY_USER_ACTION to track each time a rule is matched: Misc Macros.
  7704.                                                               (line  14)
  7705. * yyalloc, overriding:                   Overriding The Default Memory Management.
  7706.                                                               (line   6)
  7707. * yyfree, overriding:                    Overriding The Default Memory Management.
  7708.                                                               (line   6)
  7709. * yyin:                                  Generated Scanner.   (line  39)
  7710. * yyinput():                             Actions.             (line 211)
  7711. * yyleng:                                Matching.            (line  14)
  7712. * yyleng, modification of:               Actions.             (line  50)
  7713. * yyless():                              Actions.             (line 131)
  7714. * yyless(), pushing back characters:     Actions.             (line 137)
  7715. * yylex(), in generated scanner:         Generated Scanner.   (line   6)
  7716. * yylex(), overriding:                   Generated Scanner.   (line  17)
  7717. * yylex, overriding the prototype of:    Generated Scanner.   (line  21)
  7718. * yylineno, in a reentrant scanner:      Reentrant Functions. (line  38)
  7719. * yylineno, performance costs:           Performance.         (line  12)
  7720. * yymore():                              Actions.             (line 109)
  7721. * yymore() to append token to previous token: Actions.        (line 115)
  7722. * yymore(), mega-kludge:                 Actions.             (line 115)
  7723. * yymore, and yyleng:                    Actions.             (line  50)
  7724. * yymore, performance penalty of:        Actions.             (line 125)
  7725. * yyout:                                 Generated Scanner.   (line 104)
  7726. * yyrealloc, overriding:                 Overriding The Default Memory Management.
  7727.                                                               (line   6)
  7728. * yyrestart():                           Generated Scanner.   (line  44)
  7729. * yyterminate():                         Actions.             (line 221)
  7730. * yytext:                                Matching.            (line  14)
  7731. * yytext, default array size:            User Values.         (line  13)
  7732. * yytext, memory considerations:         A Note About yytext And Memory.
  7733.                                                               (line   6)
  7734. * yytext, modification of:               Actions.             (line  44)
  7735. * yytext, two types of:                  Matching.            (line  30)
  7736. * yywrap():                              Generated Scanner.   (line  88)
  7737. * yywrap, default for:                   Generated Scanner.   (line  96)
  7738. * |, in actions:                         Actions.             (line  35)
  7739. * |, use of:                             Actions.             (line  87)
  7740.  
  7741. 
  7742. File: flex,  Node: Index of Functions and Macros,  Next: Index of Variables,  Prev: Concept Index,  Up: Indices
  7743.  
  7744. Index of Functions and Macros
  7745. =============================
  7746.  
  7747. This is an index of functions and preprocessor macros that look like
  7748. functions.  For macros that expand to variables or constants, see *Note
  7749. Index of Variables::.
  7750.  
  7751. [index]
  7752. * Menu:
  7753.  
  7754. * BEGIN:                                 Start Conditions.    (line  90)
  7755. * debug (C++ only):                      Cxx.                 (line  48)
  7756. * LexerError (C++ only):                 Cxx.                 (line 106)
  7757. * LexerInput (C++ only):                 Cxx.                 (line  91)
  7758. * LexerOutput (C++ only):                Cxx.                 (line 101)
  7759. * lineno (C++ only):                     Cxx.                 (line  38)
  7760. * set_debug (C++ only):                  Cxx.                 (line  42)
  7761. * switch_streams (C++ only):             Cxx.                 (line  78)
  7762. * YY_AT_BOL:                             Misc Macros.         (line  48)
  7763. * yy_create_buffer:                      Multiple Input Buffers.
  7764.                                                               (line  20)
  7765. * yy_delete_buffer:                      Multiple Input Buffers.
  7766.                                                               (line  47)
  7767. * yy_flush_buffer:                       Multiple Input Buffers.
  7768.                                                               (line  67)
  7769. * yy_new_buffer:                         Multiple Input Buffers.
  7770.                                                               (line  73)
  7771. * YY_NEW_FILE  (now obsolete):           EOF.                 (line  11)
  7772. * yy_pop_state:                          Start Conditions.    (line 311)
  7773. * yy_push_state:                         Start Conditions.    (line 305)
  7774. * yy_scan_buffer:                        Multiple Input Buffers.
  7775.                                                               (line 200)
  7776. * yy_scan_bytes:                         Multiple Input Buffers.
  7777.                                                               (line 190)
  7778. * yy_scan_string:                        Multiple Input Buffers.
  7779.                                                               (line 186)
  7780. * yy_set_bol:                            Misc Macros.         (line  42)
  7781. * yy_set_interactive:                    Misc Macros.         (line  30)
  7782. * yy_switch_to_buffer:                   Multiple Input Buffers.
  7783.                                                               (line  36)
  7784. * yy_top_state:                          Start Conditions.    (line 314)
  7785. * yyFlexLexer constructor (C++ only):    Cxx.                 (line  61)
  7786. * yyget_debug:                           Reentrant Functions. (line   8)
  7787. * yyget_extra <1>:                       Reentrant Functions. (line   8)
  7788. * yyget_extra:                           Extra Data.          (line  20)
  7789. * yyget_in:                              Reentrant Functions. (line   8)
  7790. * yyget_leng:                            Reentrant Functions. (line   8)
  7791. * yyget_lineno:                          Reentrant Functions. (line   8)
  7792. * yyget_out:                             Reentrant Functions. (line   8)
  7793. * yyget_text:                            Reentrant Functions. (line   8)
  7794. * YYLeng (C++ only):                     Cxx.                 (line  34)
  7795. * yylex (C++ version):                   Cxx.                 (line  66)
  7796. * yylex (reentrant version):             Bison Bridge.        (line  23)
  7797. * yylex_destroy:                         Init and Destroy Functions.
  7798.                                                               (line   6)
  7799. * yylex_init:                            Init and Destroy Functions.
  7800.                                                               (line   6)
  7801. * yypop_buffer_state:                    Multiple Input Buffers.
  7802.                                                               (line  61)
  7803. * yypush_buffer_state:                   Multiple Input Buffers.
  7804.                                                               (line  53)
  7805. * yyrestart:                             User Values.         (line  39)
  7806. * yyset_debug:                           Reentrant Functions. (line   8)
  7807. * yyset_extra <1>:                       Reentrant Functions. (line   8)
  7808. * yyset_extra:                           Extra Data.          (line  20)
  7809. * yyset_in:                              Reentrant Functions. (line   8)
  7810. * yyset_lineno:                          Reentrant Functions. (line   8)
  7811. * yyset_out:                             Reentrant Functions. (line   8)
  7812. * yytables_destroy:                      Loading and Unloading Serialized Tables.
  7813.                                                               (line  24)
  7814. * yytables_fload:                        Loading and Unloading Serialized Tables.
  7815.                                                               (line  11)
  7816. * YYText (C++ only):                     Cxx.                 (line  30)
  7817.  
  7818. 
  7819. File: flex,  Node: Index of Variables,  Next: Index of Data Types,  Prev: Index of Functions and Macros,  Up: Indices
  7820.  
  7821. Index of Variables
  7822. ==================
  7823.  
  7824. This is an index of variables, constants, and preprocessor macros that
  7825. expand to variables or constants.
  7826.  
  7827. [index]
  7828. * Menu:
  7829.  
  7830. * INITIAL:                               Start Conditions.    (line  90)
  7831. * YY_CURRENT_BUFFER:                     User Values.         (line  50)
  7832. * YY_END_OF_BUFFER_CHAR:                 Multiple Input Buffers.
  7833.                                                               (line 198)
  7834. * YY_NUM_RULES:                          Misc Macros.         (line  17)
  7835. * YY_START <1>:                          User Values.         (line  53)
  7836. * YY_START:                              Start Conditions.    (line 202)
  7837. * yyextra:                               Extra Data.          (line   6)
  7838. * yyin:                                  User Values.         (line  29)
  7839. * yyleng:                                User Values.         (line  26)
  7840. * yylloc:                                Bison Bridge.        (line   6)
  7841. * YYLMAX:                                User Values.         (line  13)
  7842. * yylval:                                Bison Bridge.        (line   6)
  7843. * yylval, with yacc:                     Yacc.                (line   6)
  7844. * yyout:                                 User Values.         (line  46)
  7845. * yyscanner (reentrant only):            Extra Reentrant Argument.
  7846.                                                               (line   6)
  7847. * yytext <1>:                            User Values.         (line   9)
  7848. * yytext:                                Matching.            (line  30)
  7849.  
  7850. 
  7851. File: flex,  Node: Index of Data Types,  Next: Index of Hooks,  Prev: Index of Variables,  Up: Indices
  7852.  
  7853. Index of Data Types
  7854. ===================
  7855.  
  7856. [index]
  7857. * Menu:
  7858.  
  7859. * FlexLexer (C++ only):                  Cxx.                 (line  57)
  7860. * YY_BUFFER_STATE:                       Multiple Input Buffers.
  7861.                                                               (line  25)
  7862. * YY_EXTRA_TYPE (reentrant only):        Extra Data.          (line  20)
  7863. * yy_size_t:                             Multiple Input Buffers.
  7864.                                                               (line 211)
  7865. * yyFlexLexer (C++ only):                Cxx.                 (line  57)
  7866. * YYLTYPE:                               Bison Bridge.        (line   6)
  7867. * yyscan_t (reentrant only):             About yyscan_t.      (line   6)
  7868. * YYSTYPE:                               Bison Bridge.        (line   6)
  7869.  
  7870. 
  7871. File: flex,  Node: Index of Hooks,  Next: Index of Scanner Options,  Prev: Index of Data Types,  Up: Indices
  7872.  
  7873. Index of Hooks
  7874. ==============
  7875.  
  7876. This is an index of "hooks" that the user may define. These hooks
  7877. typically  correspond to specific locations in the generated scanner,
  7878. and may be used to insert arbitrary code.
  7879.  
  7880. [index]
  7881. * Menu:
  7882.  
  7883. * YY_BREAK:                              Misc Macros.          (line 51)
  7884. * YY_USER_ACTION:                        Misc Macros.          (line  6)
  7885. * YY_USER_INIT:                          Misc Macros.          (line 25)
  7886.  
  7887. 
  7888. File: flex,  Node: Index of Scanner Options,  Prev: Index of Hooks,  Up: Indices
  7889.  
  7890. Index of Scanner Options
  7891. ========================
  7892.  
  7893. [index]
  7894. * Menu:
  7895.  
  7896. * -+:                                    Code-Level And API Options.
  7897.                                                               (line  50)
  7898. * --7bit:                                Options Affecting Scanner Behavior.
  7899.                                                               (line  57)
  7900. * --8bit:                                Options Affecting Scanner Behavior.
  7901.                                                               (line  81)
  7902. * --align:                               Options for Scanner Speed and Size.
  7903.                                                               (line  15)
  7904. * --always-interactive:                  Options Affecting Scanner Behavior.
  7905.                                                               (line  93)
  7906. * --array:                               Code-Level And API Options.
  7907.                                                               (line  54)
  7908. * --backup:                              Debugging Options.   (line   6)
  7909. * --batch:                               Options Affecting Scanner Behavior.
  7910.                                                               (line  23)
  7911. * --bison-bridge:                        Code-Level And API Options.
  7912.                                                               (line  17)
  7913. * --bison-locations:                     Code-Level And API Options.
  7914.                                                               (line  24)
  7915. * --c++:                                 Code-Level And API Options.
  7916.                                                               (line  50)
  7917. * --case-insensitive:                    Options Affecting Scanner Behavior.
  7918.                                                               (line   6)
  7919. * --debug:                               Debugging Options.   (line  16)
  7920. * --default:                             Options Affecting Scanner Behavior.
  7921.                                                               (line  90)
  7922. * --ecs:                                 Options for Scanner Speed and Size.
  7923.                                                               (line  24)
  7924. * --fast:                                Options for Scanner Speed and Size.
  7925.                                                               (line 101)
  7926. * --full:                                Options for Scanner Speed and Size.
  7927.                                                               (line  96)
  7928. * --header-file:                         Options for Specifing Filenames.
  7929.                                                               (line   6)
  7930. * --help:                                Miscellaneous Options.
  7931.                                                               (line   9)
  7932. * --interactive:                         Options Affecting Scanner Behavior.
  7933.                                                               (line  33)
  7934. * --lex-compat:                          Options Affecting Scanner Behavior.
  7935.                                                               (line  14)
  7936. * --main:                                Code-Level And API Options.
  7937.                                                               (line 101)
  7938. * --meta-ecs:                            Options for Scanner Speed and Size.
  7939.                                                               (line  45)
  7940. * --never-interactive:                   Options Affecting Scanner Behavior.
  7941.                                                               (line 101)
  7942. * --nodefault:                           Debugging Options.   (line  44)
  7943. * --noline:                              Code-Level And API Options.
  7944.                                                               (line  29)
  7945. * --nounistd:                            Code-Level And API Options.
  7946.                                                               (line 106)
  7947. * --nowarn:                              Debugging Options.   (line  56)
  7948. * --option-ansi-definitions:             Code-Level And API Options.
  7949.                                                               (line   6)
  7950. * --option-ansi-prototypes:              Code-Level And API Options.
  7951.                                                               (line  12)
  7952. * --outfile:                             Options for Specifing Filenames.
  7953.                                                               (line  21)
  7954. * --perf-report:                         Debugging Options.   (line  32)
  7955. * --pointer:                             Code-Level And API Options.
  7956.                                                               (line  57)
  7957. * --posix:                               Options Affecting Scanner Behavior.
  7958.                                                               (line 105)
  7959. * --prefix:                              Code-Level And API Options.
  7960.                                                               (line  61)
  7961. * --read:                                Options for Scanner Speed and Size.
  7962.                                                               (line  54)
  7963. * --reentrant:                           Code-Level And API Options.
  7964.                                                               (line  38)
  7965. * --skel:                                Options for Specifing Filenames.
  7966.                                                               (line  31)
  7967. * --stack:                               Options Affecting Scanner Behavior.
  7968.                                                               (line 125)
  7969. * --stdinit:                             Options Affecting Scanner Behavior.
  7970.                                                               (line 129)
  7971. * --stdout:                              Options for Specifing Filenames.
  7972.                                                               (line  27)
  7973. * --tables-file:                         Options for Specifing Filenames.
  7974.                                                               (line  36)
  7975. * --tables-verify:                       Options for Specifing Filenames.
  7976.                                                               (line  41)
  7977. * --trace:                               Debugging Options.   (line  50)
  7978. * --verbose:                             Debugging Options.   (line  59)
  7979. * --version:                             Miscellaneous Options.
  7980.                                                               (line  18)
  7981. * --warn:                                Debugging Options.   (line  67)
  7982. * --yyclass:                             Code-Level And API Options.
  7983.                                                               (line 115)
  7984. * --yylineno:                            Options Affecting Scanner Behavior.
  7985.                                                               (line 138)
  7986. * --yywrap:                              Options Affecting Scanner Behavior.
  7987.                                                               (line 146)
  7988. * -7:                                    Options Affecting Scanner Behavior.
  7989.                                                               (line  57)
  7990. * -8:                                    Options Affecting Scanner Behavior.
  7991.                                                               (line  81)
  7992. * -b:                                    Debugging Options.   (line   6)
  7993. * -B:                                    Options Affecting Scanner Behavior.
  7994.                                                               (line  23)
  7995. * -c:                                    Miscellaneous Options.
  7996.                                                               (line   6)
  7997. * -C:                                    Options for Scanner Speed and Size.
  7998.                                                               (line  10)
  7999. * -Ca:                                   Options for Scanner Speed and Size.
  8000.                                                               (line  15)
  8001. * -Ce:                                   Options for Scanner Speed and Size.
  8002.                                                               (line  24)
  8003. * -CF:                                   Options for Scanner Speed and Size.
  8004.                                                               (line  40)
  8005. * -Cf:                                   Options for Scanner Speed and Size.
  8006.                                                               (line  35)
  8007. * -Cm:                                   Options for Scanner Speed and Size.
  8008.                                                               (line  45)
  8009. * -Cr:                                   Options for Scanner Speed and Size.
  8010.                                                               (line  54)
  8011. * -d:                                    Debugging Options.   (line  16)
  8012. * -F:                                    Options for Scanner Speed and Size.
  8013.                                                               (line 101)
  8014. * -f:                                    Options for Scanner Speed and Size.
  8015.                                                               (line  96)
  8016. * -h:                                    Miscellaneous Options.
  8017.                                                               (line   9)
  8018. * -I:                                    Options Affecting Scanner Behavior.
  8019.                                                               (line  33)
  8020. * -i:                                    Options Affecting Scanner Behavior.
  8021.                                                               (line   6)
  8022. * -L:                                    Code-Level And API Options.
  8023.                                                               (line  29)
  8024. * -l:                                    Options Affecting Scanner Behavior.
  8025.                                                               (line  14)
  8026. * -n:                                    Miscellaneous Options.
  8027.                                                               (line  15)
  8028. * -o:                                    Options for Specifing Filenames.
  8029.                                                               (line  21)
  8030. * -p:                                    Debugging Options.   (line  32)
  8031. * -P:                                    Code-Level And API Options.
  8032.                                                               (line  61)
  8033. * -R:                                    Code-Level And API Options.
  8034.                                                               (line  38)
  8035. * -s:                                    Debugging Options.   (line  44)
  8036. * -T:                                    Debugging Options.   (line  50)
  8037. * -t:                                    Options for Specifing Filenames.
  8038.                                                               (line  27)
  8039. * -V:                                    Miscellaneous Options.
  8040.                                                               (line  18)
  8041. * -v:                                    Debugging Options.   (line  59)
  8042. * -w:                                    Debugging Options.   (line  56)
  8043. * -X:                                    Options Affecting Scanner Behavior.
  8044.                                                               (line 105)
  8045. * 7bit:                                  Options Affecting Scanner Behavior.
  8046.                                                               (line  57)
  8047. * 8bit:                                  Options Affecting Scanner Behavior.
  8048.                                                               (line  81)
  8049. * align:                                 Options for Scanner Speed and Size.
  8050.                                                               (line  15)
  8051. * always-interactive:                    Options Affecting Scanner Behavior.
  8052.                                                               (line  93)
  8053. * ansi-definitions:                      Code-Level And API Options.
  8054.                                                               (line   6)
  8055. * ansi-prototypes:                       Code-Level And API Options.
  8056.                                                               (line  12)
  8057. * array:                                 Code-Level And API Options.
  8058.                                                               (line  54)
  8059. * backup:                                Debugging Options.   (line   6)
  8060. * batch:                                 Options Affecting Scanner Behavior.
  8061.                                                               (line  23)
  8062. * bison-bridge:                          Code-Level And API Options.
  8063.                                                               (line  17)
  8064. * bison-locations:                       Code-Level And API Options.
  8065.                                                               (line  24)
  8066. * c++:                                   Code-Level And API Options.
  8067.                                                               (line  50)
  8068. * case-insensitive:                      Options Affecting Scanner Behavior.
  8069.                                                               (line   6)
  8070. * debug:                                 Debugging Options.   (line  16)
  8071. * default:                               Options Affecting Scanner Behavior.
  8072.                                                               (line  90)
  8073. * ecs:                                   Options for Scanner Speed and Size.
  8074.                                                               (line  24)
  8075. * fast:                                  Options for Scanner Speed and Size.
  8076.                                                               (line 101)
  8077. * full:                                  Options for Scanner Speed and Size.
  8078.                                                               (line  96)
  8079. * header-file:                           Options for Specifing Filenames.
  8080.                                                               (line   6)
  8081. * interactive:                           Options Affecting Scanner Behavior.
  8082.                                                               (line  33)
  8083. * lex-compat:                            Options Affecting Scanner Behavior.
  8084.                                                               (line  14)
  8085. * main:                                  Code-Level And API Options.
  8086.                                                               (line 101)
  8087. * meta-ecs:                              Options for Scanner Speed and Size.
  8088.                                                               (line  45)
  8089. * nodefault:                             Debugging Options.   (line  44)
  8090. * noline:                                Code-Level And API Options.
  8091.                                                               (line  29)
  8092. * nounistd:                              Code-Level And API Options.
  8093.                                                               (line 106)
  8094. * nowarn:                                Debugging Options.   (line  56)
  8095. * noyyalloc:                             Overriding The Default Memory Management.
  8096.                                                               (line  17)
  8097. * outfile:                               Options for Specifing Filenames.
  8098.                                                               (line  21)
  8099. * perf-report:                           Debugging Options.   (line  32)
  8100. * pointer:                               Code-Level And API Options.
  8101.                                                               (line  57)
  8102. * posix:                                 Options Affecting Scanner Behavior.
  8103.                                                               (line 105)
  8104. * prefix:                                Code-Level And API Options.
  8105.                                                               (line  61)
  8106. * read:                                  Options for Scanner Speed and Size.
  8107.                                                               (line  54)
  8108. * reentrant:                             Code-Level And API Options.
  8109.                                                               (line  38)
  8110. * stack:                                 Options Affecting Scanner Behavior.
  8111.                                                               (line 125)
  8112. * stdinit:                               Options Affecting Scanner Behavior.
  8113.                                                               (line 129)
  8114. * stdout:                                Options for Specifing Filenames.
  8115.                                                               (line  27)
  8116. * tables-file:                           Options for Specifing Filenames.
  8117.                                                               (line  36)
  8118. * tables-verify:                         Options for Specifing Filenames.
  8119.                                                               (line  41)
  8120. * trace:                                 Debugging Options.   (line  50)
  8121. * verbose:                               Debugging Options.   (line  59)
  8122. * warn:                                  Debugging Options.   (line  67)
  8123. * yyclass:                               Code-Level And API Options.
  8124.                                                               (line 115)
  8125. * yylineno:                              Options Affecting Scanner Behavior.
  8126.                                                               (line 138)
  8127. * yywrap:                                Options Affecting Scanner Behavior.
  8128.                                                               (line 146)
  8129.  
  8130.  
  8131. 
  8132. Tag Table:
  8133. Node: Top1571
  8134. Node: Copyright7332
  8135. Node: Reporting Bugs8763
  8136. Node: Introduction9054
  8137. Node: Simple Examples9877
  8138. Node: Format13182
  8139. Node: Definitions Section13591
  8140. Ref: Definitions Section-Footnote-115849
  8141. Node: Rules Section15917
  8142. Node: User Code Section17070
  8143. Node: Comments in the Input17503
  8144. Node: Patterns18862
  8145. Ref: case and character ranges24116
  8146. Node: Matching26791
  8147. Node: Actions30072
  8148. Node: Generated Scanner39045
  8149. Node: Start Conditions44058
  8150. Node: Multiple Input Buffers54611
  8151. Ref: Scanning Strings61144
  8152. Node: EOF62774
  8153. Node: Misc Macros64357
  8154. Node: User Values67207
  8155. Node: Yacc69533
  8156. Node: Scanner Options70424
  8157. Node: Options for Specifing Filenames73177
  8158. Ref: option-header73395
  8159. Ref: option-outfile74107
  8160. Ref: option-stdout74432
  8161. Node: Options Affecting Scanner Behavior75414
  8162. Ref: option-case-insensitive75649
  8163. Ref: option-lex-compat76082
  8164. Ref: option-batch76614
  8165. Ref: option-interactive77138
  8166. Ref: option-7bit78492
  8167. Ref: option-8bit79796
  8168. Ref: option-default80208
  8169. Ref: option-always-interactive80272
  8170. Ref: option-posix80876
  8171. Ref: option-stack82023
  8172. Ref: option-stdinit82131
  8173. Ref: option-yylineno82609
  8174. Ref: option-yywrap83052
  8175. Node: Code-Level And API Options83320
  8176. Ref: option-ansi-definitions83542
  8177. Ref: option-ansi-prototypes83794
  8178. Ref: option-bison-bridge84041
  8179. Ref: option-bison-locations84380
  8180. Ref: option-noline84640
  8181. Ref: option-reentrant85154
  8182. Ref: option-c++85765
  8183. Ref: option-array85891
  8184. Ref: option-pointer85989
  8185. Ref: option-prefix86117
  8186. Ref: option-main87646
  8187. Ref: option-nounistd87830
  8188. Ref: option-yyclass88338
  8189. Node: Options for Scanner Speed and Size88818
  8190. Ref: option-align89362
  8191. Ref: option-ecs89863
  8192. Ref: option-meta-ecs90899
  8193. Ref: option-read91386
  8194. Ref: option-full93269
  8195. Ref: option-fast93464
  8196. Node: Debugging Options94402
  8197. Ref: option-backup94584
  8198. Ref: option-debug95129
  8199. Ref: option-perf-report95852
  8200. Ref: option-nodefault96478
  8201. Ref: option-trace96796
  8202. Ref: option-nowarn97087
  8203. Ref: option-verbose97155
  8204. Ref: option-warn97584
  8205. Node: Miscellaneous Options97803
  8206. Node: Performance98282
  8207. Node: Cxx108537
  8208. Node: Reentrant116053
  8209. Node: Reentrant Uses116725
  8210. Node: Reentrant Overview118283
  8211. Node: Reentrant Example119077
  8212. Node: Reentrant Detail119832
  8213. Node: Specify Reentrant120260
  8214. Node: Extra Reentrant Argument120902
  8215. Node: Global Replacement122149
  8216. Node: Init and Destroy Functions123373
  8217. Node: Accessor Methods125517
  8218. Node: Extra Data126856
  8219. Node: About yyscan_t129018
  8220. Node: Reentrant Functions129409
  8221. Ref: bison-functions130888
  8222. Node: Lex and Posix131629
  8223. Node: Memory Management138876
  8224. Ref: memory-management139017
  8225. Node: The Default Memory Management139245
  8226. Ref: The Default Memory Management-Footnote-1142659
  8227. Node: Overriding The Default Memory Management142812
  8228. Ref: Overriding The Default Memory Management-Footnote-1145206
  8229. Node: A Note About yytext And Memory145370
  8230. Node: Serialized Tables146598
  8231. Ref: serialization146737
  8232. Node: Creating Serialized Tables147502
  8233. Node: Loading and Unloading Serialized Tables149107
  8234. Node: Tables File Format150870
  8235. Node: Diagnostics157881
  8236. Node: Limitations161287
  8237. Node: Bibliography163231
  8238. Node: FAQ163899
  8239. Node: When was flex born?167929
  8240. Node: How do I expand \ escape sequences in C-style quoted strings?168293
  8241. Node: Why do flex scanners call fileno if it is not ANSI compatible?169568
  8242. Node: Does flex support recursive pattern definitions?170350
  8243. Node: How do I skip huge chunks of input (tens of megabytes) while using flex?171192
  8244. Node: Flex is not matching my patterns in the same order that I defined them.171654
  8245. Node: My actions are executing out of order or sometimes not at all.173395
  8246. Node: How can I have multiple input sources feed into the same scanner at the same time?174165
  8247. Node: Can I build nested parsers that work with the same input file?176148
  8248. Node: How can I match text only at the end of a file?177149
  8249. Node: How can I make REJECT cascade across start condition boundaries?177949
  8250. Node: Why cant I use fast or full tables with interactive mode?178960
  8251. Node: How much faster is -F or -f than -C?180213
  8252. Node: If I have a simple grammar cant I just parse it with flex?180520
  8253. Node: Why doesnt yyrestart() set the start state back to INITIAL?180995
  8254. Node: How can I match C-style comments?181616
  8255. Node: The period isnt working the way I expected.182423
  8256. Node: Can I get the flex manual in another format?183664
  8257. Node: Does there exist a "faster" NDFA->DFA algorithm?184147
  8258. Node: How does flex compile the DFA so quickly?184652
  8259. Node: How can I use more than 8192 rules?185614
  8260. Node: How do I abandon a file in the middle of a scan and switch to a new file?187021
  8261. Node: How do I execute code only during initialization (only before the first scan)?187569
  8262. Node: How do I execute code at termination?188318
  8263. Node: Where else can I find help?188639
  8264. Node: Can I include comments in the "rules" section of the file?189006
  8265. Node: I get an error about undefined yywrap().189380
  8266. Node: How can I change the matching pattern at run time?189852
  8267. Node: How can I expand macros in the input?190209
  8268. Node: How can I build a two-pass scanner?191237
  8269. Node: How do I match any string not matched in the preceding rules?192147
  8270. Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf.193052
  8271. Node: Is there a way to make flex treat NULL like a regular character?193842
  8272. Node: Whenever flex can not match the input it says "flex scanner jammed".194358
  8273. Node: Why doesnt flex have non-greedy operators like perl does?194997
  8274. Node: Memory leak - 16386 bytes allocated by malloc.196344
  8275. Ref: faq-memory-leak196636
  8276. Node: How do I track the byte offset for lseek()?197604
  8277. Node: How do I use my own I/O classes in a C++ scanner?199110
  8278. Node: How do I skip as many chars as possible?199948
  8279. Node: deleteme00201020
  8280. Node: Are certain equivalent patterns faster than others?201456
  8281. Node: Is backing up a big deal?204870
  8282. Node: Can I fake multi-byte character support?206772
  8283. Node: deleteme01208209
  8284. Node: Can you discuss some flex internals?209314
  8285. Node: unput() messes up yy_at_bol211554
  8286. Node: The | operator is not doing what I want212652
  8287. Node: Why can't flex understand this variable trailing context pattern?214194
  8288. Node: The ^ operator isn't working215439
  8289. Node: Trailing context is getting confused with trailing optional patterns216670
  8290. Node: Is flex GNU or not?217909
  8291. Node: ERASEME53219578
  8292. Node: I need to scan if-then-else blocks and while loops220344
  8293. Node: ERASEME55221539
  8294. Node: ERASEME56222633
  8295. Node: ERASEME57223987
  8296. Node: Is there a repository for flex scanners?224981
  8297. Node: How can I conditionally compile or preprocess my flex input file?225291
  8298. Node: Where can I find grammars for lex and yacc?225759
  8299. Node: I get an end-of-buffer message for each character scanned.226101
  8300. Node: unnamed-faq-62226691
  8301. Node: unnamed-faq-63227705
  8302. Node: unnamed-faq-64228998
  8303. Node: unnamed-faq-65229960
  8304. Node: unnamed-faq-66230742
  8305. Node: unnamed-faq-67231853
  8306. Node: unnamed-faq-68232836
  8307. Node: unnamed-faq-69233974
  8308. Node: unnamed-faq-70234683
  8309. Node: unnamed-faq-71235440
  8310. Node: unnamed-faq-72236645
  8311. Node: unnamed-faq-73237684
  8312. Node: unnamed-faq-74238604
  8313. Node: unnamed-faq-75239545
  8314. Node: unnamed-faq-76240673
  8315. Node: unnamed-faq-77241375
  8316. Node: unnamed-faq-78242264
  8317. Node: unnamed-faq-79243258
  8318. Node: unnamed-faq-80244954
  8319. Node: unnamed-faq-81246268
  8320. Node: unnamed-faq-82249064
  8321. Node: unnamed-faq-83250017
  8322. Node: unnamed-faq-84251793
  8323. Node: unnamed-faq-85252892
  8324. Node: unnamed-faq-86253895
  8325. Node: unnamed-faq-87254829
  8326. Node: unnamed-faq-88255471
  8327. Node: unnamed-faq-90256298
  8328. Node: unnamed-faq-91257557
  8329. Node: unnamed-faq-92259981
  8330. Node: unnamed-faq-93260476
  8331. Node: unnamed-faq-94261399
  8332. Node: unnamed-faq-95262807
  8333. Node: unnamed-faq-96264321
  8334. Node: unnamed-faq-97265076
  8335. Node: unnamed-faq-98265739
  8336. Node: unnamed-faq-99266400
  8337. Node: unnamed-faq-100267325
  8338. Node: unnamed-faq-101268031
  8339. Node: Appendices268776
  8340. Node: Makefiles and Flex268960
  8341. Ref: Makefiles and Flex-Footnote-1272152
  8342. Ref: Makefiles and Flex-Footnote-2272269
  8343. Node: Bison Bridge272320
  8344. Ref: Bison Bridge-Footnote-1274984
  8345. Node: M4 Dependency275176
  8346. Ref: M4 Dependency-Footnote-1276092
  8347. Node: Indices276164
  8348. Node: Concept Index276397
  8349. Node: Index of Functions and Macros301602
  8350. Node: Index of Variables306493
  8351. Node: Index of Data Types308154
  8352. Node: Index of Hooks309037
  8353. Node: Index of Scanner Options309600
  8354. 
  8355. End Tag Table
  8356.