<html lang="en">
<head>
<title>flex: a fast lexical analyzer generator</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="flex: a fast lexical analyzer generator">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
The flex manual is placed under the same licensing conditions as the
rest of flex:

Copyright (C) 1990, 1997 The Regents of the University of California.
All rights reserved.

This code is derived from software contributed to Berkeley by
Vern Paxson.

The United States Government has rights in this work pursuant
to contract no. DE-AC03-76SF00098 between the United States
Department of Energy and the University of California.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
  1.  Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the
     distribution.

Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<h1 class="settitle">flex: a fast lexical analyzer generator</h1>
   <div class="contents">
<h2>Table of Contents</h2>
<ul>
<li><a name="toc_Top" href="#Top">flex</a>
<li><a name="toc_Copyright" href="#Copyright">1 Copyright</a>
<li><a name="toc_Reporting-Bugs" href="#Reporting-Bugs">2 Reporting Bugs</a>
<li><a name="toc_Introduction" href="#Introduction">3 Introduction</a>
<li><a name="toc_Simple-Examples" href="#Simple-Examples">4 Some Simple Examples</a>
<li><a name="toc_Format" href="#Format">5 Format of the Input File</a>
<ul>
<li><a href="#Definitions-Section">5.1 Format of the Definitions Section</a>
<li><a href="#Rules-Section">5.2 Format of the Rules Section</a>
<li><a href="#User-Code-Section">5.3 Format of the User Code Section</a>
<li><a href="#Comments-in-the-Input">5.4 Comments in the Input</a>
</li></ul>
<li><a name="toc_Patterns" href="#Patterns">6 Patterns</a>
<li><a name="toc_Matching" href="#Matching">7 How the Input Is Matched</a>
<li><a name="toc_Actions" href="#Actions">8 Actions</a>
<li><a name="toc_Generated-Scanner" href="#Generated-Scanner">9 The Generated Scanner</a>
<li><a name="toc_Start-Conditions" href="#Start-Conditions">10 Start Conditions</a>
<li><a name="toc_Multiple-Input-Buffers" href="#Multiple-Input-Buffers">11 Multiple Input Buffers</a>
<li><a name="toc_EOF" href="#EOF">12 End-of-File Rules</a>
<li><a name="toc_Misc-Macros" href="#Misc-Macros">13 Miscellaneous Macros</a>
<li><a name="toc_User-Values" href="#User-Values">14 Values Available To the User</a>
<li><a name="toc_Yacc" href="#Yacc">15 Interfacing with Yacc</a>
<li><a name="toc_Scanner-Options" href="#Scanner-Options">16 Scanner Options</a>
<ul>
<li><a href="#Options-for-Specifing-Filenames">16.1 Options for Specifing Filenames</a>
<li><a href="#Options-Affecting-Scanner-Behavior">16.2 Options Affecting Scanner Behavior</a>
<li><a href="#Code_002dLevel-And-API-Options">16.3 Code-Level And API Options</a>
<li><a href="#Options-for-Scanner-Speed-and-Size">16.4 Options for Scanner Speed and Size</a>
<li><a href="#Debugging-Options">16.5 Debugging Options</a>
<li><a href="#Miscellaneous-Options">16.6 Miscellaneous Options</a>
</li></ul>
<li><a name="toc_Performance" href="#Performance">17 Performance Considerations</a>
<li><a name="toc_Cxx" href="#Cxx">18 Generating C++ Scanners</a>
<li><a name="toc_Reentrant" href="#Reentrant">19 Reentrant C Scanners</a>
<ul>
<li><a href="#Reentrant-Uses">19.1 Uses for Reentrant Scanners</a>
<li><a href="#Reentrant-Overview">19.2 An Overview of the Reentrant API</a>
<li><a href="#Reentrant-Example">19.3 Reentrant Example</a>
<li><a href="#Reentrant-Detail">19.4 The Reentrant API in Detail</a>
<ul>
<li><a href="#Specify-Reentrant">19.4.1 Declaring a Scanner As Reentrant</a>
<li><a href="#Extra-Reentrant-Argument">19.4.2 The Extra Argument</a>
<li><a href="#Global-Replacement">19.4.3 Global Variables Replaced By Macros</a>
<li><a href="#Init-and-Destroy-Functions">19.4.4 Init and Destroy Functions</a>
<li><a href="#Accessor-Methods">19.4.5 Accessing Variables with Reentrant Scanners</a>
<li><a href="#Extra-Data">19.4.6 Extra Data</a>
<li><a href="#About-yyscan_005ft">19.4.7 About yyscan_t</a>
</li></ul>
<li><a href="#Reentrant-Functions">19.5 Functions and Macros Available in Reentrant C Scanners</a>
</li></ul>
<li><a name="toc_Lex-and-Posix" href="#Lex-and-Posix">20 Incompatibilities with Lex and Posix</a>
<li><a name="toc_Memory-Management" href="#Memory-Management">21 Memory Management</a>
<ul>
<li><a href="#The-Default-Memory-Management">21.1 The Default Memory Management</a>
<li><a href="#Overriding-The-Default-Memory-Management">21.2 Overriding The Default Memory Management</a>
<li><a href="#A-Note-About-yytext-And-Memory">21.3 A Note About yytext And Memory</a>
</li></ul>
<li><a name="toc_Serialized-Tables" href="#Serialized-Tables">22 Serialized Tables</a>
<ul>
<li><a href="#Creating-Serialized-Tables">22.1 Creating Serialized Tables</a>
<li><a href="#Loading-and-Unloading-Serialized-Tables">22.2 Loading and Unloading Serialized Tables</a>
<li><a href="#Tables-File-Format">22.3 Tables File Format</a>
</li></ul>
<li><a name="toc_Diagnostics" href="#Diagnostics">23 Diagnostics</a>
<li><a name="toc_Limitations" href="#Limitations">24 Limitations</a>
<li><a name="toc_Bibliography" href="#Bibliography">25 Additional Reading</a>
<li><a name="toc_FAQ" href="#FAQ">FAQ</a>
<ul>
<li><a href="#When-was-flex-born_003f">When was flex born?</a>
<li><a href="#How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f">How do I expand \ escape sequences in C-style quoted strings?</a>
<li><a href="#Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f">Why do flex scanners call fileno if it is not ANSI compatible?</a>
<li><a href="#Does-flex-support-recursive-pattern-definitions_003f">Does flex support recursive pattern definitions?</a>
<li><a href="#How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f">How do I skip huge chunks of input (tens of megabytes) while using flex?</a>
<li><a href="#Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e">Flex is not matching my patterns in the same order that I defined them.</a>
<li><a href="#My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e">My actions are executing out of order or sometimes not at all.</a>
<li><a href="#How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f">How can I have multiple input sources feed into the same scanner at the same time?</a>
<li><a href="#Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f">Can I build nested parsers that work with the same input file?</a>
<li><a href="#How-can-I-match-text-only-at-the-end-of-a-file_003f">How can I match text only at the end of a file?</a>
<li><a href="#How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f">How can I make REJECT cascade across start condition boundaries?</a>
<li><a href="#Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f">Why can't I use fast or full tables with interactive mode?</a>
<li><a href="#How-much-faster-is-_002dF-or-_002df-than-_002dC_003f">How much faster is -F or -f than -C?</a>
<li><a href="#If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f">If I have a simple grammar can't I just parse it with flex?</a>
<li><a href="#Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f">Why doesn't yyrestart() set the start state back to INITIAL?</a>
<li><a href="#How-can-I-match-C_002dstyle-comments_003f">How can I match C-style comments?</a>
<li><a href="#The-period-isnt-working-the-way-I-expected_002e">The '.' isn't working the way I expected.</a>
<li><a href="#Can-I-get-the-flex-manual-in-another-format_003f">Can I get the flex manual in another format?</a>
<li><a href="#Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f">Does there exist a "faster" NDFA-&gt;DFA algorithm?</a>
<li><a href="#How-does-flex-compile-the-DFA-so-quickly_003f">How does flex compile the DFA so quickly?</a>
<li><a href="#How-can-I-use-more-than-8192-rules_003f">How can I use more than 8192 rules?</a>
<li><a href="#How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f">How do I abandon a file in the middle of a scan and switch to a new file?</a>
<li><a href="#How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f">How do I execute code only during initialization (only before the first scan)?</a>
<li><a href="#How-do-I-execute-code-at-termination_003f">How do I execute code at termination?</a>
<li><a href="#Where-else-can-I-find-help_003f">Where else can I find help?</a>
<li><a href="#Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f">Can I include comments in the "rules" section of the file?</a>
<li><a href="#I-get-an-error-about-undefined-yywrap_0028_0029_002e">I get an error about undefined yywrap().</a>
<li><a href="#How-can-I-change-the-matching-pattern-at-run-time_003f">How can I change the matching pattern at run time?</a>
<li><a href="#How-can-I-expand-macros-in-the-input_003f">How can I expand macros in the input?</a>
<li><a href="#How-can-I-build-a-two_002dpass-scanner_003f">How can I build a two-pass scanner?</a>
<li><a href="#How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f">How do I match any string not matched in the preceding rules?</a>
<li><a href="#I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</a>
<li><a href="#Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f">Is there a way to make flex treat NULL like a regular character?</a>
<li><a href="#Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e">Whenever flex can not match the input it says "flex scanner jammed".</a>
<li><a href="#Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f">Why doesn't flex have non-greedy operators like perl does?</a>
<li><a href="#Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e">Memory leak - 16386 bytes allocated by malloc.</a>
<li><a href="#How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f">How do I track the byte offset for lseek()?</a>
<li><a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a>
<li><a href="#How-do-I-skip-as-many-chars-as-possible_003f">How do I skip as many chars as possible?</a>
<li><a href="#deleteme00">deleteme00</a>
<li><a href="#Are-certain-equivalent-patterns-faster-than-others_003f">Are certain equivalent patterns faster than others?</a>
<li><a href="#Is-backing-up-a-big-deal_003f">Is backing up a big deal?</a>
<li><a href="#Can-I-fake-multi_002dbyte-character-support_003f">Can I fake multi-byte character support?</a>
<li><a href="#deleteme01">deleteme01</a>
<li><a href="#Can-you-discuss-some-flex-internals_003f">Can you discuss some flex internals?</a>
<li><a href="#unput_0028_0029-messes-up-yy_005fat_005fbol">unput() messes up yy_at_bol</a>
<li><a href="#The-_007c-operator-is-not-doing-what-I-want">The | operator is not doing what I want</a>
<li><a href="#Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f">Why can't flex understand this variable trailing context pattern?</a>
<li><a href="#The-_005e-operator-isn_0027t-working">The ^ operator isn't working</a>
<li><a href="#Trailing-context-is-getting-confused-with-trailing-optional-patterns">Trailing context is getting confused with trailing optional patterns</a>
<li><a href="#Is-flex-GNU-or-not_003f">Is flex GNU or not?</a>
<li><a href="#ERASEME53">ERASEME53</a>
<li><a href="#I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops">I need to scan if-then-else blocks and while loops</a>
<li><a href="#ERASEME55">ERASEME55</a>
<li><a href="#ERASEME56">ERASEME56</a>
<li><a href="#ERASEME57">ERASEME57</a>
<li><a href="#Is-there-a-repository-for-flex-scanners_003f">Is there a repository for flex scanners?</a>
<li><a href="#How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f">How can I conditionally compile or preprocess my flex input file?</a>
<li><a href="#Where-can-I-find-grammars-for-lex-and-yacc_003f">Where can I find grammars for lex and yacc?</a>
<li><a href="#I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e">I get an end-of-buffer message for each character scanned.</a>
<li><a href="#unnamed_002dfaq_002d62">unnamed-faq-62</a>
<li><a href="#unnamed_002dfaq_002d63">unnamed-faq-63</a>
<li><a href="#unnamed_002dfaq_002d64">unnamed-faq-64</a>
<li><a href="#unnamed_002dfaq_002d65">unnamed-faq-65</a>
<li><a href="#unnamed_002dfaq_002d66">unnamed-faq-66</a>
<li><a href="#unnamed_002dfaq_002d67">unnamed-faq-67</a>
<li><a href="#unnamed_002dfaq_002d68">unnamed-faq-68</a>
<li><a href="#unnamed_002dfaq_002d69">unnamed-faq-69</a>
<li><a href="#unnamed_002dfaq_002d70">unnamed-faq-70</a>
<li><a href="#unnamed_002dfaq_002d71">unnamed-faq-71</a>
<li><a href="#unnamed_002dfaq_002d72">unnamed-faq-72</a>
<li><a href="#unnamed_002dfaq_002d73">unnamed-faq-73</a>
<li><a href="#unnamed_002dfaq_002d74">unnamed-faq-74</a>
<li><a href="#unnamed_002dfaq_002d75">unnamed-faq-75</a>
<li><a href="#unnamed_002dfaq_002d76">unnamed-faq-76</a>
<li><a href="#unnamed_002dfaq_002d77">unnamed-faq-77</a>
<li><a href="#unnamed_002dfaq_002d78">unnamed-faq-78</a>
<li><a href="#unnamed_002dfaq_002d79">unnamed-faq-79</a>
<li><a href="#unnamed_002dfaq_002d80">unnamed-faq-80</a>
<li><a href="#unnamed_002dfaq_002d81">unnamed-faq-81</a>
<li><a href="#unnamed_002dfaq_002d82">unnamed-faq-82</a>
<li><a href="#unnamed_002dfaq_002d83">unnamed-faq-83</a>
<li><a href="#unnamed_002dfaq_002d84">unnamed-faq-84</a>
<li><a href="#unnamed_002dfaq_002d85">unnamed-faq-85</a>
<li><a href="#unnamed_002dfaq_002d86">unnamed-faq-86</a>
<li><a href="#unnamed_002dfaq_002d87">unnamed-faq-87</a>
<li><a href="#unnamed_002dfaq_002d88">unnamed-faq-88</a>
<li><a href="#unnamed_002dfaq_002d90">unnamed-faq-90</a>
<li><a href="#unnamed_002dfaq_002d91">unnamed-faq-91</a>
<li><a href="#unnamed_002dfaq_002d92">unnamed-faq-92</a>
<li><a href="#unnamed_002dfaq_002d93">unnamed-faq-93</a>
<li><a href="#unnamed_002dfaq_002d94">unnamed-faq-94</a>
<li><a href="#unnamed_002dfaq_002d95">unnamed-faq-95</a>
<li><a href="#unnamed_002dfaq_002d96">unnamed-faq-96</a>
<li><a href="#unnamed_002dfaq_002d97">unnamed-faq-97</a>
<li><a href="#unnamed_002dfaq_002d98">unnamed-faq-98</a>
<li><a href="#unnamed_002dfaq_002d99">unnamed-faq-99</a>
<li><a href="#unnamed_002dfaq_002d100">unnamed-faq-100</a>
<li><a href="#unnamed_002dfaq_002d101">unnamed-faq-101</a>
</li></ul>
<li><a name="toc_Appendices" href="#Appendices">Appendix A Appendices</a>
<ul>
<li><a href="#Makefiles-and-Flex">A.1 Makefiles and Flex</a>
<li><a href="#Bison-Bridge">A.2 C Scanners with Bison Parsers</a>
<li><a href="#M4-Dependency">A.3 M4 Dependency</a>
</li></ul>
<li><a name="toc_Indices" href="#Indices">Indices</a>
<ul>
<li><a href="#Concept-Index">Concept Index</a>
<li><a href="#Index-of-Functions-and-Macros">Index of Functions and Macros</a>
<li><a href="#Index-of-Variables">Index of Variables</a>
<li><a href="#Index-of-Data-Types">Index of Data Types</a>
<li><a href="#Index-of-Hooks">Index of Hooks</a>
<li><a href="#Index-of-Scanner-Options">Index of Scanner Options</a>
</li></ul>
</li></ul>
</div>



<div class="node">
<p><hr>
<a name="Top"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Copyright">Copyright</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>

</div>

<h2 class="unnumbered">flex</h2>

<p>This manual describes <code>flex</code>, a tool for generating programs that
perform pattern-matching on text.  The manual includes both tutorial and
reference sections.

   <p>This edition of <cite>The flex Manual</cite> documents <code>flex</code> version
2.5.31. It was last updated on 27 March 2003.

<ul class="menu">
<li><a accesskey="1" href="#Copyright">Copyright</a>
<li><a accesskey="2" href="#Reporting-Bugs">Reporting Bugs</a>
<li><a accesskey="3" href="#Introduction">Introduction</a>
<li><a accesskey="4" href="#Simple-Examples">Simple Examples</a>
<li><a accesskey="5" href="#Format">Format</a>
<li><a accesskey="6" href="#Patterns">Patterns</a>
<li><a accesskey="7" href="#Matching">Matching</a>
<li><a accesskey="8" href="#Actions">Actions</a>
<li><a accesskey="9" href="#Generated-Scanner">Generated Scanner</a>
<li><a href="#Start-Conditions">Start Conditions</a>
<li><a href="#Multiple-Input-Buffers">Multiple Input Buffers</a>
<li><a href="#EOF">EOF</a>
<li><a href="#Misc-Macros">Misc Macros</a>
<li><a href="#User-Values">User Values</a>
<li><a href="#Yacc">Yacc</a>
<li><a href="#Scanner-Options">Scanner Options</a>
<li><a href="#Performance">Performance</a>
<li><a href="#Cxx">Cxx</a>
<li><a href="#Reentrant">Reentrant</a>
<li><a href="#Lex-and-Posix">Lex and Posix</a>
<li><a href="#Memory-Management">Memory Management</a>
<li><a href="#Serialized-Tables">Serialized Tables</a>
<li><a href="#Diagnostics">Diagnostics</a>
<li><a href="#Limitations">Limitations</a>
<li><a href="#Bibliography">Bibliography</a>
<li><a href="#FAQ">FAQ</a>
<li><a href="#Appendices">Appendices</a>
<li><a href="#Indices">Indices</a>

</li></ul>
<p>--- The Detailed Node Listing ---

<p>Format of the Input File

</p>
<ul class="menu">
<li><a href="#Definitions-Section">Definitions Section</a>
<li><a href="#Rules-Section">Rules Section</a>
<li><a href="#User-Code-Section">User Code Section</a>
<li><a href="#Comments-in-the-Input">Comments in the Input</a>

</li></ul>
<p>Scanner Options

</p>
<ul class="menu">
<li><a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a>
<li><a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a>
<li><a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a>
<li><a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a>
<li><a href="#Debugging-Options">Debugging Options</a>
<li><a href="#Miscellaneous-Options">Miscellaneous Options</a>

</li></ul>
<p>Reentrant C Scanners

</p>
<ul class="menu">
<li><a href="#Reentrant-Uses">Reentrant Uses</a>
<li><a href="#Reentrant-Overview">Reentrant Overview</a>
<li><a href="#Reentrant-Example">Reentrant Example</a>
<li><a href="#Reentrant-Detail">Reentrant Detail</a>
<li><a href="#Reentrant-Functions">Reentrant Functions</a>

</li></ul>
<p>The Reentrant API in Detail

</p>
<ul class="menu">
<li><a href="#Specify-Reentrant">Specify Reentrant</a>
<li><a href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a>
<li><a href="#Global-Replacement">Global Replacement</a>
<li><a href="#Init-and-Destroy-Functions">Init and Destroy Functions</a>
<li><a href="#Accessor-Methods">Accessor Methods</a>
<li><a href="#Extra-Data">Extra Data</a>
<li><a href="#About-yyscan_005ft">About yyscan_t</a>

</li></ul>
<p>Memory Management

</p>
<ul class="menu">
<li><a href="#The-Default-Memory-Management">The Default Memory Management</a>
<li><a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a>
<li><a href="#A-Note-About-yytext-And-Memory">A Note About yytext And Memory</a>

</li></ul>
<p>Serialized Tables

</p>
<ul class="menu">
<li><a href="#Creating-Serialized-Tables">Creating Serialized Tables</a>
<li><a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a>
<li><a href="#Tables-File-Format">Tables File Format</a>

</li></ul>
<p>FAQ

</p>
<ul class="menu">
<li><a href="#When-was-flex-born_003f">When was flex born?</a>
<li><a href="#How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f">How do I expand \ escape sequences in C-style quoted strings?</a>
<li><a href="#Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f">Why do flex scanners call fileno if it is not ANSI compatible?</a>
<li><a href="#Does-flex-support-recursive-pattern-definitions_003f">Does flex support recursive pattern definitions?</a>
<li><a href="#How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f">How do I skip huge chunks of input (tens of megabytes) while using flex?</a>
<li><a href="#Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e">Flex is not matching my patterns in the same order that I defined them.</a>
<li><a href="#My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e">My actions are executing out of order or sometimes not at all.</a>
<li><a href="#How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f">How can I have multiple input sources feed into the same scanner at the same time?</a>
<li><a href="#Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f">Can I build nested parsers that work with the same input file?</a>
<li><a href="#How-can-I-match-text-only-at-the-end-of-a-file_003f">How can I match text only at the end of a file?</a>
<li><a href="#How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f">How can I make REJECT cascade across start condition boundaries?</a>
<li><a href="#Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f">Why cant I use fast or full tables with interactive mode?</a>
<li><a href="#How-much-faster-is-_002dF-or-_002df-than-_002dC_003f">How much faster is -F or -f than -C?</a>
<li><a href="#If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f">If I have a simple grammar cant I just parse it with flex?</a>
<li><a href="#Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f">Why doesnt yyrestart() set the start state back to INITIAL?</a>
<li><a href="#How-can-I-match-C_002dstyle-comments_003f">How can I match C-style comments?</a>
<li><a href="#The-period-isnt-working-the-way-I-expected_002e">The period isnt working the way I expected.</a>
<li><a href="#Can-I-get-the-flex-manual-in-another-format_003f">Can I get the flex manual in another format?</a>
<li><a href="#Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f">Does there exist a "faster" NDFA-&gt;DFA algorithm?</a>
<li><a href="#How-does-flex-compile-the-DFA-so-quickly_003f">How does flex compile the DFA so quickly?</a>
<li><a href="#How-can-I-use-more-than-8192-rules_003f">How can I use more than 8192 rules?</a>
<li><a href="#How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f">How do I abandon a file in the middle of a scan and switch to a new file?</a>
<li><a href="#How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f">How do I execute code only during initialization (only before the first scan)?</a>
<li><a href="#How-do-I-execute-code-at-termination_003f">How do I execute code at termination?</a>
<li><a href="#Where-else-can-I-find-help_003f">Where else can I find help?</a>
<li><a href="#Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f">Can I include comments in the "rules" section of the file?</a>
<li><a href="#I-get-an-error-about-undefined-yywrap_0028_0029_002e">I get an error about undefined yywrap().</a>
<li><a href="#How-can-I-change-the-matching-pattern-at-run-time_003f">How can I change the matching pattern at run time?</a>
<li><a href="#How-can-I-expand-macros-in-the-input_003f">How can I expand macros in the input?</a>
<li><a href="#How-can-I-build-a-two_002dpass-scanner_003f">How can I build a two-pass scanner?</a>
<li><a href="#How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f">How do I match any string not matched in the preceding rules?</a>
<li><a href="#I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</a>
<li><a href="#Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f">Is there a way to make flex treat NULL like a regular character?</a>
<li><a href="#Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e">Whenever flex can not match the input it says "flex scanner jammed".</a>
<li><a href="#Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f">Why doesnt flex have non-greedy operators like perl does?</a>
<li><a href="#Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e">Memory leak - 16386 bytes allocated by malloc.</a>
<li><a href="#How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f">How do I track the byte offset for lseek()?</a>
<li><a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a>
<li><a href="#How-do-I-skip-as-many-chars-as-possible_003f">How do I skip as many chars as possible?</a>
<li><a href="#deleteme00">deleteme00</a>
<li><a href="#Are-certain-equivalent-patterns-faster-than-others_003f">Are certain equivalent patterns faster than others?</a>
<li><a href="#Is-backing-up-a-big-deal_003f">Is backing up a big deal?</a>
<li><a href="#Can-I-fake-multi_002dbyte-character-support_003f">Can I fake multi-byte character support?</a>
<li><a href="#deleteme01">deleteme01</a>
<li><a href="#Can-you-discuss-some-flex-internals_003f">Can you discuss some flex internals?</a>
<li><a href="#unput_0028_0029-messes-up-yy_005fat_005fbol">unput() messes up yy_at_bol</a>
<li><a href="#The-_007c-operator-is-not-doing-what-I-want">The | operator is not doing what I want</a>
<li><a href="#Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f">Why can't flex understand this variable trailing context pattern?</a>
<li><a href="#The-_005e-operator-isn_0027t-working">The ^ operator isn't working</a>
<li><a href="#Trailing-context-is-getting-confused-with-trailing-optional-patterns">Trailing context is getting confused with trailing optional patterns</a>
<li><a href="#Is-flex-GNU-or-not_003f">Is flex GNU or not?</a>
<li><a href="#ERASEME53">ERASEME53</a>
<li><a href="#I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops">I need to scan if-then-else blocks and while loops</a>
<li><a href="#ERASEME55">ERASEME55</a>
<li><a href="#ERASEME56">ERASEME56</a>
<li><a href="#ERASEME57">ERASEME57</a>
<li><a href="#Is-there-a-repository-for-flex-scanners_003f">Is there a repository for flex scanners?</a>
<li><a href="#How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f">How can I conditionally compile or preprocess my flex input file?</a>
<li><a href="#Where-can-I-find-grammars-for-lex-and-yacc_003f">Where can I find grammars for lex and yacc?</a>
<li><a href="#I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e">I get an end-of-buffer message for each character scanned.</a>
<li><a href="#unnamed_002dfaq_002d62">unnamed-faq-62</a>
<li><a href="#unnamed_002dfaq_002d63">unnamed-faq-63</a>
<li><a href="#unnamed_002dfaq_002d64">unnamed-faq-64</a>
<li><a href="#unnamed_002dfaq_002d65">unnamed-faq-65</a>
<li><a href="#unnamed_002dfaq_002d66">unnamed-faq-66</a>
<li><a href="#unnamed_002dfaq_002d67">unnamed-faq-67</a>
<li><a href="#unnamed_002dfaq_002d68">unnamed-faq-68</a>
<li><a href="#unnamed_002dfaq_002d69">unnamed-faq-69</a>
<li><a href="#unnamed_002dfaq_002d70">unnamed-faq-70</a>
<li><a href="#unnamed_002dfaq_002d71">unnamed-faq-71</a>
<li><a href="#unnamed_002dfaq_002d72">unnamed-faq-72</a>
<li><a href="#unnamed_002dfaq_002d73">unnamed-faq-73</a>
<li><a href="#unnamed_002dfaq_002d74">unnamed-faq-74</a>
<li><a href="#unnamed_002dfaq_002d75">unnamed-faq-75</a>
<li><a href="#unnamed_002dfaq_002d76">unnamed-faq-76</a>
<li><a href="#unnamed_002dfaq_002d77">unnamed-faq-77</a>
<li><a href="#unnamed_002dfaq_002d78">unnamed-faq-78</a>
<li><a href="#unnamed_002dfaq_002d79">unnamed-faq-79</a>
<li><a href="#unnamed_002dfaq_002d80">unnamed-faq-80</a>
<li><a href="#unnamed_002dfaq_002d81">unnamed-faq-81</a>
<li><a href="#unnamed_002dfaq_002d82">unnamed-faq-82</a>
<li><a href="#unnamed_002dfaq_002d83">unnamed-faq-83</a>
<li><a href="#unnamed_002dfaq_002d84">unnamed-faq-84</a>
<li><a href="#unnamed_002dfaq_002d85">unnamed-faq-85</a>
<li><a href="#unnamed_002dfaq_002d86">unnamed-faq-86</a>
<li><a href="#unnamed_002dfaq_002d87">unnamed-faq-87</a>
<li><a href="#unnamed_002dfaq_002d88">unnamed-faq-88</a>
<li><a href="#unnamed_002dfaq_002d90">unnamed-faq-90</a>
<li><a href="#unnamed_002dfaq_002d91">unnamed-faq-91</a>
<li><a href="#unnamed_002dfaq_002d92">unnamed-faq-92</a>
<li><a href="#unnamed_002dfaq_002d93">unnamed-faq-93</a>
<li><a href="#unnamed_002dfaq_002d94">unnamed-faq-94</a>
<li><a href="#unnamed_002dfaq_002d95">unnamed-faq-95</a>
<li><a href="#unnamed_002dfaq_002d96">unnamed-faq-96</a>
<li><a href="#unnamed_002dfaq_002d97">unnamed-faq-97</a>
<li><a href="#unnamed_002dfaq_002d98">unnamed-faq-98</a>
<li><a href="#unnamed_002dfaq_002d99">unnamed-faq-99</a>
<li><a href="#unnamed_002dfaq_002d100">unnamed-faq-100</a>
<li><a href="#unnamed_002dfaq_002d101">unnamed-faq-101</a>

</li></ul>
<p>Appendices

</p>
<ul class="menu">
<li><a href="#Makefiles-and-Flex">Makefiles and Flex</a>
<li><a href="#Bison-Bridge">Bison Bridge</a>
<li><a href="#M4-Dependency">M4 Dependency</a>

</li></ul>
<p>Indices

</p>
<ul class="menu">
<li><a href="#Concept-Index">Concept Index</a>
<li><a href="#Index-of-Functions-and-Macros">Index of Functions and Macros</a>
<li><a href="#Index-of-Variables">Index of Variables</a>
<li><a href="#Index-of-Data-Types">Index of Data Types</a>
<li><a href="#Index-of-Hooks">Index of Hooks</a>
<li><a href="#Index-of-Scanner-Options">Index of Scanner Options</a>

   </ul>

<div class="node">
<p><hr>
<a name="Copyright"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reporting-Bugs">Reporting Bugs</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Top">Top</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">1 Copyright</h2>

<p><a name="index-copyright-of-flex-1"></a><a name="index-distributing-flex-2"></a>The flex manual is placed under the same licensing conditions as the
rest of flex:

   <p>Copyright &copy; 1990, 1997 The Regents of the University of California. 
All rights reserved.

   <p>This code is derived from software contributed to Berkeley by
Vern Paxson.

   <p>The United States Government has rights in this work pursuant
to contract no. DE-AC03-76SF00098 between the United States
Department of Energy and the University of California.

   <p>Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

     <ol type=1 start=1>
<li> Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

     <li>Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
        </ol>

   <p>Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

   <p>THIS SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo; AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.

<div class="node">
<p><hr>
<a name="Reporting-Bugs"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Introduction">Introduction</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Copyright">Copyright</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">2 Reporting Bugs</h2>

<p><a name="index-bugs_002c-reporting-3"></a><a name="index-reporting-bugs-4"></a>
If you have problems with <code>flex</code> or think you have found a bug,
please send mail detailing your problem to
<a href="mailto:lex-help@lists.sourceforge.net">lex-help@lists.sourceforge.net</a>. Patches are always welcome.

<div class="node">
<p><hr>
<a name="Introduction"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Simple-Examples">Simple Examples</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reporting-Bugs">Reporting Bugs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">3 Introduction</h2>

<p><a name="index-scanner_002c-definition-of-5"></a><code>flex</code> is a tool for generating <dfn>scanners</dfn>.  A scanner is a
program which recognizes lexical patterns in text.  The <code>flex</code>
program reads the given input files, or its standard input if no file
names are given, for a description of a scanner to generate.  The
description is in the form of pairs of regular expressions and C code,
called <dfn>rules</dfn>. <code>flex</code> generates as output a C source file,
<samp><span class="file">lex.yy.c</span></samp> by default, which defines a routine <code>yylex()</code>. 
This file can be compiled and linked with the flex runtime library to
produce an executable.  When the executable is run, it analyzes its
input for occurrences of the regular expressions.  Whenever it finds
one, it executes the corresponding C code.

<div class="node">
<p><hr>
<a name="Simple-Examples"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Format">Format</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Introduction">Introduction</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">4 Some Simple Examples</h2>

<p>First some simple examples to get the flavor of how one uses
<code>flex</code>.

   <p><a name="index-username-expansion-6"></a>The following <code>flex</code> input specifies a scanner which, when it
encounters the string `<samp><span class="samp">username</span></samp>' will replace it with the user's
login name:

<pre class="example"><pre class="verbatim">     
         %%
         username    printf( "%s", getlogin() );
</pre>
</pre>
   <p><a name="index-default-rule-7"></a><a name="index-rules_002c-default-8"></a>By default, any text not matched by a <code>flex</code> scanner is copied to
the output, so the net effect of this scanner is to copy its input file
to its output with each occurrence of `<samp><span class="samp">username</span></samp>' expanded.  In this
input, there is just one rule.  `<samp><span class="samp">username</span></samp>' is the <dfn>pattern</dfn> and
the `<samp><span class="samp">printf</span></samp>' is the <dfn>action</dfn>.  The `<samp><span class="samp">%%</span></samp>' symbol marks the
beginning of the rules.

   <p>Here's another simple example:

   <p><a name="index-counting-characters-and-lines-9"></a>
<pre class="example"><pre class="verbatim">     
                 int num_lines = 0, num_chars = 0;
     
         %%
         \n      ++num_lines; ++num_chars;
         .       ++num_chars;
     
         %%
         main()
                 {
                 yylex();
                 printf( "# of lines = %d, # of chars = %d\n",
                         num_lines, num_chars );
                 }
</pre>
</pre>
   <p>This scanner counts the number of characters and the number of lines in
its input. It produces no output other than the final report on the
character and line counts.  The first line declares two globals,
<code>num_lines</code> and <code>num_chars</code>, which are accessible both inside
<code>yylex()</code> and in the <code>main()</code> routine declared after the
second `<samp><span class="samp">%%</span></samp>'.  There are two rules, one which matches a newline
(`<samp><span class="samp">\n</span></samp>') and increments both the line count and the character count,
and one which matches any character other than a newline (indicated by
the `<samp><span class="samp">.</span></samp>' regular expression).

   <p>A somewhat more complicated example:

   <p><a name="index-Pascal_002dlike-language-10"></a>
<pre class="example"><pre class="verbatim">     
         /* scanner for a toy Pascal-like language */
     
         %{
         /* need this for the call to atof() below */
         #include math.h>
         %}
     
         DIGIT    [0-9]
         ID       [a-z][a-z0-9]*
     
         %%
     
         {DIGIT}+    {
                     printf( "An integer: %s (%d)\n", yytext,
                             atoi( yytext ) );
                     }
     
         {DIGIT}+"."{DIGIT}*        {
                     printf( "A float: %s (%g)\n", yytext,
                             atof( yytext ) );
                     }
     
         if|then|begin|end|procedure|function        {
                     printf( "A keyword: %s\n", yytext );
                     }
     
         {ID}        printf( "An identifier: %s\n", yytext );
     
         "+"|"-"|"*"|"/"   printf( "An operator: %s\n", yytext );
     
         "{"[\^{}}\n]*"}"     /* eat up one-line comments */
     
         [ \t\n]+          /* eat up whitespace */
     
         .           printf( "Unrecognized character: %s\n", yytext );
     
         %%
     
         main( argc, argv )
         int argc;
         char **argv;
             {
             ++argv, --argc;  /* skip over program name */
             if ( argc > 0 )
                     yyin = fopen( argv[0], "r" );
             else
                     yyin = stdin;
     
             yylex();
             }
</pre>
</pre>
   <p>This is the beginnings of a simple scanner for a language like Pascal. 
It identifies different types of <dfn>tokens</dfn> and reports on what it has
seen.

   <p>The details of this example will be explained in the following
sections.

<div class="node">
<p><hr>
<a name="Format"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Patterns">Patterns</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Simple-Examples">Simple Examples</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">5 Format of the Input File</h2>

<p><a name="index-format-of-flex-input-11"></a><a name="index-input_002c-format-of-12"></a><a name="index-file-format-13"></a><a name="index-sections-of-flex-input-14"></a>
The <code>flex</code> input file consists of three sections, separated by a
line containing only `<samp><span class="samp">%%</span></samp>'.

   <p><a name="index-format-of-input-file-15"></a>
<pre class="example"><pre class="verbatim">     
         definitions
         %%
         rules
         %%
         user code
</pre>
</pre>
   <ul class="menu">
<li><a accesskey="1" href="#Definitions-Section">Definitions Section</a>
<li><a accesskey="2" href="#Rules-Section">Rules Section</a>
<li><a accesskey="3" href="#User-Code-Section">User Code Section</a>
<li><a accesskey="4" href="#Comments-in-the-Input">Comments in the Input</a>
</ul>

<div class="node">
<p><hr>
<a name="Definitions-Section"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Rules-Section">Rules Section</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Format">Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Format">Format</a>

</div>

<h3 class="section">5.1 Format of the Definitions Section</h3>

<p><a name="index-input-file_002c-Definitions-section-16"></a><a name="index-Definitions_002c-in-flex-input-17"></a>The <dfn>definitions section</dfn> contains declarations of simple <dfn>name</dfn>
definitions to simplify the scanner specification, and declarations of
<dfn>start conditions</dfn>, which are explained in a later section.

   <p><a name="index-aliases_002c-how-to-define-18"></a><a name="index-pattern-aliases_002c-how-to-define-19"></a>Name definitions have the form:

<pre class="example"><pre class="verbatim">     
         name definition
</pre>
</pre>
   <p>The `<samp><span class="samp">name</span></samp>' is a word beginning with a letter or an underscore
(`<samp><span class="samp">_</span></samp>') followed by zero or more letters, digits, `<samp><span class="samp">_</span></samp>', or
`<samp><span class="samp">-</span></samp>' (dash).  The definition is taken to begin at the first
non-whitespace character following the name and continuing to the end of
the line.  The definition can subsequently be referred to using
`<samp><span class="samp">{name}</span></samp>', which will expand to `<samp><span class="samp">(definition)</span></samp>'.  For example,

   <p><a name="index-pattern-aliases_002c-defining-20"></a><a name="index-defining-pattern-aliases-21"></a>
<pre class="example"><pre class="verbatim">     
         DIGIT    [0-9]
         ID       [a-z][a-z0-9]*
</pre>
</pre>
   <p>Defines `<samp><span class="samp">DIGIT</span></samp>' to be a regular expression which matches a single
digit, and `<samp><span class="samp">ID</span></samp>' to be a regular expression which matches a letter
followed by zero-or-more letters-or-digits.  A subsequent reference to

   <p><a name="index-pattern-aliases_002c-use-of-22"></a>
<pre class="example"><pre class="verbatim">     
         {DIGIT}+"."{DIGIT}*
</pre>
</pre>
   <p>is identical to

<pre class="example"><pre class="verbatim">     
         ([0-9])+"."([0-9])*
</pre>
</pre>
   <p>and matches one-or-more digits followed by a `<samp><span class="samp">.</span></samp>' followed by
zero-or-more digits.

   <p><a name="index-comments-in-flex-input-23"></a>An unindented comment (i.e., a line
beginning with `<samp><span class="samp">/*</span></samp>') is copied verbatim to the output up
to the next `<samp><span class="samp">*/</span></samp>'.

   <p><a name="index-g_t_0025_0040_007b-and-_0025_0040_007d_002c-in-Definitions-Section-24"></a><a name="index-embedding-C-code-in-flex-input-25"></a><a name="index-C-code-in-flex-input-26"></a>Any <em>indented</em> text or text enclosed in `<samp><span class="samp">%{</span></samp>' and `<samp><span class="samp">%}</span></samp>'
is also copied verbatim to the output (with the %{ and %} symbols
removed).  The %{ and %} symbols must appear unindented on lines by
themselves.

   <p><a name="index-g_t_0025top-27"></a>
A <code>%top</code> block is similar to a `<samp><span class="samp">%{</span></samp>' ... `<samp><span class="samp">%}</span></samp>' block, except
that the code in a <code>%top</code> block is relocated to the <em>top</em> of the
generated file, before any flex definitions <a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>. 
The <code>%top</code> block is useful when you want certain preprocessor macros to be
defined or certain files to be included before the generated code. 
The single characters, `<samp><span class="samp">{</span></samp>'  and `<samp><span class="samp">}</span></samp>' are used to delimit the
<code>%top</code> block, as show in the example below:

<pre class="example"><pre class="verbatim">     
         %top{
             /* This code goes at the "top" of the generated file. */
             #include &lt;stdint.h>
             #include &lt;inttypes.h>
         }
</pre>
</pre>
   <p>Multiple <code>%top</code> blocks are allowed, and their order is preserved.

<div class="node">
<p><hr>
<a name="Rules-Section"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#User-Code-Section">User Code Section</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Definitions-Section">Definitions Section</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Format">Format</a>

</div>

<h3 class="section">5.2 Format of the Rules Section</h3>

<p><a name="index-input-file_002c-Rules-Section-28"></a><a name="index-rules_002c-in-flex-input-29"></a>The <dfn>rules</dfn> section of the <code>flex</code> input contains a series of
rules of the form:

<pre class="example"><pre class="verbatim">     
         pattern   action
</pre>
</pre>
   <p>where the pattern must be unindented and the action must begin
on the same line. 
See <a href="#Patterns">Patterns</a>, for a further description of patterns and actions.

   <p>In the rules section, any indented or %{ %} enclosed text appearing
before the first rule may be used to declare variables which are local
to the scanning routine and (after the declarations) code which is to be
executed whenever the scanning routine is entered.  Other indented or
%{ %} text in the rule section is still copied to the output, but its
meaning is not well-defined and it may well cause compile-time errors
(this feature is present for <acronym>POSIX</acronym> compliance. See <a href="#Lex-and-Posix">Lex and Posix</a>, for other such features).

   <p>Any <em>indented</em> text or text enclosed in `<samp><span class="samp">%{</span></samp>' and `<samp><span class="samp">%}</span></samp>'
is copied verbatim to the output (with the %{ and %} symbols removed). 
The %{ and %} symbols must appear unindented on lines by themselves.

<div class="node">
<p><hr>
<a name="User-Code-Section"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Comments-in-the-Input">Comments in the Input</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Rules-Section">Rules Section</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Format">Format</a>

</div>

<h3 class="section">5.3 Format of the User Code Section</h3>

<p><a name="index-input-file_002c-user-code-Section-30"></a><a name="index-user-code_002c-in-flex-input-31"></a>The user code section is simply copied to <samp><span class="file">lex.yy.c</span></samp> verbatim.  It
is used for companion routines which call or are called by the scanner. 
The presence of this section is optional; if it is missing, the second
`<samp><span class="samp">%%</span></samp>' in the input file may be skipped, too.

<div class="node">
<p><hr>
<a name="Comments-in-the-Input"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#User-Code-Section">User Code Section</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Format">Format</a>

</div>

<h3 class="section">5.4 Comments in the Input</h3>

<p><a name="index-comments_002c-syntax-of-32"></a>Flex supports C-style comments, that is, anything between /* and */ is
considered a comment. Whenever flex encounters a comment, it copies the
entire comment verbatim to the generated source code. Comments may
appear just about anywhere, but with the following exceptions:

     
<a name="index-comments_002c-in-rules-section-33"></a>
<ul><li>Comments may not appear in the Rules Section wherever flex is expecting
a regular expression. This means comments may not appear at the
beginning of a line, or immediately following a list of scanner states. 
<li>Comments may not appear on an `<samp><span class="samp">%option</span></samp>' line in the Definitions
Section. 
</ul>

   <p>If you want to follow a simple rule, then always begin a comment on a
new line, with one or more whitespace characters before the initial
`<samp><span class="samp">/*</span></samp>').  This rule will work anywhere in the input file.

   <p>All the comments in the following example are valid:

   <p><a name="index-comments_002c-valid-uses-of-34"></a><a name="index-comments-in-the-input-35"></a>
<pre class="example"><pre class="verbatim">     
     %{
     /* code block */
     %}
     
     /* Definitions Section */
     %x STATE_X
     
     %%
         /* Rules Section */
     ruleA   /* after regex */ { /* code block */ } /* after code block */
             /* Rules Section (indented) */
     &lt;STATE_X>{
     ruleC   ECHO;
     ruleD   ECHO;
     %{
     /* code block */
     %}
     }
     %%
     /* User Code Section */
     
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Patterns"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Matching">Matching</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Format">Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">6 Patterns</h2>

<p><a name="index-patterns_002c-in-rules-section-36"></a><a name="index-regular-expressions_002c-in-patterns-37"></a>The patterns in the input (see <a href="#Rules-Section">Rules Section</a>) are written using an
extended set of regular expressions.  These are:

   <p><a name="index-patterns_002c-syntax-38"></a><a name="index-patterns_002c-syntax-39"></a>
     <dl>
<dt>`<samp><span class="samp">x</span></samp>'<dd>match the character 'x'

     <br><dt>`<samp><span class="samp">.</span></samp>'<dd>any character (byte) except newline

     <p><a name="index-g_t_005b_005d-in-patterns-40"></a><a name="index-character-classes-in-patterns_002c-syntax-of-41"></a><a name="index-POSIX_002c-character-classes-in-patterns_002c-syntax-of-42"></a><br><dt>`<samp><span class="samp">[xyz]</span></samp>'<dd>a <dfn>character class</dfn>; in this case, the pattern
matches either an 'x', a 'y', or a 'z'

     <p><a name="index-ranges-in-patterns-43"></a><br><dt>`<samp><span class="samp">[abj-oZ]</span></samp>'<dd>a "character class" with a range in it; matches
an 'a', a 'b', any letter from 'j' through 'o',
or a 'Z'

     <p><a name="index-ranges-in-patterns_002c-negating-44"></a><a name="index-negating-ranges-in-patterns-45"></a><br><dt>`<samp><span class="samp">[^A-Z]</span></samp>'<dd>a "negated character class", i.e., any character
but those in the class.  In this case, any
character EXCEPT an uppercase letter.

     <br><dt>`<samp><span class="samp">[^A-Z\n]</span></samp>'<dd>any character EXCEPT an uppercase letter or
a newline

     <br><dt>`<samp><span class="samp">r*</span></samp>'<dd>zero or more r's, where r is any regular expression

     <br><dt>`<samp><span class="samp">r+</span></samp>'<dd>one or more r's

     <br><dt>`<samp><span class="samp">r?</span></samp>'<dd>zero or one r's (that is, &ldquo;an optional r&rdquo;)

     <p><a name="index-braces-in-patterns-46"></a><br><dt>`<samp><span class="samp">r{2,5}</span></samp>'<dd>anywhere from two to five r's

     <br><dt>`<samp><span class="samp">r{2,}</span></samp>'<dd>two or more r's

     <br><dt>`<samp><span class="samp">r{4}</span></samp>'<dd>exactly 4 r's

     <p><a name="index-pattern-aliases_002c-expansion-of-47"></a><br><dt>`<samp><span class="samp">{name}</span></samp>'<dd>the expansion of the `<samp><span class="samp">name</span></samp>' definition
(see <a href="#Format">Format</a>).

     <p><a name="index-literal-text-in-patterns_002c-syntax-of-48"></a><a name="index-verbatim-text-in-patterns_002c-syntax-of-49"></a><br><dt>`<samp><span class="samp">"[xyz]\"foo"</span></samp>'<dd>the literal string: `<samp><span class="samp">[xyz]"foo</span></samp>'

     <p><a name="index-escape-sequences-in-patterns_002c-syntax-of-50"></a><br><dt>`<samp><span class="samp">\X</span></samp>'<dd>if X is `<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">f</span></samp>', `<samp><span class="samp">n</span></samp>', `<samp><span class="samp">r</span></samp>', `<samp><span class="samp">t</span></samp>', or
`<samp><span class="samp">v</span></samp>', then the ANSI-C interpretation of `<samp><span class="samp">\x</span></samp>'.  Otherwise, a
literal `<samp><span class="samp">X</span></samp>' (used to escape operators such as `<samp><span class="samp">*</span></samp>')

     <p><a name="index-NULL-character-in-patterns_002c-syntax-of-51"></a><br><dt>`<samp><span class="samp">\0</span></samp>'<dd>a NUL character (ASCII code 0)

     <p><a name="index-octal-characters-in-patterns-52"></a><br><dt>`<samp><span class="samp">\123</span></samp>'<dd>the character with octal value 123

     <br><dt>`<samp><span class="samp">\x2a</span></samp>'<dd>the character with hexadecimal value 2a

     <br><dt>`<samp><span class="samp">(r)</span></samp>'<dd>match an `<samp><span class="samp">r</span></samp>'; parentheses are used to override precedence (see below)

     <p><a name="index-concatenation_002c-in-patterns-53"></a><br><dt>`<samp><span class="samp">rs</span></samp>'<dd>the regular expression `<samp><span class="samp">r</span></samp>' followed by the regular expression `<samp><span class="samp">s</span></samp>'; called
<dfn>concatenation</dfn>

     <br><dt>`<samp><span class="samp">r|s</span></samp>'<dd>either an `<samp><span class="samp">r</span></samp>' or an `<samp><span class="samp">s</span></samp>'

     <p><a name="index-trailing-context_002c-in-patterns-54"></a><br><dt>`<samp><span class="samp">r/s</span></samp>'<dd>an `<samp><span class="samp">r</span></samp>' but only if it is followed by an `<samp><span class="samp">s</span></samp>'.  The text matched by `<samp><span class="samp">s</span></samp>' is
included when determining whether this rule is the longest match, but is
then returned to the input before the action is executed.  So the action
only sees the text matched by `<samp><span class="samp">r</span></samp>'.  This type of pattern is called
<dfn>trailing context</dfn>.  (There are some combinations of `<samp><span class="samp">r/s</span></samp>' that flex
cannot match correctly. See <a href="#Limitations">Limitations</a>, regarding dangerous trailing
context.)

     <p><a name="index-beginning-of-line_002c-in-patterns-55"></a><a name="index-BOL_002c-in-patterns-56"></a><br><dt>`<samp><span class="samp">^r</span></samp>'<dd>an `<samp><span class="samp">r</span></samp>', but only at the beginning of a line (i.e.,
when just starting to scan, or right after a
newline has been scanned).

     <p><a name="index-end-of-line_002c-in-patterns-57"></a><a name="index-EOL_002c-in-patterns-58"></a><br><dt>`<samp><span class="samp">r$</span></samp>'<dd>an `<samp><span class="samp">r</span></samp>', but only at the end of a line (i.e., just before a
newline).  Equivalent to `<samp><span class="samp">r/\n</span></samp>'.

     <p><a name="index-newline_002c-matching-in-patterns-59"></a>Note that <code>flex</code>'s notion of &ldquo;newline&rdquo; is exactly
whatever the C compiler used to compile <code>flex</code>
interprets `<samp><span class="samp">\n</span></samp>' as; in particular, on some DOS
systems you must either filter out `<samp><span class="samp">\r</span></samp>'s in the
input yourself, or explicitly use `<samp><span class="samp">r/\r\n</span></samp>' for `<samp><span class="samp">r$</span></samp>'.

     <p><a name="index-start-conditions_002c-in-patterns-60"></a><br><dt>`<samp><span class="samp">&lt;s&gt;r</span></samp>'<dd>an `<samp><span class="samp">r</span></samp>', but only in start condition <code>s</code> (see <a href="#Start-Conditions">Start Conditions</a> for discussion of start conditions).

     <br><dt>`<samp><span class="samp">&lt;s1,s2,s3&gt;r</span></samp>'<dd>same, but in any of start conditions <code>s1</code>, <code>s2</code>, or <code>s3</code>.

     <br><dt>`<samp><span class="samp">&lt;*&gt;r</span></samp>'<dd>an `<samp><span class="samp">r</span></samp>' in any start condition, even an exclusive one.

     <p><a name="index-end-of-file_002c-in-patterns-61"></a><a name="index-EOF-in-patterns_002c-syntax-of-62"></a><br><dt>`<samp><span class="samp">&lt;&lt;EOF&gt;&gt;</span></samp>'<dd>an end-of-file.

     <br><dt>`<samp><span class="samp">&lt;s1,s2&gt;&lt;&lt;EOF&gt;&gt;</span></samp>'<dd>an end-of-file when in start condition <code>s1</code> or <code>s2</code>
</dl>

   <p>Note that inside of a character class, all regular expression operators
lose their special meaning except escape (`<samp><span class="samp">\</span></samp>') and the character class
operators, `<samp><span class="samp">-</span></samp>', `<samp><span class="samp">]]</span></samp>', and, at the beginning of the class, `<samp><span class="samp">^</span></samp>'.

   <p><a name="index-patterns_002c-precedence-of-operators-63"></a>The regular expressions listed above are grouped according to
precedence, from highest precedence at the top to lowest at the bottom. 
Those grouped together have equal precedence (see special note on the
precedence of the repeat operator, `<samp><span class="samp">{}</span></samp>', under the documentation
for the `<samp><span class="samp">--posix</span></samp>' POSIX compliance option).  For example,

   <p><a name="index-patterns_002c-grouping-and-precedence-64"></a>
<pre class="example"><pre class="verbatim">     
         foo|bar*
</pre>
</pre>
   <p>is the same as

<pre class="example"><pre class="verbatim">     
         (foo)|(ba(r*))
</pre>
</pre>
   <p>since the `<samp><span class="samp">*</span></samp>' operator has higher precedence than concatenation,
and concatenation higher than alternation (`<samp><span class="samp">|</span></samp>').  This pattern
therefore matches <em>either</em> the string `<samp><span class="samp">foo</span></samp>' <em>or</em> the
string `<samp><span class="samp">ba</span></samp>' followed by zero-or-more `<samp><span class="samp">r</span></samp>''s.  To match
`<samp><span class="samp">foo</span></samp>' or zero-or-more repetitions of the string `<samp><span class="samp">bar</span></samp>', use:

<pre class="example"><pre class="verbatim">     
         foo|(bar)*
</pre>
</pre>
   <p>And to match a sequence of zero or more repetitions of `<samp><span class="samp">foo</span></samp>' and
`<samp><span class="samp">bar</span></samp>':

   <p><a name="index-patterns_002c-repetitions-with-grouping-65"></a>
<pre class="example"><pre class="verbatim">     
         (foo|bar)*
</pre>
</pre>
   <p><a name="index-character-classes-in-patterns-66"></a>In addition to characters and ranges of characters, character classes
can also contain <dfn>character class expressions</dfn>.  These are
expressions enclosed inside `<samp><span class="samp">[</span></samp>': and `<samp><span class="samp">:]</span></samp>' delimiters (which
themselves must appear between the `<samp><span class="samp">[</span></samp>' and `<samp><span class="samp">]</span></samp>' of the
character class. Other elements may occur inside the character class,
too).  The valid expressions are:

   <p><a name="index-patterns_002c-valid-character-classes-67"></a>
<pre class="example"><pre class="verbatim">     
         [:alnum:] [:alpha:] [:blank:]
         [:cntrl:] [:digit:] [:graph:]
         [:lower:] [:print:] [:punct:]
         [:space:] [:upper:] [:xdigit:]
</pre>
</pre>
   <p>These expressions all designate a set of characters equivalent to the
corresponding standard C <code>isXXX</code> function.  For example,
`<samp><span class="samp">[:alnum:]</span></samp>' designates those characters for which <code>isalnum()</code>
returns true - i.e., any alphabetic or numeric character.  Some systems
don't provide <code>isblank()</code>, so flex defines `<samp><span class="samp">[:blank:]</span></samp>' as a
blank or a tab.

   <p>For example, the following character classes are all equivalent:

   <p><a name="index-character-classes_002c-equivalence-of-68"></a><a name="index-patterns_002c-character-class-equivalence-69"></a>
<pre class="example"><pre class="verbatim">     
         [[:alnum:]]
         [[:alpha:][:digit:]]
         [[:alpha:][0-9]]
         [a-zA-Z0-9]
</pre>
</pre>
   <p>Some notes on patterns are in order.

     
<a name="index-case_002dinsensitive_002c-effect-on-character-classes-70"></a>
<ul><li>If your scanner is case-insensitive (the `<samp><span class="samp">-i</span></samp>' flag), then
`<samp><span class="samp">[:upper:]</span></samp>' and `<samp><span class="samp">[:lower:]</span></samp>' are equivalent to
`<samp><span class="samp">[:alpha:]</span></samp>'.

     <p><a name="case-and-character-ranges"></a>
<li>Character classes with ranges, such as `<samp><span class="samp">[a-Z]</span></samp>', should be used with
caution in a case-insensitive scanner if the range spans upper or lowercase
characters. Flex does not know if you want to fold all upper and lowercase
characters together, or if you want the literal numeric range specified (with
no case folding). When in doubt, flex will assume that you meant the literal
numeric range, and will issue a warning. The exception to this rule is a
character range such as `<samp><span class="samp">[a-z]</span></samp>' or `<samp><span class="samp">[S-W]</span></samp>' where it is obvious that you
want case-folding to occur. Here are some examples with the `<samp><span class="samp">-i</span></samp>' flag
enabled:

     <p><table summary=""><tr align="left"><td valign="top">Range </td><td valign="top">Result </td><td valign="top">Literal Range </td><td valign="top">Alternate Range
<br></td></tr><tr align="left"><td valign="top">`<samp><span class="samp">[a-t]</span></samp>' </td><td valign="top">ok </td><td valign="top">`<samp><span class="samp">[a-tA-T]</span></samp>' </td><td valign="top">
<br></td></tr><tr align="left"><td valign="top">`<samp><span class="samp">[A-T]</span></samp>' </td><td valign="top">ok </td><td valign="top">`<samp><span class="samp">[a-tA-T]</span></samp>' </td><td valign="top">
<br></td></tr><tr align="left"><td valign="top">`<samp><span class="samp">[A-t]</span></samp>' </td><td valign="top">ambiguous </td><td valign="top">`<samp><span class="samp">[A-Z\[\\\]_`a-t]</span></samp>' </td><td valign="top">`<samp><span class="samp">[a-tA-T]</span></samp>'
<br></td></tr><tr align="left"><td valign="top">`<samp><span class="samp">[_-{]</span></samp>' </td><td valign="top">ambiguous </td><td valign="top">`<samp><span class="samp">[_`a-z{]</span></samp>' </td><td valign="top">`<samp><span class="samp">[_`a-zA-Z{]</span></samp>'
<br></td></tr><tr align="left"><td valign="top">`<samp><span class="samp">[@-C]</span></samp>' </td><td valign="top">ambiguous </td><td valign="top">`<samp><span class="samp">[@ABC]</span></samp>' </td><td valign="top">`<samp><span class="samp">[@A-Z\[\\\]_`abc]</span></samp>'
     <br></td></tr></table>

     <p><a name="index-end-of-line_002c-in-negated-character-classes-71"></a><a name="index-EOL_002c-in-negated-character-classes-72"></a><li>A negated character class such as the example `<samp><span class="samp">[^A-Z]</span></samp>' above
<em>will</em> match a newline unless `<samp><span class="samp">\n</span></samp>' (or an equivalent escape
sequence) is one of the characters explicitly present in the negated
character class (e.g., `<samp><span class="samp">[^A-Z\n]</span></samp>').  This is unlike how many other
regular expression tools treat negated character classes, but
unfortunately the inconsistency is historically entrenched.  Matching
newlines means that a pattern like `<samp><span class="samp">[^"]*</span></samp>' can match the entire
input unless there's another quote in the input.

     <p><a name="index-trailing-context_002c-limits-of-73"></a><a name="index-g_t_005e-as-non_002dspecial-character-in-patterns-74"></a><a name="index-g_t_0024-as-normal-character-in-patterns-75"></a><li>A rule can have at most one instance of trailing context (the `<samp><span class="samp">/</span></samp>' operator
or the `<samp><span class="samp">$</span></samp>' operator).  The start condition, `<samp><span class="samp">^</span></samp>', and `<samp><span class="samp">&lt;&lt;EOF&gt;&gt;</span></samp>' patterns
can only occur at the beginning of a pattern, and, as well as with `<samp><span class="samp">/</span></samp>' and `<samp><span class="samp">$</span></samp>',
cannot be grouped inside parentheses.  A `<samp><span class="samp">^</span></samp>' which does not occur at
the beginning of a rule or a `<samp><span class="samp">$</span></samp>' which does not occur at the end of
a rule loses its special properties and is treated as a normal character.

     <li>The following are invalid:

     <p><a name="index-patterns_002c-invalid-trailing-context-76"></a>
     <pre class="example">     <pre class="verbatim">          
              foo/bar$
              &lt;sc1>foo&lt;sc2>bar
     </pre>
     </pre>
     <p>Note that the first of these can be written `<samp><span class="samp">foo/bar\n</span></samp>'.

     <li>The following will result in `<samp><span class="samp">$</span></samp>' or `<samp><span class="samp">^</span></samp>' being treated as a normal character:

     <p><a name="index-patterns_002c-special-characters-treated-as-non_002dspecial-77"></a>
     <pre class="example">     <pre class="verbatim">          
              foo|(bar$)
              foo|^bar
     </pre>
     </pre>
     <p>If the desired meaning is a `<samp><span class="samp">foo</span></samp>' or a
`<samp><span class="samp">bar</span></samp>'-followed-by-a-newline, the following could be used (the
special <code>|</code> action is explained below, see <a href="#Actions">Actions</a>):

     <p><a name="index-patterns_002c-end-of-line-78"></a>
     <pre class="example">     <pre class="verbatim">          
              foo      |
              bar$     /* action goes here */
     </pre>
     </pre>
     <p>A similar trick will work for matching a `<samp><span class="samp">foo</span></samp>' or a
`<samp><span class="samp">bar</span></samp>'-at-the-beginning-of-a-line. 
</ul>

<div class="node">
<p><hr>
<a name="Matching"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Actions">Actions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Patterns">Patterns</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">7 How the Input Is Matched</h2>

<p><a name="index-patterns_002c-matching-79"></a><a name="index-input_002c-matching-80"></a><a name="index-trailing-context_002c-matching-81"></a><a name="index-matching_002c-and-trailing-context-82"></a><a name="index-matching_002c-length-of-83"></a><a name="index-matching_002c-multiple-matches-84"></a>When the generated scanner is run, it analyzes its input looking for
strings which match any of its patterns.  If it finds more than one
match, it takes the one matching the most text (for trailing context
rules, this includes the length of the trailing part, even though it
will then be returned to the input).  If it finds two or more matches of
the same length, the rule listed first in the <code>flex</code> input file is
chosen.

   <p><a name="index-token-85"></a><a name="index-yytext-86"></a><a name="index-yyleng-87"></a>Once the match is determined, the text corresponding to the match
(called the <dfn>token</dfn>) is made available in the global character
pointer <code>yytext</code>, and its length in the global integer
<code>yyleng</code>.  The <dfn>action</dfn> corresponding to the matched pattern is
then executed (see <a href="#Actions">Actions</a>), and then the remaining input is scanned
for another match.

   <p><a name="index-default-rule-88"></a>If no match is found, then the <dfn>default rule</dfn> is executed: the next
character in the input is considered matched and copied to the standard
output.  Thus, the simplest valid <code>flex</code> input is:

   <p><a name="index-minimal-scanner-89"></a>
<pre class="example"><pre class="verbatim">     
         %%
</pre>
</pre>
   <p>which generates a scanner that simply copies its input (one character at
a time) to its output.

   <p><a name="index-yytext_002c-two-types-of-90"></a><a name="index-g_t_0025array_002c-use-of-91"></a><a name="index-g_t_0025pointer_002c-use-of-92"></a><a name="index-yytext-93"></a>Note that <code>yytext</code> can be defined in two different ways: either as
a character <em>pointer</em> or as a character <em>array</em>. You can
control which definition <code>flex</code> uses by including one of the
special directives <code>%pointer</code> or <code>%array</code> in the first
(definitions) section of your flex input.  The default is
<code>%pointer</code>, unless you use the `<samp><span class="samp">-l</span></samp>' lex compatibility option,
in which case <code>yytext</code> will be an array.  The advantage of using
<code>%pointer</code> is substantially faster scanning and no buffer overflow
when matching very large tokens (unless you run out of dynamic memory). 
The disadvantage is that you are restricted in how your actions can
modify <code>yytext</code> (see <a href="#Actions">Actions</a>), and calls to the <code>unput()</code>
function destroys the present contents of <code>yytext</code>, which can be a
considerable porting headache when moving between different <code>lex</code>
versions.

   <p><a name="index-g_t_0025array_002c-advantages-of-94"></a>The advantage of <code>%array</code> is that you can then modify <code>yytext</code>
to your heart's content, and calls to <code>unput()</code> do not destroy
<code>yytext</code> (see <a href="#Actions">Actions</a>).  Furthermore, existing <code>lex</code>
programs sometimes access <code>yytext</code> externally using declarations of
the form:

<pre class="example"><pre class="verbatim">     
         extern char yytext[];
</pre>
</pre>
   <p>This definition is erroneous when used with <code>%pointer</code>, but correct
for <code>%array</code>.

   <p>The <code>%array</code> declaration defines <code>yytext</code> to be an array of
<code>YYLMAX</code> characters, which defaults to a fairly large value.  You
can change the size by simply #define'ing <code>YYLMAX</code> to a different
value in the first section of your <code>flex</code> input.  As mentioned
above, with <code>%pointer</code> yytext grows dynamically to accommodate
large tokens.  While this means your <code>%pointer</code> scanner can
accommodate very large tokens (such as matching entire blocks of
comments), bear in mind that each time the scanner must resize
<code>yytext</code> it also must rescan the entire token from the beginning,
so matching such tokens can prove slow.  <code>yytext</code> presently does
<em>not</em> dynamically grow if a call to <code>unput()</code> results in too
much text being pushed back; instead, a run-time error results.

   <p><a name="index-g_t_0025array_002c-with-C_002b_002b-95"></a>Also note that you cannot use <code>%array</code> with C++ scanner classes
(see <a href="#Cxx">Cxx</a>).

<div class="node">
<p><hr>
<a name="Actions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Generated-Scanner">Generated Scanner</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Matching">Matching</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">8 Actions</h2>

<p><a name="index-actions-96"></a>Each pattern in a rule has a corresponding <dfn>action</dfn>, which can be
any arbitrary C statement.  The pattern ends at the first non-escaped
whitespace character; the remainder of the line is its action.  If the
action is empty, then when the pattern is matched the input token is
simply discarded.  For example, here is the specification for a program
which deletes all occurrences of `<samp><span class="samp">zap me</span></samp>' from its input:

   <p><a name="index-deleting-lines-from-input-97"></a>
<pre class="example"><pre class="verbatim">     
         %%
         "zap me"
</pre>
</pre>
   <p>This example will copy all other characters in the input to the output
since they will be matched by the default rule.

   <p>Here is a program which compresses multiple blanks and tabs down to a
single blank, and throws away whitespace found at the end of a line:

   <p><a name="index-whitespace_002c-compressing-98"></a><a name="index-compressing-whitespace-99"></a>
<pre class="example"><pre class="verbatim">     
         %%
         [ \t]+        putchar( ' ' );
         [ \t]+$       /* ignore this token */
</pre>
</pre>
   <p><a name="index-g_t_0025_0040_007b-and-_0025_0040_007d_002c-in-Rules-Section-100"></a><a name="index-actions_002c-use-of-_0040_007b-and-_0040_007d-101"></a><a name="index-actions_002c-embedded-C-strings-102"></a><a name="index-C_002dstrings_002c-in-actions-103"></a><a name="index-comments_002c-in-actions-104"></a>If the action contains a `<samp><span class="samp">}</span></samp>', then the action spans till the
balancing `<samp><span class="samp">}</span></samp>' is found, and the action may cross multiple lines. 
<code>flex</code> knows about C strings and comments and won't be fooled by
braces found within them, but also allows actions to begin with
`<samp><span class="samp">%{</span></samp>' and will consider the action to be all the text up to the
next `<samp><span class="samp">%}</span></samp>' (regardless of ordinary braces inside the action).

   <p><a name="index-g_t_007c_002c-in-actions-105"></a>An action consisting solely of a vertical bar (`<samp><span class="samp">|</span></samp>') means &ldquo;same as the
action for the next rule&rdquo;.  See below for an illustration.

   <p>Actions can include arbitrary C code, including <code>return</code> statements
to return a value to whatever routine called <code>yylex()</code>.  Each time
<code>yylex()</code> is called it continues processing tokens from where it
last left off until it either reaches the end of the file or executes a
return.

   <p><a name="index-yytext_002c-modification-of-106"></a>Actions are free to modify <code>yytext</code> except for lengthening it
(adding characters to its end&ndash;these will overwrite later characters in
the input stream).  This however does not apply when using <code>%array</code>
(see <a href="#Matching">Matching</a>). In that case, <code>yytext</code> may be freely modified
in any way.

   <p><a name="index-yyleng_002c-modification-of-107"></a><a name="index-yymore_002c-and-yyleng-108"></a>Actions are free to modify <code>yyleng</code> except they should not do so if
the action also includes use of <code>yymore()</code> (see below).

   <p><a name="index-preprocessor-macros_002c-for-use-in-actions-109"></a>There are a number of special directives which can be included within an
action:

     <dl>
<dt><code>ECHO</code><dd><a name="index-ECHO-110"></a>copies yytext to the scanner's output.

     <br><dt><code>BEGIN</code><dd><a name="index-BEGIN-111"></a>followed by the name of a start condition places the scanner in the
corresponding start condition (see below).

     <br><dt><code>REJECT</code><dd><a name="index-REJECT-112"></a>directs the scanner to proceed on to the &ldquo;second best&rdquo; rule which
matched the input (or a prefix of the input).  The rule is chosen as
described above in <a href="#Matching">Matching</a>, and <code>yytext</code> and <code>yyleng</code>
set up appropriately.  It may either be one which matched as much text
as the originally chosen rule but came later in the <code>flex</code> input
file, or one which matched less text.  For example, the following will
both count the words in the input and call the routine <code>special()</code>
whenever `<samp><span class="samp">frob</span></samp>' is seen:

     <pre class="example">     <pre class="verbatim">          
                      int word_count = 0;
              %%
          
              frob        special(); REJECT;
              [^ \t\n]+   ++word_count;
     </pre>
     </pre>
     <p>Without the <code>REJECT</code>, any occurences of `<samp><span class="samp">frob</span></samp>' in the input
would not be counted as words, since the scanner normally executes only
one action per token.  Multiple uses of <code>REJECT</code> are allowed, each
one finding the next best choice to the currently active rule.  For
example, when the following scanner scans the token `<samp><span class="samp">abcd</span></samp>', it will
write `<samp><span class="samp">abcdabcaba</span></samp>' to the output:

     <p><a name="index-REJECT_002c-calling-multiple-times-113"></a><a name="index-g_t_007c_002c-use-of-114"></a>
     <pre class="example">     <pre class="verbatim">          
              %%
              a        |
              ab       |
              abc      |
              abcd     ECHO; REJECT;
              .|\n     /* eat up any unmatched character */
     </pre>
     </pre>
     <p>The first three rules share the fourth's action since they use the
special `<samp><span class="samp">|</span></samp>' action.

     <p><code>REJECT</code> is a particularly expensive feature in terms of scanner
performance; if it is used in <em>any</em> of the scanner's actions it
will slow down <em>all</em> of the scanner's matching.  Furthermore,
<code>REJECT</code> cannot be used with the `<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' options
(see <a href="#Scanner-Options">Scanner Options</a>).

     <p>Note also that unlike the other special actions, <code>REJECT</code> is a
<em>branch</em>.  code immediately following it in the action will
<em>not</em> be executed.

     <br><dt><code>yymore()</code><dd><a name="index-yymore_0028_0029-115"></a>tells the scanner that the next time it matches a rule, the
corresponding token should be <em>appended</em> onto the current value of
<code>yytext</code> rather than replacing it.  For example, given the input
`<samp><span class="samp">mega-kludge</span></samp>' the following will write `<samp><span class="samp">mega-mega-kludge</span></samp>' to
the output:

     <p><a name="index-yymore_0028_0029_002c-mega_002dkludge-116"></a><a name="index-yymore_0028_0029-to-append-token-to-previous-token-117"></a>
     <pre class="example">     <pre class="verbatim">          
              %%
              mega-    ECHO; yymore();
              kludge   ECHO;
     </pre>
     </pre>
     <p>First `<samp><span class="samp">mega-</span></samp>' is matched and echoed to the output.  Then `<samp><span class="samp">kludge</span></samp>'
is matched, but the previous `<samp><span class="samp">mega-</span></samp>' is still hanging around at the
beginning of
<code>yytext</code>
so the
<code>ECHO</code>
for the `<samp><span class="samp">kludge</span></samp>' rule will actually write `<samp><span class="samp">mega-kludge</span></samp>'. 
</dl>

   <p><a name="index-yymore_002c-performance-penalty-of-118"></a>Two notes regarding use of <code>yymore()</code>.  First, <code>yymore()</code>
depends on the value of <code>yyleng</code> correctly reflecting the size of
the current token, so you must not modify <code>yyleng</code> if you are using
<code>yymore()</code>.  Second, the presence of <code>yymore()</code> in the
scanner's action entails a minor performance penalty in the scanner's
matching speed.

   <p><a name="index-yyless_0028_0029-119"></a><code>yyless(n)</code> returns all but the first <code>n</code> characters of the
current token back to the input stream, where they will be rescanned
when the scanner looks for the next match.  <code>yytext</code> and
<code>yyleng</code> are adjusted appropriately (e.g., <code>yyleng</code> will now
be equal to <code>n</code>).  For example, on the input `<samp><span class="samp">foobar</span></samp>' the
following will write out `<samp><span class="samp">foobarbar</span></samp>':

   <p><a name="index-yyless_0028_0029_002c-pushing-back-characters-120"></a><a name="index-pushing-back-characters-with-yyless-121"></a>
<pre class="example"><pre class="verbatim">     
         %%
         foobar    ECHO; yyless(3);
         [a-z]+    ECHO;
</pre>
</pre>
   <p>An argument of 0 to <code>yyless()</code> will cause the entire current input
string to be scanned again.  Unless you've changed how the scanner will
subsequently process its input (using <code>BEGIN</code>, for example), this
will result in an endless loop.

   <p>Note that <code>yyless()</code> is a macro and can only be used in the flex
input file, not from other source files.

   <p><a name="index-unput_0028_0029-122"></a><a name="index-pushing-back-characters-with-unput-123"></a><code>unput(c)</code> puts the character <code>c</code> back onto the input stream. 
It will be the next character scanned.  The following action will take
the current token and cause it to be rescanned enclosed in parentheses.

   <p><a name="index-unput_0028_0029_002c-pushing-back-characters-124"></a><a name="index-pushing-back-characters-with-unput_0028_0029-125"></a>
<pre class="example"><pre class="verbatim">     
         {
         int i;
         /* Copy yytext because unput() trashes yytext */
         char *yycopy = strdup( yytext );
         unput( ')' );
         for ( i = yyleng - 1; i >= 0; --i )
             unput( yycopy[i] );
         unput( '(' );
         free( yycopy );
         }
</pre>
</pre>
   <p>Note that since each <code>unput()</code> puts the given character back at the
<em>beginning</em> of the input stream, pushing back strings must be done
back-to-front.

   <p><a name="index-g_t_0025pointer_002c-and-unput_0028_0029-126"></a><a name="index-unput_0028_0029_002c-and-_0025pointer-127"></a>An important potential problem when using <code>unput()</code> is that if you
are using <code>%pointer</code> (the default), a call to <code>unput()</code>
<em>destroys</em> the contents of <code>yytext</code>, starting with its
rightmost character and devouring one character to the left with each
call.  If you need the value of <code>yytext</code> preserved after a call to
<code>unput()</code> (as in the above example), you must either first copy it
elsewhere, or build your scanner using <code>%array</code> instead
(see <a href="#Matching">Matching</a>).

   <p><a name="index-pushing-back-EOF-128"></a><a name="index-EOF_002c-pushing-back-129"></a>Finally, note that you cannot put back `<samp><span class="samp">EOF</span></samp>' to attempt to mark the
input stream with an end-of-file.

   <p><a name="index-input_0028_0029-130"></a><code>input()</code> reads the next character from the input stream.  For
example, the following is one way to eat up C comments:

   <p><a name="index-comments_002c-discarding-131"></a><a name="index-discarding-C-comments-132"></a>
<pre class="example"><pre class="verbatim">     
         %%
         "/*"        {
                     register int c;
     
                     for ( ; ; )
                         {
                         while ( (c = input()) != '*' &amp;&amp;
                                 c != EOF )
                             ;    /* eat up text of comment */
     
                         if ( c == '*' )
                             {
                             while ( (c = input()) == '*' )
                                 ;
                             if ( c == '/' )
                                 break;    /* found the end */
                             }
     
                         if ( c == EOF )
                             {
                             error( "EOF in comment" );
                             break;
                             }
                         }
                     }
</pre>
</pre>
   <p><a name="index-input_0028_0029_002c-and-C_002b_002b-133"></a><a name="index-yyinput_0028_0029-134"></a>(Note that if the scanner is compiled using <code>C++</code>, then
<code>input()</code> is instead referred to as <b>yyinput()</b>, in order to
avoid a name clash with the <code>C++</code> stream by the name of
<code>input</code>.)

   <p><a name="index-flushing-the-internal-buffer-135"></a><a name="index-YY_005fFLUSH_005fBUFFER_0028_0029-136"></a><code>YY_FLUSH_BUFFER()</code> flushes the scanner's internal buffer so that
the next time the scanner attempts to match a token, it will first
refill the buffer using <code>YY_INPUT()</code> (see <a href="#Generated-Scanner">Generated Scanner</a>). 
This action is a special case of the more general
<code>yy_flush_buffer()</code> function, described below (see <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a>)

   <p><a name="index-yyterminate_0028_0029-137"></a><a name="index-terminating-with-yyterminate_0028_0029-138"></a><a name="index-exiting-with-yyterminate_0028_0029-139"></a><a name="index-halting-with-yyterminate_0028_0029-140"></a><code>yyterminate()</code> can be used in lieu of a return statement in an
action.  It terminates the scanner and returns a 0 to the scanner's
caller, indicating &ldquo;all done&rdquo;.  By default, <code>yyterminate()</code> is
also called when an end-of-file is encountered.  It is a macro and may
be redefined.

<div class="node">
<p><hr>
<a name="Generated-Scanner"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Start-Conditions">Start Conditions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Actions">Actions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">9 The Generated Scanner</h2>

<p><a name="index-yylex_0028_0029_002c-in-generated-scanner-141"></a>The output of <code>flex</code> is the file <samp><span class="file">lex.yy.c</span></samp>, which contains
the scanning routine <code>yylex()</code>, a number of tables used by it for
matching tokens, and a number of auxiliary routines and macros.  By
default, <code>yylex()</code> is declared as follows:

<pre class="example"><pre class="verbatim">     
         int yylex()
             {
             ... various definitions and the actions in here ...
             }
</pre>
</pre>
   <p><a name="index-yylex_0028_0029_002c-overriding-142"></a>(If your environment supports function prototypes, then it will be
<code>int yylex( void )</code>.)  This definition may be changed by defining
the <code>YY_DECL</code> macro.  For example, you could use:

   <p><a name="index-yylex_002c-overriding-the-prototype-of-143"></a>
<pre class="example"><pre class="verbatim">     
         #define YY_DECL float lexscan( a, b ) float a, b;
</pre>
</pre>
   <p>to give the scanning routine the name <code>lexscan</code>, returning a float,
and taking two floats as arguments.  Note that if you give arguments to
the scanning routine using a K&amp;R-style/non-prototyped function
declaration, you must terminate the definition with a semi-colon (;).

   <p><code>flex</code> generates `<samp><span class="samp">C99</span></samp>' function definitions by
default. However flex does have the ability to generate obsolete, er,
`<samp><span class="samp">traditional</span></samp>', function definitions. This is to support
bootstrapping gcc on old systems.  Unfortunately, traditional
definitions prevent us from using any standard data types smaller than
int (such as short, char, or bool) as function arguments.  For this
reason, future versions of <code>flex</code> may generate standard C99 code
only, leaving K&amp;R-style functions to the historians.  Currently, if you
do <strong>not</strong> want `<samp><span class="samp">C99</span></samp>' definitions, then you must use
<code>%option noansi-definitions</code>.

   <p><a name="index-stdin_002c-default-for-yyin-144"></a><a name="index-yyin-145"></a>Whenever <code>yylex()</code> is called, it scans tokens from the global input
file <samp><span class="file">yyin</span></samp> (which defaults to stdin).  It continues until it
either reaches an end-of-file (at which point it returns the value 0) or
one of its actions executes a <code>return</code> statement.

   <p><a name="index-EOF-and-yyrestart_0028_0029-146"></a><a name="index-end_002dof_002dfile_002c-and-yyrestart_0028_0029-147"></a><a name="index-yyrestart_0028_0029-148"></a>If the scanner reaches an end-of-file, subsequent calls are undefined
unless either <samp><span class="file">yyin</span></samp> is pointed at a new input file (in which case
scanning continues from that file), or <code>yyrestart()</code> is called. 
<code>yyrestart()</code> takes one argument, a <code>FILE *</code> pointer (which
can be NULL, if you've set up <code>YY_INPUT</code> to scan from a source other
than <code>yyin</code>), and initializes <samp><span class="file">yyin</span></samp> for scanning from that
file.  Essentially there is no difference between just assigning
<samp><span class="file">yyin</span></samp> to a new input file or using <code>yyrestart()</code> to do so;
the latter is available for compatibility with previous versions of
<code>flex</code>, and because it can be used to switch input files in the
middle of scanning.  It can also be used to throw away the current input
buffer, by calling it with an argument of <samp><span class="file">yyin</span></samp>; but it would be
better to use <code>YY_FLUSH_BUFFER</code> (see <a href="#Actions">Actions</a>).  Note that
<code>yyrestart()</code> does <em>not</em> reset the start condition to
<code>INITIAL</code> (see <a href="#Start-Conditions">Start Conditions</a>).

   <p><a name="index-RETURN_002c-within-actions-149"></a>If <code>yylex()</code> stops scanning due to executing a <code>return</code>
statement in one of the actions, the scanner may then be called again
and it will resume scanning where it left off.

   <p><a name="index-YY_005fINPUT-150"></a>By default (and for purposes of efficiency), the scanner uses
block-reads rather than simple <code>getc()</code> calls to read characters
from <samp><span class="file">yyin</span></samp>.  The nature of how it gets its input can be controlled
by defining the <code>YY_INPUT</code> macro.  The calling sequence for
<code>YY_INPUT()</code> is <code>YY_INPUT(buf,result,max_size)</code>.  Its action
is to place up to <code>max_size</code> characters in the character array
<code>buf</code> and return in the integer variable <code>result</code> either the
number of characters read or the constant <code>YY_NULL</code> (0 on Unix
systems) to indicate `<samp><span class="samp">EOF</span></samp>'.  The default <code>YY_INPUT</code> reads from
the global file-pointer <samp><span class="file">yyin</span></samp>.

   <p><a name="index-YY_005fINPUT_002c-overriding-151"></a>Here is a sample definition of <code>YY_INPUT</code> (in the definitions
section of the input file):

<pre class="example"><pre class="verbatim">     
         %{
         #define YY_INPUT(buf,result,max_size) \
             { \
             int c = getchar(); \
             result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
             }
         %}
</pre>
</pre>
   <p>This definition will change the input processing to occur one character
at a time.

   <p><a name="index-yywrap_0028_0029-152"></a>When the scanner receives an end-of-file indication from YY_INPUT, it
then checks the <code>yywrap()</code> function.  If <code>yywrap()</code> returns
false (zero), then it is assumed that the function has gone ahead and
set up <samp><span class="file">yyin</span></samp> to point to another input file, and scanning
continues.  If it returns true (non-zero), then the scanner terminates,
returning 0 to its caller.  Note that in either case, the start
condition remains unchanged; it does <em>not</em> revert to
<code>INITIAL</code>.

   <p><a name="index-yywrap_002c-default-for-153"></a><a name="index-nowrap_002c-_0025option-154"></a><a name="index-g_t_0025option-nowrap-155"></a>If you do not supply your own version of <code>yywrap()</code>, then you must
either use <code>%option noyywrap</code> (in which case the scanner behaves as
though <code>yywrap()</code> returned 1), or you must link with `<samp><span class="samp">-lfl</span></samp>' to
obtain the default version of the routine, which always returns 1.

   <p>For scanning from in-memory buffers (e.g., scanning strings), see
<a href="#Scanning-Strings">Scanning Strings</a>. See <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a>.

   <p><a name="index-ECHO_002c-and-yyout-156"></a><a name="index-yyout-157"></a><a name="index-stdout_002c-as-default-for-yyout-158"></a>The scanner writes its <code>ECHO</code> output to the <samp><span class="file">yyout</span></samp> global
(default, <samp><span class="file">stdout</span></samp>), which may be redefined by the user simply by
assigning it to some other <code>FILE</code> pointer.

<div class="node">
<p><hr>
<a name="Start-Conditions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Multiple-Input-Buffers">Multiple Input Buffers</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Generated-Scanner">Generated Scanner</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">10 Start Conditions</h2>

<p><a name="index-start-conditions-159"></a><code>flex</code> provides a mechanism for conditionally activating rules. 
Any rule whose pattern is prefixed with `<samp><span class="samp">&lt;sc&gt;</span></samp>' will only be active
when the scanner is in the <dfn>start condition</dfn> named <code>sc</code>.  For
example,

<!-- proofread edit stopped here -->
<pre class="example"><pre class="verbatim">     
         &lt;STRING>[^"]*        { /* eat up the string body ... */
                     ...
                     }
</pre>
</pre>
   <p>will be active only when the scanner is in the <code>STRING</code> start
condition, and

   <p><a name="index-start-conditions_002c-multiple-160"></a>
<pre class="example"><pre class="verbatim">     
         &lt;INITIAL,STRING,QUOTE>\.        { /* handle an escape ... */
                     ...
                     }
</pre>
</pre>
   <p>will be active only when the current start condition is either
<code>INITIAL</code>, <code>STRING</code>, or <code>QUOTE</code>.

   <p><a name="index-start-conditions_002c-inclusive-v_002es_002e-exclusive-161"></a>Start conditions are declared in the definitions (first) section of the
input using unindented lines beginning with either `<samp><span class="samp">%s</span></samp>' or
`<samp><span class="samp">%x</span></samp>' followed by a list of names.  The former declares
<dfn>inclusive</dfn> start conditions, the latter <dfn>exclusive</dfn> start
conditions.  A start condition is activated using the <code>BEGIN</code>
action.  Until the next <code>BEGIN</code> action is executed, rules with the
given start condition will be active and rules with other start
conditions will be inactive.  If the start condition is inclusive, then
rules with no start conditions at all will also be active.  If it is
exclusive, then <em>only</em> rules qualified with the start condition
will be active.  A set of rules contingent on the same exclusive start
condition describe a scanner which is independent of any of the other
rules in the <code>flex</code> input.  Because of this, exclusive start
conditions make it easy to specify &ldquo;mini-scanners&rdquo; which scan portions
of the input that are syntactically different from the rest (e.g.,
comments).

   <p>If the distinction between inclusive and exclusive start conditions
is still a little vague, here's a simple example illustrating the
connection between the two.  The set of rules:

   <p><a name="index-start-conditions_002c-inclusive-162"></a>
<pre class="example"><pre class="verbatim">     
         %s example
         %%
     
         &lt;example>foo   do_something();
     
         bar            something_else();
</pre>
</pre>
   <p>is equivalent to

   <p><a name="index-start-conditions_002c-exclusive-163"></a>
<pre class="example"><pre class="verbatim">     
         %x example
         %%
     
         &lt;example>foo   do_something();
     
         &lt;INITIAL,example>bar    something_else();
</pre>
</pre>
   <p>Without the <code>&lt;INITIAL,example&gt;</code> qualifier, the <code>bar</code> pattern in
the second example wouldn't be active (i.e., couldn't match) when in
start condition <code>example</code>.  If we just used <code>example&gt;</code> to
qualify <code>bar</code>, though, then it would only be active in
<code>example</code> and not in <code>INITIAL</code>, while in the first example
it's active in both, because in the first example the <code>example</code>
start condition is an inclusive <code>(%s)</code> start condition.

   <p><a name="index-start-conditions_002c-special-wildcard-condition-164"></a>Also note that the special start-condition specifier
<code>&lt;*&gt;</code>
matches every start condition.  Thus, the above example could also
have been written:

   <p><a name="index-start-conditions_002c-use-of-wildcard-condition-_0028_003c_002a_003e_0029-165"></a>
<pre class="example"><pre class="verbatim">     
         %x example
         %%
     
         &lt;example>foo   do_something();
     
         &lt;*>bar    something_else();
</pre>
</pre>
   <p>The default rule (to <code>ECHO</code> any unmatched character) remains active
in start conditions.  It is equivalent to:

   <p><a name="index-start-conditions_002c-behavior-of-default-rule-166"></a>
<pre class="example"><pre class="verbatim">     
         &lt;*>.|\n     ECHO;
</pre>
</pre>
   <p><a name="index-BEGIN_002c-explanation-167"></a><a name="index-BEGIN-168"></a><a name="index-INITIAL-169"></a><code>BEGIN(0)</code> returns to the original state where only the rules with
no start conditions are active.  This state can also be referred to as
the start-condition <code>INITIAL</code>, so <code>BEGIN(INITIAL)</code> is
equivalent to <code>BEGIN(0)</code>.  (The parentheses around the start
condition name are not required but are considered good style.)

   <p><code>BEGIN</code> actions can also be given as indented code at the beginning
of the rules section.  For example, the following will cause the scanner
to enter the <code>SPECIAL</code> start condition whenever <code>yylex()</code> is
called and the global variable <code>enter_special</code> is true:

   <p><a name="index-start-conditions_002c-using-BEGIN-170"></a>
<pre class="example"><pre class="verbatim">     
                 int enter_special;
     
         %x SPECIAL
         %%
                 if ( enter_special )
                     BEGIN(SPECIAL);
     
         &lt;SPECIAL>blahblahblah
         ...more rules follow...
</pre>
</pre>
   <p>To illustrate the uses of start conditions, here is a scanner which
provides two different interpretations of a string like `<samp><span class="samp">123.456</span></samp>'. 
By default it will treat it as three tokens, the integer `<samp><span class="samp">123</span></samp>', a
dot (`<samp><span class="samp">.</span></samp>'), and the integer `<samp><span class="samp">456</span></samp>'.  But if the string is
preceded earlier in the line by the string `<samp><span class="samp">expect-floats</span></samp>' it will
treat it as a single token, the floating-point number `<samp><span class="samp">123.456</span></samp>':

   <p><a name="index-start-conditions_002c-for-different-interpretations-of-same-input-171"></a>
<pre class="example"><pre class="verbatim">     
         %{
         #include &lt;math.h>
         %}
         %s expect
     
         %%
         expect-floats        BEGIN(expect);
     
         &lt;expect>[0-9]+@samp{.}[0-9]+      {
                     printf( "found a float, = %f\n",
                             atof( yytext ) );
                     }
         &lt;expect>\n           {
                     /* that's the end of the line, so
                      * we need another "expect-number"
                      * before we'll recognize any more
                      * numbers
                      */
                     BEGIN(INITIAL);
                     }
     
         [0-9]+      {
                     printf( "found an integer, = %d\n",
                             atoi( yytext ) );
                     }
     
         "."         printf( "found a dot\n" );
</pre>
</pre>
   <p><a name="index-comments_002c-example-of-scanning-C-comments-172"></a>Here is a scanner which recognizes (and discards) C comments while
maintaining a count of the current input line.

   <p><a name="index-recognizing-C-comments-173"></a>
<pre class="example"><pre class="verbatim">     
         %x comment
         %%
                 int line_num = 1;
     
         "/*"         BEGIN(comment);
     
         &lt;comment>[^*\n]*        /* eat anything that's not a '*' */
         &lt;comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
         &lt;comment>\n             ++line_num;
         &lt;comment>"*"+"/"        BEGIN(INITIAL);
</pre>
</pre>
   <p>This scanner goes to a bit of trouble to match as much
text as possible with each rule.  In general, when attempting to write
a high-speed scanner try to match as much possible in each rule, as
it's a big win.

   <p>Note that start-conditions names are really integer values and
can be stored as such.  Thus, the above could be extended in the
following fashion:

   <p><a name="index-start-conditions_002c-integer-values-174"></a><a name="index-using-integer-values-of-start-condition-names-175"></a>
<pre class="example"><pre class="verbatim">     
         %x comment foo
         %%
                 int line_num = 1;
                 int comment_caller;
     
         "/*"         {
                      comment_caller = INITIAL;
                      BEGIN(comment);
                      }
     
         ...
     
         &lt;foo>"/*"    {
                      comment_caller = foo;
                      BEGIN(comment);
                      }
     
         &lt;comment>[^*\n]*        /* eat anything that's not a '*' */
         &lt;comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
         &lt;comment>\n             ++line_num;
         &lt;comment>"*"+"/"        BEGIN(comment_caller);
</pre>
</pre>
   <p><a name="index-YY_005fSTART_002c-example-176"></a>Furthermore, you can access the current start condition using the
integer-valued <code>YY_START</code> macro.  For example, the above
assignments to <code>comment_caller</code> could instead be written

   <p><a name="index-getting-current-start-state-with-YY_005fSTART-177"></a>
<pre class="example"><pre class="verbatim">     
         comment_caller = YY_START;
</pre>
</pre>
   <p><a name="index-YY_005fSTART-178"></a>Flex provides <code>YYSTATE</code> as an alias for <code>YY_START</code> (since that
is what's used by AT&amp;T <code>lex</code>).

   <p>For historical reasons, start conditions do not have their own
name-space within the generated scanner. The start condition names are
unmodified in the generated scanner and generated header. 
See <a href="#option_002dheader">option-header</a>. See <a href="#option_002dprefix">option-prefix</a>.

   <p>Finally, here's an example of how to match C-style quoted strings using
exclusive start conditions, including expanded escape sequences (but
not including checking for a string that's too long):

   <p><a name="index-matching-C_002dstyle-double_002dquoted-strings-179"></a>
<pre class="example"><pre class="verbatim">     
         %x str
     
         %%
                 char string_buf[MAX_STR_CONST];
                 char *string_buf_ptr;
     
     
         \"      string_buf_ptr = string_buf; BEGIN(str);
     
         &lt;str>\"        { /* saw closing quote - all done */
                 BEGIN(INITIAL);
                 *string_buf_ptr = '\0';
                 /* return string constant token type and
                  * value to parser
                  */
                 }
     
         &lt;str>\n        {
                 /* error - unterminated string constant */
                 /* generate error message */
                 }
     
         &lt;str>\\[0-7]{1,3} {
                 /* octal escape sequence */
                 int result;
     
                 (void) sscanf( yytext + 1, "%o", &amp;result );
     
                 if ( result > 0xff )
                         /* error, constant is out-of-bounds */
     
                 *string_buf_ptr++ = result;
                 }
     
         &lt;str>\\[0-9]+ {
                 /* generate error - bad escape sequence; something
                  * like '\48' or '\0777777'
                  */
                 }
     
         &lt;str>\\n  *string_buf_ptr++ = '\n';
         &lt;str>\\t  *string_buf_ptr++ = '\t';
         &lt;str>\\r  *string_buf_ptr++ = '\r';
         &lt;str>\\b  *string_buf_ptr++ = '\b';
         &lt;str>\\f  *string_buf_ptr++ = '\f';
     
         &lt;str>\\(.|\n)  *string_buf_ptr++ = yytext[1];
     
         &lt;str>[^\\\n\"]+        {
                 char *yptr = yytext;
     
                 while ( *yptr )
                         *string_buf_ptr++ = *yptr++;
                 }
</pre>
</pre>
   <p><a name="index-start-condition_002c-applying-to-multiple-patterns-180"></a>Often, such as in some of the examples above, you wind up writing a
whole bunch of rules all preceded by the same start condition(s).  Flex
makes this a little easier and cleaner by introducing a notion of start
condition <dfn>scope</dfn>.  A start condition scope is begun with:

<pre class="example"><pre class="verbatim">     
         &lt;SCs>{
</pre>
</pre>
   <p>where <code>SCs</code> is a list of one or more start conditions.  Inside the
start condition scope, every rule automatically has the prefix
<code>SCs&gt;</code> applied to it, until a `<samp><span class="samp">}</span></samp>' which matches the initial
`<samp><span class="samp">{</span></samp>'.  So, for example,

   <p><a name="index-extended-scope-of-start-conditions-181"></a>
<pre class="example"><pre class="verbatim">     
         &lt;ESC>{
             "\\n"   return '\n';
             "\\r"   return '\r';
             "\\f"   return '\f';
             "\\0"   return '\0';
         }
</pre>
</pre>
   <p>is equivalent to:

<pre class="example"><pre class="verbatim">     
         &lt;ESC>"\\n"  return '\n';
         &lt;ESC>"\\r"  return '\r';
         &lt;ESC>"\\f"  return '\f';
         &lt;ESC>"\\0"  return '\0';
</pre>
</pre>
   <p>Start condition scopes may be nested.

   <p><a name="index-stacks_002c-routines-for-manipulating-182"></a><a name="index-start-conditions_002c-use-of-a-stack-183"></a>
The following routines are available for manipulating stacks of start conditions:

<div class="defun">
&mdash; Function: void <b>yy_push_state</b> (<var> int </var><code>new_state</code> )<var><a name="index-yy_005fpush_005fstate-184"></a></var><br>
<blockquote><p>pushes the current start condition onto the top of the start condition
stack and switches to
<code>new_state</code>
as though you had used
<code>BEGIN new_state</code>
(recall that start condition names are also integers). 
</p></blockquote></div>

<div class="defun">
&mdash; Function: void <b>yy_pop_state</b> ()<var><a name="index-yy_005fpop_005fstate-185"></a></var><br>
<blockquote><p>pops the top of the stack and switches to it via
<code>BEGIN</code>. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: int <b>yy_top_state</b> ()<var><a name="index-yy_005ftop_005fstate-186"></a></var><br>
<blockquote><p>returns the top of the stack without altering the stack's contents. 
</p></blockquote></div>

   <p><a name="index-memory_002c-for-start-condition-stacks-187"></a>The start condition stack grows dynamically and so has no built-in size
limitation.  If memory is exhausted, program execution aborts.

   <p>To use start condition stacks, your scanner must include a <code>%option
stack</code> directive (see <a href="#Scanner-Options">Scanner Options</a>).

<div class="node">
<p><hr>
<a name="Multiple-Input-Buffers"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#EOF">EOF</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Start-Conditions">Start Conditions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">11 Multiple Input Buffers</h2>

<p><a name="index-multiple-input-streams-188"></a>Some scanners (such as those which support &ldquo;include&rdquo; files) require
reading from several input streams.  As <code>flex</code> scanners do a large
amount of buffering, one cannot control where the next input will be
read from by simply writing a <code>YY_INPUT()</code> which is sensitive to
the scanning context.  <code>YY_INPUT()</code> is only called when the scanner
reaches the end of its buffer, which may be a long time after scanning a
statement such as an <code>include</code> statement which requires switching
the input source.

   <p>To negotiate these sorts of problems, <code>flex</code> provides a mechanism
for creating and switching between multiple input buffers.  An input
buffer is created by using:

   <p><a name="index-memory_002c-allocating-input-buffers-189"></a>

<div class="defun">
&mdash; Function: YY_BUFFER_STATE <b>yy_create_buffer</b> (<var> FILE *file, int size </var>)<var><a name="index-yy_005fcreate_005fbuffer-190"></a></var><br>
</div>

   <p>which takes a <code>FILE</code> pointer and a size and creates a buffer
associated with the given file and large enough to hold <code>size</code>
characters (when in doubt, use <code>YY_BUF_SIZE</code> for the size).  It
returns a <code>YY_BUFFER_STATE</code> handle, which may then be passed to
other routines (see below). 
<a name="index-YY_005fBUFFER_005fSTATE-191"></a>The <code>YY_BUFFER_STATE</code> type is a
pointer to an opaque <code>struct yy_buffer_state</code> structure, so you may
safely initialize <code>YY_BUFFER_STATE</code> variables to <code>((YY_BUFFER_STATE)
0)</code> if you wish, and also refer to the opaque structure in order to
correctly declare input buffers in source files other than that of your
scanner.  Note that the <code>FILE</code> pointer in the call to
<code>yy_create_buffer</code> is only used as the value of <samp><span class="file">yyin</span></samp> seen by
<code>YY_INPUT</code>.  If you redefine <code>YY_INPUT()</code> so it no longer uses
<samp><span class="file">yyin</span></samp>, then you can safely pass a NULL <code>FILE</code> pointer to
<code>yy_create_buffer</code>.  You select a particular buffer to scan from
using:

<div class="defun">
&mdash; Function: void <b>yy_switch_to_buffer</b> (<var> YY_BUFFER_STATE new_buffer </var>)<var><a name="index-yy_005fswitch_005fto_005fbuffer-192"></a></var><br>
</div>

   <p>The above function switches the scanner's input buffer so subsequent tokens
will come from <code>new_buffer</code>.  Note that <code>yy_switch_to_buffer()</code> may
be used by <code>yywrap()</code> to set things up for continued scanning, instead of
opening a new file and pointing <samp><span class="file">yyin</span></samp> at it. If you are looking for a
stack of input buffers, then you want to use <code>yypush_buffer_state()</code>
instead of this function. Note also that switching input sources via either
<code>yy_switch_to_buffer()</code> or <code>yywrap()</code> does <em>not</em> change the
start condition.

   <p><a name="index-memory_002c-deleting-input-buffers-193"></a>

<div class="defun">
&mdash; Function: void <b>yy_delete_buffer</b> (<var> YY_BUFFER_STATE buffer </var>)<var><a name="index-yy_005fdelete_005fbuffer-194"></a></var><br>
</div>

   <p>is used to reclaim the storage associated with a buffer.  (<code>buffer</code>
can be NULL, in which case the routine does nothing.)  You can also clear
the current contents of a buffer using:

   <p><a name="index-pushing-an-input-buffer-195"></a><a name="index-stack_002c-input-buffer-push-196"></a>

<div class="defun">
&mdash; Function: void <b>yypush_buffer_state</b> (<var> YY_BUFFER_STATE buffer </var>)<var><a name="index-yypush_005fbuffer_005fstate-197"></a></var><br>
</div>

   <p>This function pushes the new buffer state onto an internal stack. The pushed
state becomes the new current state. The stack is maintained by flex and will
grow as required. This function is intended to be used instead of
<code>yy_switch_to_buffer</code>, when you want to change states, but preserve the
current state for later use.

   <p><a name="index-popping-an-input-buffer-198"></a><a name="index-stack_002c-input-buffer-pop-199"></a>

<div class="defun">
&mdash; Function: void <b>yypop_buffer_state</b> ( )<var><a name="index-yypop_005fbuffer_005fstate-200"></a></var><br>
</div>

   <p>This function removes the current state from the top of the stack, and deletes
it by calling <code>yy_delete_buffer</code>.  The next state on the stack, if any,
becomes the new current state.

   <p><a name="index-clearing-an-input-buffer-201"></a><a name="index-flushing-an-input-buffer-202"></a>

<div class="defun">
&mdash; Function: void <b>yy_flush_buffer</b> (<var> YY_BUFFER_STATE buffer </var>)<var><a name="index-yy_005fflush_005fbuffer-203"></a></var><br>
</div>

   <p>This function discards the buffer's contents,
so the next time the scanner attempts to match a token from the
buffer, it will first fill the buffer anew using
<code>YY_INPUT()</code>.

<div class="defun">
&mdash; Function: YY_BUFFER_STATE <b>yy_new_buffer</b> (<var> FILE *file, int size </var>)<var><a name="index-yy_005fnew_005fbuffer-204"></a></var><br>
</div>

   <p>is an alias for <code>yy_create_buffer()</code>,
provided for compatibility with the C++ use of <code>new</code> and
<code>delete</code> for creating and destroying dynamic objects.

   <p><a name="index-YY_005fCURRENT_005fBUFFER_002c-and-multiple-buffers-Finally_002c-the-macro-205"></a><code>YY_CURRENT_BUFFER</code> macro returns a <code>YY_BUFFER_STATE</code> handle to the
current buffer. It should not be used as an lvalue.

   <p><a name="index-EOF_002c-example-using-multiple-input-buffers-206"></a>Here are two examples of using these features for writing a scanner
which expands include files (the
<code>&lt;&lt;EOF&gt;&gt;</code>
feature is discussed below).

   <p>This first example uses yypush_buffer_state and yypop_buffer_state. Flex
maintains the stack internally.

   <p><a name="index-handling-include-files-with-multiple-input-buffers-207"></a>
<pre class="example"><pre class="verbatim">     
         /* the "incl" state is used for picking up the name
          * of an include file
          */
         %x incl
         %%
         include             BEGIN(incl);
     
         [a-z]+              ECHO;
         [^a-z\n]*\n?        ECHO;
     
         &lt;incl>[ \t]*      /* eat the whitespace */
         &lt;incl>[^ \t\n]+   { /* got the include file name */
                 yyin = fopen( yytext, "r" );
     
                 if ( ! yyin )
                     error( ... );
     
     			yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
     
                 BEGIN(INITIAL);
                 }
     
         &lt;&lt;EOF>> {
     			yypop_buffer_state();
     
                 if ( !YY_CURRENT_BUFFER )
                     {
                     yyterminate();
                     }
                 }
</pre>
</pre>
   <p>The second example, below, does the same thing as the previous example did, but
manages its own input buffer stack manually (instead of letting flex do it).

   <p><a name="index-handling-include-files-with-multiple-input-buffers-208"></a>
<pre class="example"><pre class="verbatim">     
         /* the "incl" state is used for picking up the name
          * of an include file
          */
         %x incl
     
         %{
         #define MAX_INCLUDE_DEPTH 10
         YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
         int include_stack_ptr = 0;
         %}
     
         %%
         include             BEGIN(incl);
     
         [a-z]+              ECHO;
         [^a-z\n]*\n?        ECHO;
     
         &lt;incl>[ \t]*      /* eat the whitespace */
         &lt;incl>[^ \t\n]+   { /* got the include file name */
                 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
                     {
                     fprintf( stderr, "Includes nested too deeply" );
                     exit( 1 );
                     }
     
                 include_stack[include_stack_ptr++] =
                     YY_CURRENT_BUFFER;
     
                 yyin = fopen( yytext, "r" );
     
                 if ( ! yyin )
                     error( ... );
     
                 yy_switch_to_buffer(
                     yy_create_buffer( yyin, YY_BUF_SIZE ) );
     
                 BEGIN(INITIAL);
                 }
     
         &lt;&lt;EOF>> {
                 if ( --include_stack_ptr  0 )
                     {
                     yyterminate();
                     }
     
                 else
                     {
                     yy_delete_buffer( YY_CURRENT_BUFFER );
                     yy_switch_to_buffer(
                          include_stack[include_stack_ptr] );
                     }
                 }
</pre>
</pre>
   <p><a name="Scanning-Strings"></a>
<a name="index-strings_002c-scanning-strings-instead-of-files-209"></a>The following routines are available for setting up input buffers for
scanning in-memory strings instead of files.  All of them create a new
input buffer for scanning the string, and return a corresponding
<code>YY_BUFFER_STATE</code> handle (which you should delete with
<code>yy_delete_buffer()</code> when done with it).  They also switch to the
new buffer using <code>yy_switch_to_buffer()</code>, so the next call to
<code>yylex()</code> will start scanning the string.

<div class="defun">
&mdash; Function: YY_BUFFER_STATE <b>yy_scan_string</b> (<var> const char *str </var>)<var><a name="index-yy_005fscan_005fstring-210"></a></var><br>
<blockquote><p>scans a NUL-terminated string. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: YY_BUFFER_STATE <b>yy_scan_bytes</b> (<var> const char *bytes, int len </var>)<var><a name="index-yy_005fscan_005fbytes-211"></a></var><br>
<blockquote><p>scans <code>len</code> bytes (including possibly <code>NUL</code>s) starting at location
<code>bytes</code>. 
</p></blockquote></div>

   <p>Note that both of these functions create and scan a <em>copy</em> of the
string or bytes.  (This may be desirable, since <code>yylex()</code> modifies
the contents of the buffer it is scanning.)  You can avoid the copy by
using:

   <p><a name="index-YY_005fEND_005fOF_005fBUFFER_005fCHAR-212"></a>

<div class="defun">
&mdash; Function: YY_BUFFER_STATE <b>yy_scan_buffer</b> (<var>char *base, yy_size_t size</var>)<var><a name="index-yy_005fscan_005fbuffer-213"></a></var><br>
<blockquote><p>which scans in place the buffer starting at <code>base</code>, consisting of
<code>size</code> bytes, the last two bytes of which <em>must</em> be
<code>YY_END_OF_BUFFER_CHAR</code> (ASCII NUL).  These last two bytes are not
scanned; thus, scanning consists of <code>base[0]</code> through
<code>base[size-2]</code>, inclusive. 
</p></blockquote></div>

   <p>If you fail to set up <code>base</code> in this manner (i.e., forget the final
two <code>YY_END_OF_BUFFER_CHAR</code> bytes), then <code>yy_scan_buffer()</code>
returns a NULL pointer instead of creating a new input buffer.

<div class="defun">
&mdash; Data type: <b>yy_size_t</b><var><a name="index-yy_005fsize_005ft-214"></a></var><br>
<blockquote><p>is an integral type to which you can cast an integer expression
reflecting the size of the buffer. 
</p></blockquote></div>

<div class="node">
<p><hr>
<a name="EOF"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Misc-Macros">Misc Macros</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Multiple-Input-Buffers">Multiple Input Buffers</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">12 End-of-File Rules</h2>

<p><a name="index-EOF_002c-explanation-215"></a>The special rule <code>&lt;&lt;EOF&gt;&gt;</code> indicates
actions which are to be taken when an end-of-file is
encountered and <code>yywrap()</code> returns non-zero (i.e., indicates
no further files to process).  The action must finish
by doing one of the following things:

     <ul>
<li><a name="index-YY_005fNEW_005fFILE--_0028now-obsolete_0029-216"></a>assigning <samp><span class="file">yyin</span></samp> to a new input file (in previous versions of
<code>flex</code>, after doing the assignment you had to call the special
action <code>YY_NEW_FILE</code>.  This is no longer necessary.)

     <li>executing a <code>return</code> statement;

     <li>executing the special <code>yyterminate()</code> action.

     <li>or, switching to a new buffer using <code>yy_switch_to_buffer()</code> as
shown in the example above. 
</ul>

   <p>&lt;&lt;EOF&gt;&gt; rules may not be used with other patterns; they may only be
qualified with a list of start conditions.  If an unqualified &lt;&lt;EOF&gt;&gt;
rule is given, it applies to <em>all</em> start conditions which do not
already have &lt;&lt;EOF&gt;&gt; actions.  To specify an &lt;&lt;EOF&gt;&gt; rule for only the
initial start condition, use:

<pre class="example"><pre class="verbatim">     
         &lt;INITIAL>&lt;&lt;EOF>>
</pre>
</pre>
   <p>These rules are useful for catching things like unclosed comments.  An
example:

   <p><a name="index-g_t_003c_003cEOF_003e_003e_002c-use-of-217"></a>
<pre class="example"><pre class="verbatim">     
         %x quote
         %%
     
         ...other rules for dealing with quotes...
     
         &lt;quote>&lt;&lt;EOF>>   {
                  error( "unterminated quote" );
                  yyterminate();
                  }
        &lt;&lt;EOF>>  {
                  if ( *++filelist )
                      yyin = fopen( *filelist, "r" );
                  else
                     yyterminate();
                  }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Misc-Macros"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#User-Values">User Values</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#EOF">EOF</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">13 Miscellaneous Macros</h2>

<p><a name="index-YY_005fUSER_005fACTION-218"></a>The macro <code>YY_USER_ACTION</code> can be defined to provide an action
which is always executed prior to the matched rule's action.  For
example, it could be #define'd to call a routine to convert yytext to
lower-case.  When <code>YY_USER_ACTION</code> is invoked, the variable
<code>yy_act</code> gives the number of the matched rule (rules are numbered
starting with 1).  Suppose you want to profile how often each of your
rules is matched.  The following would do the trick:

   <p><a name="index-YY_005fUSER_005fACTION-to-track-each-time-a-rule-is-matched-219"></a>
<pre class="example"><pre class="verbatim">     
         #define YY_USER_ACTION ++ctr[yy_act]
</pre>
</pre>
   <p><a name="index-YY_005fNUM_005fRULES-220"></a>where <code>ctr</code> is an array to hold the counts for the different rules. 
Note that the macro <code>YY_NUM_RULES</code> gives the total number of rules
(including the default rule), even if you use `<samp><span class="samp">-s)</span></samp>', so a correct
declaration for <code>ctr</code> is:

<pre class="example"><pre class="verbatim">     
         int ctr[YY_NUM_RULES];
</pre>
</pre>
   <p><a name="index-YY_005fUSER_005fINIT-221"></a>The macro <code>YY_USER_INIT</code> may be defined to provide an action which
is always executed before the first scan (and before the scanner's
internal initializations are done).  For example, it could be used to
call a routine to read in a data table or open a logging file.

   <p><a name="index-yy_005fset_005finteractive-222"></a>The macro <code>yy_set_interactive(is_interactive)</code> can be used to
control whether the current buffer is considered <dfn>interactive</dfn>.  An
interactive buffer is processed more slowly, but must be used when the
scanner's input source is indeed interactive to avoid problems due to
waiting to fill buffers (see the discussion of the `<samp><span class="samp">-I</span></samp>' flag in
<a href="#Scanner-Options">Scanner Options</a>).  A non-zero value in the macro invocation marks
the buffer as interactive, a zero value as non-interactive.  Note that
use of this macro overrides <code>%option always-interactive</code> or
<code>%option never-interactive</code> (see <a href="#Scanner-Options">Scanner Options</a>). 
<code>yy_set_interactive()</code> must be invoked prior to beginning to scan
the buffer that is (or is not) to be considered interactive.

   <p><a name="index-BOL_002c-setting-it-223"></a><a name="index-yy_005fset_005fbol-224"></a>The macro <code>yy_set_bol(at_bol)</code> can be used to control whether the
current buffer's scanning context for the next token match is done as
though at the beginning of a line.  A non-zero macro argument makes
rules anchored with `<samp><span class="samp">^</span></samp>' active, while a zero argument makes
`<samp><span class="samp">^</span></samp>' rules inactive.

   <p><a name="index-BOL_002c-checking-the-BOL-flag-225"></a><a name="index-YY_005fAT_005fBOL-226"></a>The macro <code>YY_AT_BOL()</code> returns true if the next token scanned from
the current buffer will have `<samp><span class="samp">^</span></samp>' rules active, false otherwise.

   <p><a name="index-actions_002c-redefining-YY_005fBREAK-227"></a><a name="index-YY_005fBREAK-228"></a>In the generated scanner, the actions are all gathered in one large
switch statement and separated using <code>YY_BREAK</code>, which may be
redefined.  By default, it is simply a <code>break</code>, to separate each
rule's action from the following rule's.  Redefining <code>YY_BREAK</code>
allows, for example, C++ users to #define YY_BREAK to do nothing (while
being very careful that every rule ends with a <code>break</code>" or a
<code>return</code>!) to avoid suffering from unreachable statement warnings
where because a rule's action ends with <code>return</code>, the
<code>YY_BREAK</code> is inaccessible.

<div class="node">
<p><hr>
<a name="User-Values"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Yacc">Yacc</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Misc-Macros">Misc Macros</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">14 Values Available To the User</h2>

<p>This chapter summarizes the various values available to the user in the
rule actions.

     
<a name="index-yytext-229"></a>
<dl><dt><code>char *yytext</code><dd>holds the text of the current token.  It may be modified but not
lengthened (you cannot append characters to the end).

     <p><a name="index-yytext_002c-default-array-size-230"></a><a name="index-array_002c-default-size-for-yytext-231"></a><a name="index-YYLMAX-232"></a>If the special directive <code>%array</code> appears in the first section of
the scanner description, then <code>yytext</code> is instead declared
<code>char yytext[YYLMAX]</code>, where <code>YYLMAX</code> is a macro definition
that you can redefine in the first section if you don't like the default
value (generally 8KB).  Using <code>%array</code> results in somewhat slower
scanners, but the value of <code>yytext</code> becomes immune to calls to
<code>unput()</code>, which potentially destroy its value when <code>yytext</code> is
a character pointer.  The opposite of <code>%array</code> is <code>%pointer</code>,
which is the default.

     <p><a name="index-C_002b_002b-and-_0025array-233"></a>You cannot use <code>%array</code> when generating C++ scanner classes (the
`<samp><span class="samp">-+</span></samp>' flag).

     <p><a name="index-yyleng-234"></a><br><dt><code>int yyleng</code><dd>holds the length of the current token.

     <p><a name="index-yyin-235"></a><br><dt><code>FILE *yyin</code><dd>is the file which by default <code>flex</code> reads from.  It may be
redefined but doing so only makes sense before scanning begins or after
an EOF has been encountered.  Changing it in the midst of scanning will
have unexpected results since <code>flex</code> buffers its input; use
<code>yyrestart()</code> instead.  Once scanning terminates because an
end-of-file has been seen, you can assign <samp><span class="file">yyin</span></samp> at the new input
file and then call the scanner again to continue scanning.

     <p><a name="index-yyrestart-236"></a><br><dt><code>void yyrestart( FILE *new_file )</code><dd>may be called to point <samp><span class="file">yyin</span></samp> at the new input file.  The
switch-over to the new file is immediate (any previously buffered-up
input is lost).  Note that calling <code>yyrestart()</code> with <samp><span class="file">yyin</span></samp>
as an argument thus throws away the current input buffer and continues
scanning the same input file.

     <p><a name="index-yyout-237"></a><br><dt><code>FILE *yyout</code><dd>is the file to which <code>ECHO</code> actions are done.  It can be reassigned
by the user.

     <p><a name="index-YY_005fCURRENT_005fBUFFER-238"></a><br><dt><code>YY_CURRENT_BUFFER</code><dd>returns a <code>YY_BUFFER_STATE</code> handle to the current buffer.

     <p><a name="index-YY_005fSTART-239"></a><br><dt><code>YY_START</code><dd>returns an integer value corresponding to the current start condition. 
You can subsequently use this value with <code>BEGIN</code> to return to that
start condition. 
</dl>

<div class="node">
<p><hr>
<a name="Yacc"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Scanner-Options">Scanner Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#User-Values">User Values</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">15 Interfacing with Yacc</h2>

<p><a name="index-yacc_002c-interface-240"></a>
<a name="index-yylval_002c-with-yacc-241"></a>One of the main uses of <code>flex</code> is as a companion to the <code>yacc</code>
parser-generator.  <code>yacc</code> parsers expect to call a routine named
<code>yylex()</code> to find the next input token.  The routine is supposed to
return the type of the next token as well as putting any associated
value in the global <code>yylval</code>.  To use <code>flex</code> with <code>yacc</code>,
one specifies the `<samp><span class="samp">-d</span></samp>' option to <code>yacc</code> to instruct it to
generate the file <samp><span class="file">y.tab.h</span></samp> containing definitions of all the
<code>%tokens</code> appearing in the <code>yacc</code> input.  This file is then
included in the <code>flex</code> scanner.  For example, if one of the tokens
is <code>TOK_NUMBER</code>, part of the scanner might look like:

   <p><a name="index-yacc-interface-242"></a>
<pre class="example"><pre class="verbatim">     
         %{
         #include "y.tab.h"
         %}
     
         %%
     
         [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Scanner-Options"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Performance">Performance</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Yacc">Yacc</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">16 Scanner Options</h2>

<p><a name="index-command_002dline-options-243"></a><a name="index-options_002c-command_002dline-244"></a><a name="index-arguments_002c-command_002dline-245"></a>
The various <code>flex</code> options are categorized by function in the following
menu. If you want to lookup a particular option by name, See <a href="#Index-of-Scanner-Options">Index of Scanner Options</a>.

<ul class="menu">
<li><a accesskey="1" href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a>
<li><a accesskey="2" href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a>
<li><a accesskey="3" href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a>
<li><a accesskey="4" href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a>
<li><a accesskey="5" href="#Debugging-Options">Debugging Options</a>
<li><a accesskey="6" href="#Miscellaneous-Options">Miscellaneous Options</a>
</ul>

   <p>Even though there are many scanner options, a typical scanner might only
specify the following options:

<pre class="example"><pre class="verbatim">     
     %option   8bit reentrant bison-bridge
     %option   warn nodefault
     %option   yylineno
     %option   outfile="scanner.c" header-file="scanner.h"
</pre>
</pre>
   <p>The first line specifies the general type of scanner we want. The second line
specifies that we are being careful. The third line asks flex to track line
numbers. The last line tells flex what to name the files. (The options can be
specified in any order. We just dividied them.)

   <p><code>flex</code> also provides a mechanism for controlling options within the
scanner specification itself, rather than from the flex command-line. 
This is done by including <code>%option</code> directives in the first section
of the scanner specification.  You can specify multiple options with a
single <code>%option</code> directive, and multiple directives in the first
section of your flex input file.

   <p>Most options are given simply as names, optionally preceded by the
word `<samp><span class="samp">no</span></samp>' (with no intervening whitespace) to negate their meaning. 
The names are the same as their long-option equivalents (but without the
leading `<samp><span class="samp">--</span></samp>' ).

   <p><code>flex</code> scans your rule actions to determine whether you use the
<code>REJECT</code> or <code>yymore()</code> features.  The <code>REJECT</code> and
<code>yymore</code> options are available to override its decision as to
whether you use the options, either by setting them (e.g., <code>%option
reject)</code> to indicate the feature is indeed used, or unsetting them to
indicate it actually is not used (e.g., <code>%option noyymore)</code>.

   <p>A number of options are available for lint purists who want to suppress
the appearance of unneeded routines in the generated scanner.  Each of
the following, if unset (e.g., <code>%option nounput</code>), results in the
corresponding routine not appearing in the generated scanner:

<pre class="example"><pre class="verbatim">     
         input, unput
         yy_push_state, yy_pop_state, yy_top_state
         yy_scan_buffer, yy_scan_bytes, yy_scan_string
     
         yyget_extra, yyset_extra, yyget_leng, yyget_text,
         yyget_lineno, yyset_lineno, yyget_in, yyset_in,
         yyget_out, yyset_out, yyget_lval, yyset_lval,
         yyget_lloc, yyset_lloc, yyget_debug, yyset_debug
</pre>
</pre>
   <p>(though <code>yy_push_state()</code> and friends won't appear anyway unless
you use <code>%option stack)</code>.

<div class="node">
<p><hr>
<a name="Options-for-Specifing-Filenames"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Scanner-Options">Scanner Options</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.1 Options for Specifing Filenames</h3>

     <dl>
<a name="option_002dheader"></a>
<a name="index-g_t_002d_002d_002dheader_002dfile-246"></a><a name="index-header_002dfile-247"></a><dt>`<samp><span class="samp">--header-file=FILE, </span><code>%option header-file="FILE"</code></samp>'<dd>instructs flex to write a C header to <samp><span class="file">FILE</span></samp>. This file contains
function prototypes, extern variables, and types used by the scanner. 
Only the external API is exported by the header file. Many macros that
are usable from within scanner actions are not exported to the header
file. This is due to namespace problems and the goal of a clean
external API.

     <p>While in the header, the macro <code>yyIN_HEADER</code> is defined, where `<samp><span class="samp">yy</span></samp>'
is substituted with the appropriate prefix.

     <p>The `<samp><span class="samp">--header-file</span></samp>' option is not compatible with the `<samp><span class="samp">--c++</span></samp>' option,
since the C++ scanner provides its own header in <samp><span class="file">yyFlexLexer.h</span></samp>.

     <p><a name="option_002doutfile"></a>
<a name="index-g_t_002do-248"></a><a name="index-g_t_002d_002d_002doutfile-249"></a><a name="index-outfile-250"></a><br><dt>`<samp><span class="samp">-oFILE, --outfile=FILE, </span><code>%option outfile="FILE"</code></samp>'<dd>directs flex to write the scanner to the file <samp><span class="file">FILE</span></samp> instead of
<samp><span class="file">lex.yy.c</span></samp>.  If you combine `<samp><span class="samp">--outfile</span></samp>' with the `<samp><span class="samp">--stdout</span></samp>' option,
then the scanner is written to <samp><span class="file">stdout</span></samp> but its <code>#line</code>
directives (see the `<samp><span class="samp">-l</span></samp>' option above) refer to the file
<samp><span class="file">FILE</span></samp>.

     <p><a name="option_002dstdout"></a>
<a name="index-g_t_002dt-251"></a><a name="index-g_t_002d_002d_002dstdout-252"></a><a name="index-stdout-253"></a><br><dt>`<samp><span class="samp">-t, --stdout, </span><code>%option stdout</code></samp>'<dd>instructs <code>flex</code> to write the scanner it generates to standard
output instead of <samp><span class="file">lex.yy.c</span></samp>.

     <p><a name="index-g_t_002d_002d_002dskel-254"></a><br><dt>`<samp><span class="samp">-SFILE, --skel=FILE</span></samp>'<dd>overrides the default skeleton file from which
<code>flex</code>
constructs its scanners.  You'll never need this option unless you are doing
<code>flex</code>
maintenance or development.

     <p><a name="index-g_t_002d_002d_002dtables_002dfile-255"></a><a name="index-tables_002dfile-256"></a><br><dt>`<samp><span class="samp">--tables-file=FILE</span></samp>'<dd>Write serialized scanner dfa tables to FILE. The generated scanner will not
contain the tables, and requires them to be loaded at runtime. 
See <a href="#serialization">serialization</a>.

     <p><a name="index-g_t_002d_002d_002dtables_002dverify-257"></a><a name="index-tables_002dverify-258"></a><br><dt>`<samp><span class="samp">--tables-verify</span></samp>'<dd>This option is for flex development. We document it here in case you stumble
upon it by accident or in case you suspect some inconsistency in the serialized
tables.  Flex will serialize the scanner dfa tables but will also generate the
in-code tables as it normally does. At runtime, the scanner will verify that
the serialized tables match the in-code tables, instead of loading them.

</dl>

<div class="node">
<p><hr>
<a name="Options-Affecting-Scanner-Behavior"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.2 Options Affecting Scanner Behavior</h3>

     <dl>
<a name="option_002dcase_002dinsensitive"></a>
<a name="index-g_t_002di-259"></a><a name="index-g_t_002d_002d_002dcase_002dinsensitive-260"></a><a name="index-case_002dinsensitive-261"></a><dt>`<samp><span class="samp">-i, --case-insensitive, </span><code>%option case-insensitive</code></samp>'<dd>instructs <code>flex</code> to generate a <dfn>case-insensitive</dfn> scanner.  The
case of letters given in the <code>flex</code> input patterns will be ignored,
and tokens in the input will be matched regardless of case.  The matched
text given in <code>yytext</code> will have the preserved case (i.e., it will
not be folded).  For tricky behavior, see <a href="#case-and-character-ranges">case and character ranges</a>.

     <p><a name="option_002dlex_002dcompat"></a>
<a name="index-g_t_002dl-262"></a><a name="index-g_t_002d_002d_002dlex_002dcompat-263"></a><a name="index-lex_002dcompat-264"></a><br><dt>`<samp><span class="samp">-l, --lex-compat, </span><code>%option lex-compat</code></samp>'<dd>turns on maximum compatibility with the original AT&amp;T <code>lex</code>
implementation.  Note that this does not mean <em>full</em> compatibility. 
Use of this option costs a considerable amount of performance, and it
cannot be used with the `<samp><span class="samp">--c++</span></samp>', `<samp><span class="samp">--full</span></samp>', `<samp><span class="samp">--fast</span></samp>', `<samp><span class="samp">-Cf</span></samp>', or
`<samp><span class="samp">-CF</span></samp>' options.  For details on the compatibilities it provides, see
<a href="#Lex-and-Posix">Lex and Posix</a>.  This option also results in the name
<code>YY_FLEX_LEX_COMPAT</code> being <code>#define</code>'d in the generated scanner.

     <p><a name="option_002dbatch"></a>
<a name="index-g_t_002dB-265"></a><a name="index-g_t_002d_002d_002dbatch-266"></a><a name="index-batch-267"></a><br><dt>`<samp><span class="samp">-B, --batch, </span><code>%option batch</code></samp>'<dd>instructs <code>flex</code> to generate a <dfn>batch</dfn> scanner, the opposite of
<em>interactive</em> scanners generated by `<samp><span class="samp">--interactive</span></samp>' (see below).  In
general, you use `<samp><span class="samp">-B</span></samp>' when you are <em>certain</em> that your scanner
will never be used interactively, and you want to squeeze a
<em>little</em> more performance out of it.  If your goal is instead to
squeeze out a <em>lot</em> more performance, you should be using the
`<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' options, which turn on `<samp><span class="samp">--batch</span></samp>' automatically
anyway.

     <p><a name="option_002dinteractive"></a>
<a name="index-g_t_002dI-268"></a><a name="index-g_t_002d_002d_002dinteractive-269"></a><a name="index-interactive-270"></a><br><dt>`<samp><span class="samp">-I, --interactive, </span><code>%option interactive</code></samp>'<dd>instructs <code>flex</code> to generate an <i>interactive</i> scanner.  An
interactive scanner is one that only looks ahead to decide what token
has been matched if it absolutely must.  It turns out that always
looking one extra character ahead, even if the scanner has already seen
enough text to disambiguate the current token, is a bit faster than only
looking ahead when necessary.  But scanners that always look ahead give
dreadful interactive performance; for example, when a user types a
newline, it is not recognized as a newline token until they enter
<em>another</em> token, which often means typing in another whole line.

     <p><code>flex</code> scanners default to <code>interactive</code> unless you use the
`<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' table-compression options
(see <a href="#Performance">Performance</a>).  That's because if you're looking for
high-performance you should be using one of these options, so if you
didn't, <code>flex</code> assumes you'd rather trade off a bit of run-time
performance for intuitive interactive behavior.  Note also that you
<em>cannot</em> use `<samp><span class="samp">--interactive</span></samp>' in conjunction with `<samp><span class="samp">-Cf</span></samp>' or
`<samp><span class="samp">-CF</span></samp>'.  Thus, this option is not really needed; it is on by default
for all those cases in which it is allowed.

     <p>You can force a scanner to
<em>not</em>
be interactive by using
`<samp><span class="samp">--batch</span></samp>'

     <p><a name="option_002d7bit"></a>
<a name="index-g_t_002d7-271"></a><a name="index-g_t_002d_002d_002d7bit-272"></a><a name="index-g_t7bit-273"></a><br><dt>`<samp><span class="samp">-7, --7bit, </span><code>%option 7bit</code></samp>'<dd>instructs <code>flex</code> to generate a 7-bit scanner, i.e., one which can
only recognize 7-bit characters in its input.  The advantage of using
`<samp><span class="samp">--7bit</span></samp>' is that the scanner's tables can be up to half the size of
those generated using the `<samp><span class="samp">--8bit</span></samp>'.  The disadvantage is that such
scanners often hang or crash if their input contains an 8-bit character.

     <p>Note, however, that unless you generate your scanner using the
`<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' table compression options, use of `<samp><span class="samp">--7bit</span></samp>'
will save only a small amount of table space, and make your scanner
considerably less portable.  <code>Flex</code>'s default behavior is to
generate an 8-bit scanner unless you use the `<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>',
in which case <code>flex</code> defaults to generating 7-bit scanners unless
your site was always configured to generate 8-bit scanners (as will
often be the case with non-USA sites).  You can tell whether flex
generated a 7-bit or an 8-bit scanner by inspecting the flag summary in
the `<samp><span class="samp">--verbose</span></samp>' output as described above.

     <p>Note that if you use `<samp><span class="samp">-Cfe</span></samp>' or `<samp><span class="samp">-CFe</span></samp>' <code>flex</code> still
defaults to generating an 8-bit scanner, since usually with these
compression options full 8-bit tables are not much more expensive than
7-bit tables.

     <p><a name="option_002d8bit"></a>
<a name="index-g_t_002d8-274"></a><a name="index-g_t_002d_002d_002d8bit-275"></a><a name="index-g_t8bit-276"></a><br><dt>`<samp><span class="samp">-8, --8bit, </span><code>%option 8bit</code></samp>'<dd>instructs <code>flex</code> to generate an 8-bit scanner, i.e., one which can
recognize 8-bit characters.  This flag is only needed for scanners
generated using `<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>', as otherwise flex defaults to
generating an 8-bit scanner anyway.

     <p>See the discussion of
`<samp><span class="samp">--7bit</span></samp>'
above for <code>flex</code>'s default behavior and the tradeoffs between 7-bit
and 8-bit scanners.

     <p><a name="option_002ddefault"></a>
<a name="index-g_t_002d_002d_002ddefault-277"></a><a name="index-default-278"></a><br><dt>`<samp><span class="samp">--default, </span><code>%option default</code></samp>'<dd>generate the default rule.

     <p><a name="option_002dalways_002dinteractive"></a>
<a name="index-g_t_002d_002d_002dalways_002dinteractive-279"></a><a name="index-always_002dinteractive-280"></a><br><dt>`<samp><span class="samp">--always-interactive, </span><code>%option always-interactive</code></samp>'<dd>instructs flex to generate a scanner which always considers its input
<em>interactive</em>.  Normally, on each new input file the scanner calls
<code>isatty()</code> in an attempt to determine whether the scanner's input
source is interactive and thus should be read a character at a time. 
When this option is used, however, then no such call is made.

     <p><a name="index-g_t_002d_002d_002dnever_002dinteractive-281"></a><br><dt>`<samp><span class="samp">--never-interactive, </span><code>--never-interactive</code></samp>'<dd>instructs flex to generate a scanner which never considers its input
interactive.  This is the opposite of <code>always-interactive</code>.

     <p><a name="option_002dposix"></a>
<a name="index-g_t_002dX-282"></a><a name="index-g_t_002d_002d_002dposix-283"></a><a name="index-posix-284"></a><br><dt>`<samp><span class="samp">-X, --posix, </span><code>%option posix</code></samp>'<dd>turns on maximum compatibility with the POSIX 1003.2-1992 definition of
<code>lex</code>.  Since <code>flex</code> was originally designed to implement the
POSIX definition of <code>lex</code> this generally involves very few changes
in behavior.  At the current writing the known differences between
<code>flex</code> and the POSIX standard are:

          <ul>
<li>In POSIX and AT&amp;T <code>lex</code>, the repeat operator, `<samp><span class="samp">{}</span></samp>', has lower
precedence than concatenation (thus `<samp><span class="samp">ab{3}</span></samp>' yields `<samp><span class="samp">ababab</span></samp>'). 
Most POSIX utilities use an Extended Regular Expression (ERE) precedence
that has the precedence of the repeat operator higher than concatenation
(which causes `<samp><span class="samp">ab{3}</span></samp>' to yield `<samp><span class="samp">abbb</span></samp>').  By default, <code>flex</code>
places the precedence of the repeat operator higher than concatenation
which matches the ERE processing of other POSIX utilities.  When either
`<samp><span class="samp">--posix</span></samp>' or `<samp><span class="samp">-l</span></samp>' are specified, <code>flex</code> will use the
traditional AT&amp;T and POSIX-compliant precedence for the repeat operator
where concatenation has higher precedence than the repeat operator. 
</ul>

     <p><a name="option_002dstack"></a>
<a name="index-g_t_002d_002d_002dstack-285"></a><a name="index-stack-286"></a><br><dt>`<samp><span class="samp">--stack, </span><code>%option stack</code></samp>'<dd>enables the use of
start condition stacks (see <a href="#Start-Conditions">Start Conditions</a>).

     <p><a name="option_002dstdinit"></a>
<a name="index-g_t_002d_002d_002dstdinit-287"></a><a name="index-stdinit-288"></a><br><dt>`<samp><span class="samp">--stdinit, </span><code>%option stdinit</code></samp>'<dd>if set (i.e., <b>%option stdinit)</b> initializes <code>yyin</code> and
<code>yyout</code> to <samp><span class="file">stdin</span></samp> and <samp><span class="file">stdout</span></samp>, instead of the default of
<samp><span class="file">NULL</span></samp>.  Some existing <code>lex</code> programs depend on this behavior,
even though it is not compliant with ANSI C, which does not require
<samp><span class="file">stdin</span></samp> and <samp><span class="file">stdout</span></samp> to be compile-time constant. In a
reentrant scanner, however, this is not a problem since initialization
is performed in <code>yylex_init</code> at runtime.

     <p><a name="option_002dyylineno"></a>
<a name="index-g_t_002d_002d_002dyylineno-289"></a><a name="index-yylineno-290"></a><br><dt>`<samp><span class="samp">--yylineno, </span><code>%option yylineno</code></samp>'<dd>directs <code>flex</code> to generate a scanner
that maintains the number of the current line read from its input in the
global variable <code>yylineno</code>.  This option is implied by <code>%option
lex-compat</code>.  In a reentrant C scanner, the macro <code>yylineno</code> is
accessible regardless of the value of <code>%option yylineno</code>, however, its
value is not modified by <code>flex</code> unless <code>%option yylineno</code> is enabled.

     <p><a name="option_002dyywrap"></a>
<a name="index-g_t_002d_002d_002dyywrap-291"></a><a name="index-yywrap-292"></a><br><dt>`<samp><span class="samp">--yywrap, </span><code>%option yywrap</code></samp>'<dd>if unset (i.e., <code>--noyywrap)</code>, makes the scanner not call
<code>yywrap()</code> upon an end-of-file, but simply assume that there are no
more files to scan (until the user points <samp><span class="file">yyin</span></samp> at a new file and
calls <code>yylex()</code> again).

</dl>

<div class="node">
<p><hr>
<a name="Code-Level-And-API-Options"></a>
<a name="Code_002dLevel-And-API-Options"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.3 Code-Level And API Options</h3>

     <dl>
<a name="option_002dansi_002ddefinitions"></a>
<a name="index-g_t_002d_002d_002doption_002dansi_002ddefinitions-293"></a><a name="index-ansi_002ddefinitions-294"></a><dt>`<samp><span class="samp">--ansi-definitions, </span><code>%option ansi-definitions</code></samp>'<dd>instruct flex to generate ANSI C99 definitions for functions. 
This option is enabled by default. 
If <code>%option noansi-definitions</code> is specified, then the obsolete style
is generated.

     <p><a name="option_002dansi_002dprototypes"></a>
<a name="index-g_t_002d_002d_002doption_002dansi_002dprototypes-295"></a><a name="index-ansi_002dprototypes-296"></a><br><dt>`<samp><span class="samp">--ansi-prototypes, </span><code>%option ansi-prototypes</code></samp>'<dd>instructs flex to generate ANSI C99 prototypes for functions. 
This option is enabled by default. 
If <code>noansi-prototypes</code> is specified, then
prototypes will have empty parameter lists.

     <p><a name="option_002dbison_002dbridge"></a>
<a name="index-g_t_002d_002d_002dbison_002dbridge-297"></a><a name="index-bison_002dbridge-298"></a><br><dt>`<samp><span class="samp">--bison-bridge, </span><code>%option bison-bridge</code></samp>'<dd>instructs flex to generate a C scanner that is
meant to be called by a
<code>GNU bison</code>
parser. The scanner has minor API changes for
<code>bison</code>
compatibility. In particular, the declaration of
<code>yylex</code>
is modified to take an additional parameter,
<code>yylval</code>. 
See <a href="#Bison-Bridge">Bison Bridge</a>.

     <p><a name="option_002dbison_002dlocations"></a>
<a name="index-g_t_002d_002d_002dbison_002dlocations-299"></a><a name="index-bison_002dlocations-300"></a><br><dt>`<samp><span class="samp">--bison-locations, </span><code>%option bison-locations</code></samp>'<dd>instruct flex that
<code>GNU bison</code> <code>%locations</code> are being used. 
This means <code>yylex</code> will be passed
an additional parameter, <code>yylloc</code>. This option
implies <code>%option bison-bridge</code>. 
See <a href="#Bison-Bridge">Bison Bridge</a>.

     <p><a name="option_002dnoline"></a>
<a name="index-g_t_002dL-301"></a><a name="index-g_t_002d_002d_002dnoline-302"></a><a name="index-noline-303"></a><br><dt>`<samp><span class="samp">-L, --noline, </span><code>%option noline</code></samp>'<dd>instructs
<code>flex</code>
not to generate
<code>#line</code>
directives.  Without this option,
<code>flex</code>
peppers the generated scanner
with <code>#line</code> directives so error messages in the actions will be correctly
located with respect to either the original
<code>flex</code>
input file (if the errors are due to code in the input file), or
<samp><span class="file">lex.yy.c</span></samp>
(if the errors are
<code>flex</code>'s
fault &ndash; you should report these sorts of errors to the email address
given in <a href="#Reporting-Bugs">Reporting Bugs</a>).

     <p><a name="option_002dreentrant"></a>
<a name="index-g_t_002dR-304"></a><a name="index-g_t_002d_002d_002dreentrant-305"></a><a name="index-reentrant-306"></a><br><dt>`<samp><span class="samp">-R, --reentrant, </span><code>%option reentrant</code></samp>'<dd>instructs flex to generate a reentrant C scanner.  The generated scanner
may safely be used in a multi-threaded environment. The API for a
reentrant scanner is different than for a non-reentrant scanner
see <a href="#Reentrant">Reentrant</a>).  Because of the API difference between
reentrant and non-reentrant <code>flex</code> scanners, non-reentrant flex
code must be modified before it is suitable for use with this option. 
This option is not compatible with the `<samp><span class="samp">--c++</span></samp>' option.

     <p>The option `<samp><span class="samp">--reentrant</span></samp>' does not affect the performance of
the scanner.

     <p><a name="option_002dc_002b_002b"></a>
<a name="index-g_t_002d_002b-307"></a><a name="index-g_t_002d_002d_002dc_002b_002b-308"></a><a name="index-c_002b_002b-309"></a><br><dt>`<samp><span class="samp">-+, --c++, </span><code>%option c++</code></samp>'<dd>specifies that you want flex to generate a C++
scanner class.  See <a href="#Cxx">Cxx</a>, for
details.

     <p><a name="option_002darray"></a>
<a name="index-g_t_002d_002d_002darray-310"></a><a name="index-array-311"></a><br><dt>`<samp><span class="samp">--array, </span><code>%option array</code></samp>'<dd>specifies that you want yytext to be an array instead of a char*

     <p><a name="option_002dpointer"></a>
<a name="index-g_t_002d_002d_002dpointer-312"></a><a name="index-pointer-313"></a><br><dt>`<samp><span class="samp">--pointer, </span><code>%option pointer</code></samp>'<dd>specify that  <code>yytext</code> should be a <code>char *</code>, not an array. 
This default is <code>char *</code>.

     <p><a name="option_002dprefix"></a>
<a name="index-g_t_002dP-314"></a><a name="index-g_t_002d_002d_002dprefix-315"></a><a name="index-prefix-316"></a><br><dt>`<samp><span class="samp">-PPREFIX, --prefix=PREFIX, </span><code>%option prefix="PREFIX"</code></samp>'<dd>changes the default `<samp><span class="samp">yy</span></samp>' prefix used by <code>flex</code> for all
globally-visible variable and function names to instead be
`<samp><span class="samp">PREFIX</span></samp>'.  For example, `<samp><span class="samp">--prefix=foo</span></samp>' changes the name of
<code>yytext</code> to <code>footext</code>.  It also changes the name of the default
output file from <samp><span class="file">lex.yy.c</span></samp> to <samp><span class="file">lex.foo.c</span></samp>.  Here is a partial
list of the names affected:

     <pre class="example">     <pre class="verbatim">          
              yy_create_buffer
              yy_delete_buffer
              yy_flex_debug
              yy_init_buffer
              yy_flush_buffer
              yy_load_buffer_state
              yy_switch_to_buffer
              yyin
              yyleng
              yylex
              yylineno
              yyout
              yyrestart
              yytext
              yywrap
              yyalloc
              yyrealloc
              yyfree
     </pre>
     </pre>
     <p>(If you are using a C++ scanner, then only <code>yywrap</code> and
<code>yyFlexLexer</code> are affected.)  Within your scanner itself, you can
still refer to the global variables and functions using either version
of their name; but externally, they have the modified name.

     <p>This option lets you easily link together multiple
<code>flex</code>
programs into the same executable.  Note, though, that using this
option also renames
<code>yywrap()</code>,
so you now
<em>must</em>
either
provide your own (appropriately-named) version of the routine for your
scanner, or use
<code>%option noyywrap</code>,
as linking with
`<samp><span class="samp">-lfl</span></samp>'
no longer provides one for you by default.

     <p><a name="option_002dmain"></a>
<a name="index-g_t_002d_002d_002dmain-317"></a><a name="index-main-318"></a><br><dt>`<samp><span class="samp">--main, </span><code>%option main</code></samp>'<dd> directs flex to provide a default <code>main()</code> program for the
scanner, which simply calls <code>yylex()</code>.  This option implies
<code>noyywrap</code> (see below).

     <p><a name="option_002dnounistd"></a>
<a name="index-g_t_002d_002d_002dnounistd-319"></a><a name="index-nounistd-320"></a><br><dt>`<samp><span class="samp">--nounistd, </span><code>%option nounistd</code></samp>'<dd>suppresses inclusion of the non-ANSI header file <samp><span class="file">unistd.h</span></samp>. This option
is meant to target environments in which <samp><span class="file">unistd.h</span></samp> does not exist. Be aware
that certain options may cause flex to generate code that relies on functions
normally found in <samp><span class="file">unistd.h</span></samp>, (e.g. <code>isatty()</code>, <code>read()</code>.) 
If you wish to use these functions, you will have to inform your compiler where
to find them. 
See <a href="#option_002dalways_002dinteractive">option-always-interactive</a>. See <a href="#option_002dread">option-read</a>.

     <p><a name="option_002dyyclass"></a>
<a name="index-g_t_002d_002d_002dyyclass-321"></a><a name="index-yyclass-322"></a><br><dt>`<samp><span class="samp">--yyclass, </span><code>%option yyclass="NAME"</code></samp>'<dd>only applies when generating a C++ scanner (the `<samp><span class="samp">--c++</span></samp>' option).  It
informs <code>flex</code> that you have derived <code>foo</code> as a subclass of
<code>yyFlexLexer</code>, so <code>flex</code> will place your actions in the member
function <code>foo::yylex()</code> instead of <code>yyFlexLexer::yylex()</code>.  It
also generates a <code>yyFlexLexer::yylex()</code> member function that emits
a run-time error (by invoking <code>yyFlexLexer::LexerError())</code> if
called.  See <a href="#Cxx">Cxx</a>.

</dl>

<div class="node">
<p><hr>
<a name="Options-for-Scanner-Speed-and-Size"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Debugging-Options">Debugging Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.4 Options for Scanner Speed and Size</h3>

     <dl>
<dt>`<samp><span class="samp">-C[aefFmr]</span></samp>'<dd>controls the degree of table compression and, more generally, trade-offs
between small scanners and fast scanners.

          
<a name="index-g_t_002dC-323"></a>
<dl><dt>`<samp><span class="samp">-C</span></samp>'<dd>A lone `<samp><span class="samp">-C</span></samp>' specifies that the scanner tables should be compressed
but neither equivalence classes nor meta-equivalence classes should be
used.

          <p><a name="option_002dalign"></a>
<a name="index-g_t_002dCa-324"></a><a name="index-g_t_002d_002d_002dalign-325"></a><a name="index-align-326"></a><br><dt>`<samp><span class="samp">-Ca, --align, </span><code>%option align</code></samp>'<dd>(&ldquo;align&rdquo;) instructs flex to trade off larger tables in the
generated scanner for faster performance because the elements of
the tables are better aligned for memory access and computation.  On some
RISC architectures, fetching and manipulating longwords is more efficient
than with smaller-sized units such as shortwords.  This option can
quadruple the size of the tables used by your scanner.

          <p><a name="option_002decs"></a>
<a name="index-g_t_002dCe-327"></a><a name="index-g_t_002d_002d_002decs-328"></a><a name="index-ecs-329"></a><br><dt>`<samp><span class="samp">-Ce, --ecs, </span><code>%option ecs</code></samp>'<dd>directs <code>flex</code> to construct <dfn>equivalence classes</dfn>, i.e., sets
of characters which have identical lexical properties (for example, if
the only appearance of digits in the <code>flex</code> input is in the
character class &ldquo;[0-9]&rdquo; then the digits '0', '1', ..., '9' will all be
put in the same equivalence class).  Equivalence classes usually give
dramatic reductions in the final table/object file sizes (typically a
factor of 2-5) and are pretty cheap performance-wise (one array look-up
per character scanned).

          <p><a name="index-g_t_002dCf-330"></a><br><dt>`<samp><span class="samp">-Cf</span></samp>'<dd>specifies that the <dfn>full</dfn> scanner tables should be generated -
<code>flex</code> should not compress the tables by taking advantages of
similar transition functions for different states.

          <p><a name="index-g_t_002dCF-331"></a><br><dt>`<samp><span class="samp">-CF</span></samp>'<dd>specifies that the alternate fast scanner representation (described
above under the `<samp><span class="samp">--fast</span></samp>' flag) should be used.  This option cannot be
used with `<samp><span class="samp">--c++</span></samp>'.

          <p><a name="option_002dmeta_002decs"></a>
<a name="index-g_t_002dCm-332"></a><a name="index-g_t_002d_002d_002dmeta_002decs-333"></a><a name="index-meta_002decs-334"></a><br><dt>`<samp><span class="samp">-Cm, --meta-ecs, </span><code>%option meta-ecs</code></samp>'<dd>directs
<code>flex</code>
to construct
<dfn>meta-equivalence classes</dfn>,
which are sets of equivalence classes (or characters, if equivalence
classes are not being used) that are commonly used together.  Meta-equivalence
classes are often a big win when using compressed tables, but they
have a moderate performance impact (one or two <code>if</code> tests and one
array look-up per character scanned).

          <p><a name="option_002dread"></a>
<a name="index-g_t_002dCr-335"></a><a name="index-g_t_002d_002d_002dread-336"></a><a name="index-read-337"></a><br><dt>`<samp><span class="samp">-Cr, --read, </span><code>%option read</code></samp>'<dd>causes the generated scanner to <em>bypass</em> use of the standard I/O
library (<code>stdio</code>) for input.  Instead of calling <code>fread()</code> or
<code>getc()</code>, the scanner will use the <code>read()</code> system call,
resulting in a performance gain which varies from system to system, but
in general is probably negligible unless you are also using `<samp><span class="samp">-Cf</span></samp>'
or `<samp><span class="samp">-CF</span></samp>'.  Using `<samp><span class="samp">-Cr</span></samp>' can cause strange behavior if, for
example, you read from <samp><span class="file">yyin</span></samp> using <code>stdio</code> prior to calling
the scanner (because the scanner will miss whatever text your previous
reads left in the <code>stdio</code> input buffer).  `<samp><span class="samp">-Cr</span></samp>' has no effect
if you define <code>YY_INPUT()</code> (see <a href="#Generated-Scanner">Generated Scanner</a>). 
</dl>

     <p>The options `<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' and `<samp><span class="samp">-Cm</span></samp>' do not make sense
together - there is no opportunity for meta-equivalence classes if the
table is not being compressed.  Otherwise the options may be freely
mixed, and are cumulative.

     <p>The default setting is `<samp><span class="samp">-Cem</span></samp>', which specifies that <code>flex</code>
should generate equivalence classes and meta-equivalence classes.  This
setting provides the highest degree of table compression.  You can trade
off faster-executing scanners at the cost of larger tables with the
following generally being true:

     <pre class="example">     <pre class="verbatim">          
              slowest &amp; smallest
                    -Cem
                    -Cm
                    -Ce
                    -C
                    -C{f,F}e
                    -C{f,F}
                    -C{f,F}a
              fastest &amp; largest
     </pre>
     </pre>
     <p>Note that scanners with the smallest tables are usually generated and
compiled the quickest, so during development you will usually want to
use the default, maximal compression.

     <p>`<samp><span class="samp">-Cfe</span></samp>' is often a good compromise between speed and size for
production scanners.

     <p><a name="option_002dfull"></a>
<a name="index-g_t_002df-338"></a><a name="index-g_t_002d_002d_002dfull-339"></a><a name="index-full-340"></a><br><dt>`<samp><span class="samp">-f, --full, </span><code>%option full</code></samp>'<dd>specifies
<dfn>fast scanner</dfn>. 
No table compression is done and <code>stdio</code> is bypassed. 
The result is large but fast.  This option is equivalent to
`<samp><span class="samp">--Cfr</span></samp>'

     <p><a name="option_002dfast"></a>
<a name="index-g_t_002dF-341"></a><a name="index-g_t_002d_002d_002dfast-342"></a><a name="index-fast-343"></a><br><dt>`<samp><span class="samp">-F, --fast, </span><code>%option fast</code></samp>'<dd>specifies that the <em>fast</em> scanner table representation should be
used (and <code>stdio</code> bypassed).  This representation is about as fast
as the full table representation `<samp><span class="samp">--full</span></samp>', and for some sets of
patterns will be considerably smaller (and for others, larger).  In
general, if the pattern set contains both <em>keywords</em> and a
catch-all, <em>identifier</em> rule, such as in the set:

     <pre class="example">     <pre class="verbatim">          
              "case"    return TOK_CASE;
              "switch"  return TOK_SWITCH;
              ...
              "default" return TOK_DEFAULT;
              [a-z]+    return TOK_ID;
     </pre>
     </pre>
     <p>then you're better off using the full table representation.  If only
the <em>identifier</em> rule is present and you then use a hash table or some such
to detect the keywords, you're better off using
`<samp><span class="samp">--fast</span></samp>'.

     <p>This option is equivalent to `<samp><span class="samp">-CFr</span></samp>' (see below).  It cannot be used
with `<samp><span class="samp">--c++</span></samp>'.

</dl>

<div class="node">
<p><hr>
<a name="Debugging-Options"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Miscellaneous-Options">Miscellaneous Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.5 Debugging Options</h3>

     <dl>
<a name="option_002dbackup"></a>
<a name="index-g_t_002db-344"></a><a name="index-g_t_002d_002d_002dbackup-345"></a><a name="index-backup-346"></a><dt>`<samp><span class="samp">-b, --backup, </span><code>%option backup</code></samp>'<dd>Generate backing-up information to <samp><span class="file">lex.backup</span></samp>.  This is a list of
scanner states which require backing up and the input characters on
which they do so.  By adding rules one can remove backing-up states.  If
<em>all</em> backing-up states are eliminated and `<samp><span class="samp">-Cf</span></samp>' or <code>-CF</code>
is used, the generated scanner will run faster (see the `<samp><span class="samp">--perf-report</span></samp>' flag). 
Only users who wish to squeeze every last cycle out of their scanners
need worry about this option.  (see <a href="#Performance">Performance</a>).

     <p><a name="option_002ddebug"></a>
<a name="index-g_t_002dd-347"></a><a name="index-g_t_002d_002d_002ddebug-348"></a><a name="index-debug-349"></a><br><dt>`<samp><span class="samp">-d, --debug, </span><code>%option debug</code></samp>'<dd>makes the generated scanner run in <dfn>debug</dfn> mode.  Whenever a pattern
is recognized and the global variable <code>yy_flex_debug</code> is non-zero
(which is the default), the scanner will write to <samp><span class="file">stderr</span></samp> a line
of the form:

     <pre class="example">     <pre class="verbatim">          
              -accepting rule at line 53 ("the matched text")
     </pre>
     </pre>
     <p>The line number refers to the location of the rule in the file defining
the scanner (i.e., the file that was fed to flex).  Messages are also
generated when the scanner backs up, accepts the default rule, reaches
the end of its input buffer (or encounters a NUL; at this point, the two
look the same as far as the scanner's concerned), or reaches an
end-of-file.

     <p><a name="option_002dperf_002dreport"></a>
<a name="index-g_t_002dp-350"></a><a name="index-g_t_002d_002d_002dperf_002dreport-351"></a><a name="index-perf_002dreport-352"></a><br><dt>`<samp><span class="samp">-p, --perf-report, </span><code>%option perf-report</code></samp>'<dd>generates a performance report to <samp><span class="file">stderr</span></samp>.  The report consists of
comments regarding features of the <code>flex</code> input file which will
cause a serious loss of performance in the resulting scanner.  If you
give the flag twice, you will also get comments regarding features that
lead to minor performance losses.

     <p>Note that the use of <code>REJECT</code>, and
variable trailing context (see <a href="#Limitations">Limitations</a>) entails a substantial
performance penalty; use of <code>yymore()</code>, the `<samp><span class="samp">^</span></samp>' operator, and
the `<samp><span class="samp">--interactive</span></samp>' flag entail minor performance penalties.

     <p><a name="option_002dnodefault"></a>
<a name="index-g_t_002ds-353"></a><a name="index-g_t_002d_002d_002dnodefault-354"></a><a name="index-nodefault-355"></a><br><dt>`<samp><span class="samp">-s, --nodefault, </span><code>%option nodefault</code></samp>'<dd>causes the <em>default rule</em> (that unmatched scanner input is echoed
to <samp><span class="file">stdout)</span></samp> to be suppressed.  If the scanner encounters input
that does not match any of its rules, it aborts with an error.  This
option is useful for finding holes in a scanner's rule set.

     <p><a name="option_002dtrace"></a>
<a name="index-g_t_002dT-356"></a><a name="index-g_t_002d_002d_002dtrace-357"></a><a name="index-trace-358"></a><br><dt>`<samp><span class="samp">-T, --trace, </span><code>%option trace</code></samp>'<dd>makes <code>flex</code> run in <dfn>trace</dfn> mode.  It will generate a lot of
messages to <samp><span class="file">stderr</span></samp> concerning the form of the input and the
resultant non-deterministic and deterministic finite automata.  This
option is mostly for use in maintaining <code>flex</code>.

     <p><a name="option_002dnowarn"></a>
<a name="index-g_t_002dw-359"></a><a name="index-g_t_002d_002d_002dnowarn-360"></a><a name="index-nowarn-361"></a><br><dt>`<samp><span class="samp">-w, --nowarn, </span><code>%option nowarn</code></samp>'<dd>suppresses warning messages.

     <p><a name="option_002dverbose"></a>
<a name="index-g_t_002dv-362"></a><a name="index-g_t_002d_002d_002dverbose-363"></a><a name="index-verbose-364"></a><br><dt>`<samp><span class="samp">-v, --verbose, </span><code>%option verbose</code></samp>'<dd>specifies that <code>flex</code> should write to <samp><span class="file">stderr</span></samp> a summary of
statistics regarding the scanner it generates.  Most of the statistics
are meaningless to the casual <code>flex</code> user, but the first line
identifies the version of <code>flex</code> (same as reported by `<samp><span class="samp">--version</span></samp>'),
and the next line the flags used when generating the scanner, including
those that are on by default.

     <p><a name="option_002dwarn"></a>
<a name="index-g_t_002d_002d_002dwarn-365"></a><a name="index-warn-366"></a><br><dt>`<samp><span class="samp">--warn, </span><code>%option warn</code></samp>'<dd>warn about certain things. In particular, if the default rule can be
matched but no defualt rule has been given, the flex will warn you. 
We recommend using this option always.

</dl>

<div class="node">
<p><hr>
<a name="Miscellaneous-Options"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Debugging-Options">Debugging Options</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scanner-Options">Scanner Options</a>

</div>

<h3 class="section">16.6 Miscellaneous Options</h3>

     
<a name="index-g_t_002dc-367"></a>
<dl><dt>`<samp><span class="samp">-c</span></samp>'<dd>is a do-nothing option included for POSIX compliance.

     <p><a name="index-g_t_002dh-368"></a><a name="index-g_t_002d_002d_002dhelp-369"></a>generates
<br><dt>`<samp><span class="samp">-h, -?, --help</span></samp>'<dd>generates a &ldquo;help&rdquo; summary of <code>flex</code>'s options to <samp><span class="file">stdout</span></samp>
and then exits.

     <p><a name="index-g_t_002dn-370"></a><br><dt>`<samp><span class="samp">-n</span></samp>'<dd>is another do-nothing option included only for
POSIX compliance.

     <p><a name="index-g_t_002dV-371"></a><a name="index-g_t_002d_002d_002dversion-372"></a><br><dt>`<samp><span class="samp">-V, --version</span></samp>'<dd>prints the version number to <samp><span class="file">stdout</span></samp> and exits.

</dl>

<div class="node">
<p><hr>
<a name="Performance"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Cxx">Cxx</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Scanner-Options">Scanner Options</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">17 Performance Considerations</h2>

<p><a name="index-performance_002c-considerations-373"></a>The main design goal of <code>flex</code> is that it generate high-performance
scanners.  It has been optimized for dealing well with large sets of
rules.  Aside from the effects on scanner speed of the table compression
`<samp><span class="samp">-C</span></samp>' options outlined above, there are a number of options/actions
which degrade performance.  These are, from most expensive to least:

   <p><a name="index-REJECT_002c-performance-costs-374"></a><a name="index-yylineno_002c-performance-costs-375"></a><a name="index-trailing-context_002c-performance-costs-376"></a>
<pre class="example"><pre class="verbatim">     
         REJECT
         arbitrary trailing context
     
         pattern sets that require backing up
         %option yylineno
         %array
     
         %option interactive
         %option always-interactive
     
         @samp{^} beginning-of-line operator
         yymore()
</pre>
</pre>
   <p>with the first two all being quite expensive and the last two being
quite cheap.  Note also that <code>unput()</code> is implemented as a routine
call that potentially does quite a bit of work, while <code>yyless()</code> is
a quite-cheap macro. So if you are just putting back some excess text
you scanned, use <code>ss()</code>.

   <p><code>REJECT</code> should be avoided at all costs when performance is
important.  It is a particularly expensive option.

   <p>There is one case when <code>%option yylineno</code> can be expensive. That is when
your patterns match long tokens that could <em>possibly</em> contain a newline
character. There is no performance penalty for rules that can not possibly
match newlines, since flex does not need to check them for newlines.  In
general, you should avoid rules such as <code>[^f]+</code>, which match very long
tokens, including newlines, and may possibly match your entire file! A better
approach is to separate <code>[^f]+</code> into two rules:

<pre class="example"><pre class="verbatim">     
     %option yylineno
     %%
         [^f\n]+
         \n+
</pre>
</pre>
   <p>The above scanner does not incur a performance penalty.

   <p><a name="index-patterns_002c-tuning-for-performance-377"></a><a name="index-performance_002c-backing-up-378"></a><a name="index-backing-up_002c-example-of-eliminating-379"></a>Getting rid of backing up is messy and often may be an enormous amount
of work for a complicated scanner.  In principal, one begins by using
the `<samp><span class="samp">-b</span></samp>' flag to generate a <samp><span class="file">lex.backup</span></samp> file.  For example,
on the input:

   <p><a name="index-backing-up_002c-eliminating-380"></a>
<pre class="example"><pre class="verbatim">     
         %%
         foo        return TOK_KEYWORD;
         foobar     return TOK_KEYWORD;
</pre>
</pre>
   <p>the file looks like:

<pre class="example"><pre class="verbatim">     
         State #6 is non-accepting -
          associated rule line numbers:
                2       3
          out-transitions: [ o ]
          jam-transitions: EOF [ \001-n  p-\177 ]
     
         State #8 is non-accepting -
          associated rule line numbers:
                3
          out-transitions: [ a ]
          jam-transitions: EOF [ \001-`  b-\177 ]
     
         State #9 is non-accepting -
          associated rule line numbers:
                3
          out-transitions: [ r ]
          jam-transitions: EOF [ \001-q  s-\177 ]
     
         Compressed tables always back up.
</pre>
</pre>
   <p>The first few lines tell us that there's a scanner state in which it can
make a transition on an 'o' but not on any other character, and that in
that state the currently scanned text does not match any rule.  The
state occurs when trying to match the rules found at lines 2 and 3 in
the input file.  If the scanner is in that state and then reads
something other than an 'o', it will have to back up to find a rule
which is matched.  With a bit of headscratching one can see that this
must be the state it's in when it has seen `<samp><span class="samp">fo</span></samp>'.  When this has
happened, if anything other than another `<samp><span class="samp">o</span></samp>' is seen, the scanner
will have to back up to simply match the `<samp><span class="samp">f</span></samp>' (by the default rule).

   <p>The comment regarding State #8 indicates there's a problem when
`<samp><span class="samp">foob</span></samp>' has been scanned.  Indeed, on any character other than an
`<samp><span class="samp">a</span></samp>', the scanner will have to back up to accept "foo".  Similarly,
the comment for State #9 concerns when `<samp><span class="samp">fooba</span></samp>' has been scanned and
an `<samp><span class="samp">r</span></samp>' does not follow.

   <p>The final comment reminds us that there's no point going to all the
trouble of removing backing up from the rules unless we're using
`<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>', since there's no performance gain doing so
with compressed scanners.

   <p><a name="index-error-rules_002c-to-eliminate-backing-up-381"></a>The way to remove the backing up is to add &ldquo;error&rdquo; rules:

   <p><a name="index-backing-up_002c-eliminating-by-adding-error-rules-382"></a>
<pre class="example"><pre class="verbatim">     
         %%
         foo         return TOK_KEYWORD;
         foobar      return TOK_KEYWORD;
     
         fooba       |
         foob        |
         fo          {
                     /* false alarm, not really a keyword */
                     return TOK_ID;
                     }
</pre>
</pre>
   <p>Eliminating backing up among a list of keywords can also be done using a
&ldquo;catch-all&rdquo; rule:

   <p><a name="index-backing-up_002c-eliminating-with-catch_002dall-rule-383"></a>
<pre class="example"><pre class="verbatim">     
         %%
         foo         return TOK_KEYWORD;
         foobar      return TOK_KEYWORD;
     
         [a-z]+      return TOK_ID;
</pre>
</pre>
   <p>This is usually the best solution when appropriate.

   <p>Backing up messages tend to cascade.  With a complicated set of rules
it's not uncommon to get hundreds of messages.  If one can decipher
them, though, it often only takes a dozen or so rules to eliminate the
backing up (though it's easy to make a mistake and have an error rule
accidentally match a valid token.  A possible future <code>flex</code> feature
will be to automatically add rules to eliminate backing up).

   <p>It's important to keep in mind that you gain the benefits of eliminating
backing up only if you eliminate <em>every</em> instance of backing up. 
Leaving just one means you gain nothing.

   <p><em>Variable</em> trailing context (where both the leading and trailing
parts do not have a fixed length) entails almost the same performance
loss as <code>REJECT</code> (i.e., substantial).  So when possible a rule
like:

   <p><a name="index-trailing-context_002c-variable-length-384"></a>
<pre class="example"><pre class="verbatim">     
         %%
         mouse|rat/(cat|dog)   run();
</pre>
</pre>
   <p>is better written:

<pre class="example"><pre class="verbatim">     
         %%
         mouse/cat|dog         run();
         rat/cat|dog           run();
</pre>
</pre>
   <p>or as

<pre class="example"><pre class="verbatim">     
         %%
         mouse|rat/cat         run();
         mouse|rat/dog         run();
</pre>
</pre>
   <p>Note that here the special '|' action does <em>not</em> provide any
savings, and can even make things worse (see <a href="#Limitations">Limitations</a>).

   <p>Another area where the user can increase a scanner's performance (and
one that's easier to implement) arises from the fact that the longer the
tokens matched, the faster the scanner will run.  This is because with
long tokens the processing of most input characters takes place in the
(short) inner scanning loop, and does not often have to go through the
additional work of setting up the scanning environment (e.g.,
<code>yytext</code>) for the action.  Recall the scanner for C comments:

   <p><a name="index-performance-optimization_002c-matching-longer-tokens-385"></a>
<pre class="example"><pre class="verbatim">     
         %x comment
         %%
                 int line_num = 1;
     
         "/*"         BEGIN(comment);
     
         &lt;comment>[^*\n]*
         &lt;comment>"*"+[^*/\n]*
         &lt;comment>\n             ++line_num;
         &lt;comment>"*"+"/"        BEGIN(INITIAL);
</pre>
</pre>
   <p>This could be sped up by writing it as:

<pre class="example"><pre class="verbatim">     
         %x comment
         %%
                 int line_num = 1;
     
         "/*"         BEGIN(comment);
     
         &lt;comment>[^*\n]*
         &lt;comment>[^*\n]*\n      ++line_num;
         &lt;comment>"*"+[^*/\n]*
         &lt;comment>"*"+[^*/\n]*\n ++line_num;
         &lt;comment>"*"+"/"        BEGIN(INITIAL);
</pre>
</pre>
   <p>Now instead of each newline requiring the processing of another action,
recognizing the newlines is distributed over the other rules to keep the
matched text as long as possible.  Note that <em>adding</em> rules does
<em>not</em> slow down the scanner!  The speed of the scanner is
independent of the number of rules or (modulo the considerations given
at the beginning of this section) how complicated the rules are with
regard to operators such as `<samp><span class="samp">*</span></samp>' and `<samp><span class="samp">|</span></samp>'.

   <p><a name="index-keywords_002c-for-performance-386"></a><a name="index-performance_002c-using-keywords-387"></a>A final example in speeding up a scanner: suppose you want to scan
through a file containing identifiers and keywords, one per line
and with no other extraneous characters, and recognize all the
keywords.  A natural first approach is:

   <p><a name="index-performance-optimization_002c-recognizing-keywords-388"></a>
<pre class="example"><pre class="verbatim">     
         %%
         asm      |
         auto     |
         break    |
         ... etc ...
         volatile |
         while    /* it's a keyword */
     
         .|\n     /* it's not a keyword */
</pre>
</pre>
   <p>To eliminate the back-tracking, introduce a catch-all rule:

<pre class="example"><pre class="verbatim">     
         %%
         asm      |
         auto     |
         break    |
         ... etc ...
         volatile |
         while    /* it's a keyword */
     
         [a-z]+   |
         .|\n     /* it's not a keyword */
</pre>
</pre>
   <p>Now, if it's guaranteed that there's exactly one word per line, then we
can reduce the total number of matches by a half by merging in the
recognition of newlines with that of the other tokens:

<pre class="example"><pre class="verbatim">     
         %%
         asm\n    |
         auto\n   |
         break\n  |
         ... etc ...
         volatile\n |
         while\n  /* it's a keyword */
     
         [a-z]+\n |
         .|\n     /* it's not a keyword */
</pre>
</pre>
   <p>One has to be careful here, as we have now reintroduced backing up
into the scanner.  In particular, while
<em>we</em>
know that there will never be any characters in the input stream
other than letters or newlines,
<code>flex</code>
can't figure this out, and it will plan for possibly needing to back up
when it has scanned a token like `<samp><span class="samp">auto</span></samp>' and then the next character
is something other than a newline or a letter.  Previously it would
then just match the `<samp><span class="samp">auto</span></samp>' rule and be done, but now it has no `<samp><span class="samp">auto</span></samp>'
rule, only a `<samp><span class="samp">auto\n</span></samp>' rule.  To eliminate the possibility of backing up,
we could either duplicate all rules but without final newlines, or,
since we never expect to encounter such an input and therefore don't
how it's classified, we can introduce one more catch-all rule, this
one which doesn't include a newline:

<pre class="example"><pre class="verbatim">     
         %%
         asm\n    |
         auto\n   |
         break\n  |
         ... etc ...
         volatile\n |
         while\n  /* it's a keyword */
     
         [a-z]+\n |
         [a-z]+   |
         .|\n     /* it's not a keyword */
</pre>
</pre>
   <p>Compiled with `<samp><span class="samp">-Cf</span></samp>', this is about as fast as one can get a
<code>flex</code> scanner to go for this particular problem.

   <p>A final note: <code>flex</code> is slow when matching <code>NUL</code>s,
particularly when a token contains multiple <code>NUL</code>s.  It's best to
write rules which match <em>short</em> amounts of text if it's anticipated
that the text will often include <code>NUL</code>s.

   <p>Another final note regarding performance: as mentioned in
<a href="#Matching">Matching</a>, dynamically resizing <code>yytext</code> to accommodate huge
tokens is a slow process because it presently requires that the (huge)
token be rescanned from the beginning.  Thus if performance is vital,
you should attempt to match &ldquo;large&rdquo; quantities of text but not
&ldquo;huge&rdquo; quantities, where the cutoff between the two is at about 8K
characters per token.

<div class="node">
<p><hr>
<a name="Cxx"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reentrant">Reentrant</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Performance">Performance</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">18 Generating C++ Scanners</h2>

<p><a name="index-c_002b_002b_002c-experimental-form-of-scanner-class-389"></a><a name="index-experimental-form-of-c_002b_002b-scanner-class-390"></a><strong>IMPORTANT</strong>: the present form of the scanning class is <em>experimental</em>
and may change considerably between major releases.

   <p><a name="index-C_002b_002b-391"></a><a name="index-member-functions_002c-C_002b_002b-392"></a><a name="index-methods_002c-c_002b_002b-393"></a><code>flex</code> provides two different ways to generate scanners for use
with C++.  The first way is to simply compile a scanner generated by
<code>flex</code> using a C++ compiler instead of a C compiler.  You should
not encounter any compilation errors (see <a href="#Reporting-Bugs">Reporting Bugs</a>).  You can
then use C++ code in your rule actions instead of C code.  Note that the
default input source for your scanner remains <samp><span class="file">yyin</span></samp>, and default
echoing is still done to <samp><span class="file">yyout</span></samp>.  Both of these remain <code>FILE
*</code> variables and not C++ <em>streams</em>.

   <p>You can also use <code>flex</code> to generate a C++ scanner class, using the
`<samp><span class="samp">-+</span></samp>' option (or, equivalently, <code>%option c++)</code>, which is
automatically specified if the name of the <code>flex</code> executable ends
in a '+', such as <code>flex++</code>.  When using this option, <code>flex</code>
defaults to generating the scanner to the file <samp><span class="file">lex.yy.cc</span></samp> instead
of <samp><span class="file">lex.yy.c</span></samp>.  The generated scanner includes the header file
<samp><span class="file">FlexLexer.h</span></samp>, which defines the interface to two C++ classes.

   <p>The first class,
<code>FlexLexer</code>,
provides an abstract base class defining the general scanner class
interface.  It provides the following member functions:

     
<a name="index-YYText-_0028C_002b_002b-only_0029-394"></a>
<dl><dt><code>const char* YYText()</code><dd>returns the text of the most recently matched token, the equivalent of
<code>yytext</code>.

     <p><a name="index-YYLeng-_0028C_002b_002b-only_0029-395"></a><br><dt><code>int YYLeng()</code><dd>returns the length of the most recently matched token, the equivalent of
<code>yyleng</code>.

     <p><a name="index-lineno-_0028C_002b_002b-only_0029-396"></a><br><dt><code>int lineno() const</code><dd>returns the current input line number (see <code>%option yylineno)</code>, or
<code>1</code> if <code>%option yylineno</code> was not used.

     <p><a name="index-set_005fdebug-_0028C_002b_002b-only_0029-397"></a><br><dt><code>void set_debug( int flag )</code><dd>sets the debugging flag for the scanner, equivalent to assigning to
<code>yy_flex_debug</code> (see <a href="#Scanner-Options">Scanner Options</a>).  Note that you must build
the scannerusing <code>%option debug</code> to include debugging information
in it.

     <p><a name="index-debug-_0028C_002b_002b-only_0029-398"></a><br><dt><code>int debug() const</code><dd>returns the current setting of the debugging flag. 
</dl>

   <p>Also provided are member functions equivalent to
<code>yy_switch_to_buffer()</code>, <code>yy_create_buffer()</code> (though the
first argument is an <code>istream*</code> object pointer and not a
<code>FILE*)</code>, <code>yy_flush_buffer()</code>, <code>yy_delete_buffer()</code>, and
<code>yyrestart()</code> (again, the first argument is a <code>istream*</code>
object pointer).

   <p><a name="index-yyFlexLexer-_0028C_002b_002b-only_0029-399"></a><a name="index-FlexLexer-_0028C_002b_002b-only_0029-400"></a>The second class defined in <samp><span class="file">FlexLexer.h</span></samp> is <code>yyFlexLexer</code>,
which is derived from <code>FlexLexer</code>.  It defines the following
additional member functions:

     
<a name="index-yyFlexLexer-constructor-_0028C_002b_002b-only_0029-401"></a>
<dl><dt><code>yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )</code><dd>constructs a <code>yyFlexLexer</code> object using the given streams for input
and output.  If not specified, the streams default to <code>cin</code> and
<code>cout</code>, respectively.

     <p><a name="index-yylex-_0028C_002b_002b-version_0029-402"></a><br><dt><code>virtual int yylex()</code><dd>performs the same role is <code>yylex()</code> does for ordinary <code>flex</code>
scanners: it scans the input stream, consuming tokens, until a rule's
action returns a value.  If you derive a subclass <code>S</code> from
<code>yyFlexLexer</code> and want to access the member functions and variables
of <code>S</code> inside <code>yylex()</code>, then you need to use <code>%option
yyclass="S"</code> to inform <code>flex</code> that you will be using that subclass
instead of <code>yyFlexLexer</code>.  In this case, rather than generating
<code>yyFlexLexer::yylex()</code>, <code>flex</code> generates <code>S::yylex()</code>
(and also generates a dummy <code>yyFlexLexer::yylex()</code> that calls
<code>yyFlexLexer::LexerError()</code> if called).

     <p><a name="index-switch_005fstreams-_0028C_002b_002b-only_0029-403"></a><br><dt><code>virtual void switch_streams(istream* new_in = 0, ostream* new_out = 0)</code><dd>reassigns <code>yyin</code> to <code>new_in</code> (if non-null) and <code>yyout</code> to
<code>new_out</code> (if non-null), deleting the previous input buffer if
<code>yyin</code> is reassigned.

     <br><dt><code>int yylex( istream* new_in, ostream* new_out = 0 )</code><dd>first switches the input streams via <code>switch_streams( new_in,
new_out )</code> and then returns the value of <code>yylex()</code>. 
</dl>

   <p>In addition, <code>yyFlexLexer</code> defines the following protected virtual
functions which you can redefine in derived classes to tailor the
scanner:

     
<a name="index-LexerInput-_0028C_002b_002b-only_0029-404"></a>
<dl><dt><code>virtual int LexerInput( char* buf, int max_size )</code><dd>reads up to <code>max_size</code> characters into <code>buf</code> and returns the
number of characters read.  To indicate end-of-input, return 0
characters.  Note that <code>interactive</code> scanners (see the `<samp><span class="samp">-B</span></samp>'
and `<samp><span class="samp">-I</span></samp>' flags in <a href="#Scanner-Options">Scanner Options</a>) define the macro
<code>YY_INTERACTIVE</code>.  If you redefine <code>LexerInput()</code> and need to
take different actions depending on whether or not the scanner might be
scanning an interactive input source, you can test for the presence of
this name via <code>#ifdef</code> statements.

     <p><a name="index-LexerOutput-_0028C_002b_002b-only_0029-405"></a><br><dt><code>virtual void LexerOutput( const char* buf, int size )</code><dd>writes out <code>size</code> characters from the buffer <code>buf</code>, which, while
<code>NUL</code>-terminated, may also contain internal <code>NUL</code>s if the
scanner's rules can match text with <code>NUL</code>s in them.

     <p><a name="index-error-reporting_002c-in-C_002b_002b-406"></a><a name="index-LexerError-_0028C_002b_002b-only_0029-407"></a><br><dt><code>virtual void LexerError( const char* msg )</code><dd>reports a fatal error message.  The default version of this function
writes the message to the stream <code>cerr</code> and exits. 
</dl>

   <p>Note that a <code>yyFlexLexer</code> object contains its <em>entire</em>
scanning state.  Thus you can use such objects to create reentrant
scanners, but see also <a href="#Reentrant">Reentrant</a>.  You can instantiate multiple
instances of the same <code>yyFlexLexer</code> class, and you can also combine
multiple C++ scanner classes together in the same program using the
`<samp><span class="samp">-P</span></samp>' option discussed above.

   <p>Finally, note that the <code>%array</code> feature is not available to C++
scanner classes; you must use <code>%pointer</code> (the default).

   <p>Here is an example of a simple C++ scanner:

   <p><a name="index-C_002b_002b-scanners_002c-use-of-408"></a>
<pre class="example"><pre class="verbatim">     
             // An example of using the flex C++ scanner class.
     
         %{
         int mylineno = 0;
         %}
     
         string  \"[^\n"]+\"
     
         ws      [ \t]+
     
         alpha   [A-Za-z]
         dig     [0-9]
         name    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
         num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
         num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
         number  {num1}|{num2}
     
         %%
     
         {ws}    /* skip blanks and tabs */
     
         "/*"    {
                 int c;
     
                 while((c = yyinput()) != 0)
                     {
                     if(c == '\n')
                         ++mylineno;
     
                     else if(c == @samp{*})
                         {
                         if((c = yyinput()) == '/')
                             break;
                         else
                             unput(c);
                         }
                     }
                 }
     
         {number}  cout  "number "  YYText()  '\n';
     
         \n        mylineno++;
     
         {name}    cout  "name "  YYText()  '\n';
     
         {string}  cout  "string "  YYText()  '\n';
     
         %%
     
         int main( int /* argc */, char** /* argv */ )
             {
             @code{flex}Lexer* lexer = new yyFlexLexer;
             while(lexer->yylex() != 0)
                 ;
             return 0;
             }
</pre>
</pre>
   <p><a name="index-C_002b_002b_002c-multiple-different-scanners-409"></a>If you want to create multiple (different) lexer classes, you use the
`<samp><span class="samp">-P</span></samp>' flag (or the <code>prefix=</code> option) to rename each
<code>yyFlexLexer</code> to some other `<samp><span class="samp">xxFlexLexer</span></samp>'.  You then can
include <samp><span class="file">FlexLexer.h&gt;</span></samp> in your other sources once per lexer class,
first renaming <code>yyFlexLexer</code> as follows:

   <p><a name="index-include-files_002c-with-C_002b_002b-410"></a><a name="index-header-files_002c-with-C_002b_002b-411"></a><a name="index-C_002b_002b-scanners_002c-including-multiple-scanners-412"></a>
<pre class="example"><pre class="verbatim">     
         #undef yyFlexLexer
         #define yyFlexLexer xxFlexLexer
         #include &lt;FflexLexer.h>
     
         #undef yyFlexLexer
         #define yyFlexLexer zzFlexLexer
         #include FlexLexer.h>
</pre>
</pre>
   <p>if, for example, you used <code>%option prefix="xx"</code> for one of your
scanners and <code>%option prefix="zz"</code> for the other.

<div class="node">
<p><hr>
<a name="Reentrant"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Lex-and-Posix">Lex and Posix</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Cxx">Cxx</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">19 Reentrant C Scanners</h2>

<p><a name="index-reentrant_002c-explanation-413"></a><code>flex</code> has the ability to generate a reentrant C scanner. This is
accomplished by specifying <code>%option reentrant</code> (`<samp><span class="samp">-R</span></samp>') The generated
scanner is both portable, and safe to use in one or more separate threads of
control.  The most common use for reentrant scanners is from within
multi-threaded applications.  Any thread may create and execute a reentrant
<code>flex</code> scanner without the need for synchronization with other threads.

<ul class="menu">
<li><a accesskey="1" href="#Reentrant-Uses">Reentrant Uses</a>
<li><a accesskey="2" href="#Reentrant-Overview">Reentrant Overview</a>
<li><a accesskey="3" href="#Reentrant-Example">Reentrant Example</a>
<li><a accesskey="4" href="#Reentrant-Detail">Reentrant Detail</a>
<li><a accesskey="5" href="#Reentrant-Functions">Reentrant Functions</a>
</ul>

<div class="node">
<p><hr>
<a name="Reentrant-Uses"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reentrant-Overview">Reentrant Overview</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant">Reentrant</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant">Reentrant</a>

</div>

<h3 class="section">19.1 Uses for Reentrant Scanners</h3>

<p>However, there are other uses for a reentrant scanner.  For example, you
could scan two or more files simultaneously to implement a <code>diff</code> at
the token level (i.e., instead of at the character level):

   <p><a name="index-reentrant-scanners_002c-multiple-interleaved-scanners-414"></a>
<pre class="example"><pre class="verbatim">     
         /* Example of maintaining more than one active scanner. */
     
         do {
             int tok1, tok2;
     
             tok1 = yylex( scanner_1 );
             tok2 = yylex( scanner_2 );
     
             if( tok1 != tok2 )
                 printf("Files are different.");
     
        } while ( tok1 &amp;&amp; tok2 );
</pre>
</pre>
   <p>Another use for a reentrant scanner is recursion. 
(Note that a recursive scanner can also be created using a non-reentrant scanner and
buffer states. See <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a>.)

   <p>The following crude scanner supports the `<samp><span class="samp">eval</span></samp>' command by invoking
another instance of itself.

   <p><a name="index-reentrant-scanners_002c-recursive-invocation-415"></a>
<pre class="example"><pre class="verbatim">     
         /* Example of recursive invocation. */
     
         %option reentrant
     
         %%
         "eval(".+")"  {
                           yyscan_t scanner;
                           YY_BUFFER_STATE buf;
     
                           yylex_init( &amp;scanner );
                           yytext[yyleng-1] = ' ';
     
                           buf = yy_scan_string( yytext + 5, scanner );
                           yylex( scanner );
     
                           yy_delete_buffer(buf,scanner);
                           yylex_destroy( scanner );
                      }
         ...
         %%
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Reentrant-Overview"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reentrant-Example">Reentrant Example</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant-Uses">Reentrant Uses</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant">Reentrant</a>

</div>

<h3 class="section">19.2 An Overview of the Reentrant API</h3>

<p><a name="index-reentrant_002c-API-explanation-416"></a>The API for reentrant scanners is different than for non-reentrant
scanners. Here is a quick overview of the API:

     <ul>
<code>%option reentrant</code> must be specified.

     <li>All functions take one additional argument: <code>yyscanner</code>

     <li>All global variables are replaced by their macro equivalents. 
(We tell you this because it may be important to you during debugging.)

     <li><code>yylex_init</code> and <code>yylex_destroy</code> must be called before and
after <code>yylex</code>, respectively.

     <li>Accessor methods (get/set functions) provide access to common
<code>flex</code> variables.

     <li>User-specific data can be stored in <code>yyextra</code>. 
</ul>

<div class="node">
<p><hr>
<a name="Reentrant-Example"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reentrant-Detail">Reentrant Detail</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant-Overview">Reentrant Overview</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant">Reentrant</a>

</div>

<h3 class="section">19.3 Reentrant Example</h3>

<p>First, an example of a reentrant scanner:
<a name="index-reentrant_002c-example-of-417"></a>
<pre class="example"><pre class="verbatim">     
         /* This scanner prints "//" comments. */
         %option reentrant stack
         %x COMMENT
         %%
         "//"                 yy_push_state( COMMENT, yyscanner);
         .|\n
         &lt;COMMENT>\n          yy_pop_state( yyscanner );
         &lt;COMMENT>[^\n]+      fprintf( yyout, "%s\n", yytext);
         %%
         int main ( int argc, char * argv[] )
         {
             yyscan_t scanner;
     
             yylex_init ( &amp;scanner );
             yylex ( scanner );
             yylex_destroy ( scanner );
         return 0;
        }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Reentrant-Detail"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reentrant-Functions">Reentrant Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant-Example">Reentrant Example</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant">Reentrant</a>

</div>

<h3 class="section">19.4 The Reentrant API in Detail</h3>

<p>Here are the things you need to do or know to use the reentrant C API of
<code>flex</code>.

<ul class="menu">
<li><a accesskey="1" href="#Specify-Reentrant">Specify Reentrant</a>
<li><a accesskey="2" href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a>
<li><a accesskey="3" href="#Global-Replacement">Global Replacement</a>
<li><a accesskey="4" href="#Init-and-Destroy-Functions">Init and Destroy Functions</a>
<li><a accesskey="5" href="#Accessor-Methods">Accessor Methods</a>
<li><a accesskey="6" href="#Extra-Data">Extra Data</a>
<li><a accesskey="7" href="#About-yyscan_005ft">About yyscan_t</a>
</ul>

<div class="node">
<p><hr>
<a name="Specify-Reentrant"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant-Detail">Reentrant Detail</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.1 Declaring a Scanner As Reentrant</h4>

<p>%option reentrant (&ndash;reentrant) must be specified.

   <p>Notice that <code>%option reentrant</code> is specified in the above example
(see <a href="#Reentrant-Example">Reentrant Example</a>. Had this option not been specified,
<code>flex</code> would have happily generated a non-reentrant scanner without
complaining. You may explicitly specify <code>%option noreentrant</code>, if
you do <em>not</em> want a reentrant scanner, although it is not
necessary. The default is to generate a non-reentrant scanner.

<div class="node">
<p><hr>
<a name="Extra-Reentrant-Argument"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Global-Replacement">Global Replacement</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Specify-Reentrant">Specify Reentrant</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.2 The Extra Argument</h4>

<p><a name="index-reentrant_002c-calling-functions-418"></a><a name="index-yyscanner-_0028reentrant-only_0029-419"></a>All functions take one additional argument: <code>yyscanner</code>.

   <p>Notice that the calls to <code>yy_push_state</code> and <code>yy_pop_state</code>
both have an argument, <code>yyscanner</code> , that is not present in a
non-reentrant scanner.  Here are the declarations of
<code>yy_push_state</code> and <code>yy_pop_state</code> in the generated scanner:

<pre class="example"><pre class="verbatim">     
         static void yy_push_state  ( int new_state , yyscan_t yyscanner ) ;
         static void yy_pop_state  ( yyscan_t yyscanner  ) ;
</pre>
</pre>
   <p>Notice that the argument <code>yyscanner</code> appears in the declaration of
both functions.  In fact, all <code>flex</code> functions in a reentrant
scanner have this additional argument.  It is always the last argument
in the argument list, it is always of type <code>yyscan_t</code> (which is
typedef'd to <code>void *</code>) and it is
always named <code>yyscanner</code>.  As you may have guessed,
<code>yyscanner</code> is a pointer to an opaque data structure encapsulating
the current state of the scanner.  For a list of function declarations,
see <a href="#Reentrant-Functions">Reentrant Functions</a>. Note that preprocessor macros, such as
<code>BEGIN</code>, <code>ECHO</code>, and <code>REJECT</code>, do not take this
additional argument.

<div class="node">
<p><hr>
<a name="Global-Replacement"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Init-and-Destroy-Functions">Init and Destroy Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.3 Global Variables Replaced By Macros</h4>

<p><a name="index-reentrant_002c-accessing-flex-variables-420"></a>All global variables in traditional flex have been replaced by macro equivalents.

   <p>Note that in the above example, <code>yyout</code> and <code>yytext</code> are
not plain variables. These are macros that will expand to their equivalent lvalue. 
All of the familiar <code>flex</code> globals have been replaced by their macro
equivalents. In particular, <code>yytext</code>, <code>yyleng</code>, <code>yylineno</code>,
<code>yyin</code>, <code>yyout</code>, <code>yyextra</code>, <code>yylval</code>, and <code>yylloc</code>
are macros. You may safely use these macros in actions as if they were plain
variables. We only tell you this so you don't expect to link to these variables
externally. Currently, each macro expands to a member of an internal struct, e.g.,

<pre class="example"><pre class="verbatim">     
     #define yytext (((struct yyguts_t*)yyscanner)->yytext_r)
</pre>
</pre>
   <p>One important thing to remember about
<code>yytext</code>
and friends is that
<code>yytext</code>
is not a global variable in a reentrant
scanner, you can not access it directly from outside an action or from
other functions. You must use an accessor method, e.g.,
<code>yyget_text</code>,
to accomplish this. (See below).

<div class="node">
<p><hr>
<a name="Init-and-Destroy-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Accessor-Methods">Accessor Methods</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Global-Replacement">Global Replacement</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.4 Init and Destroy Functions</h4>

<p><a name="index-memory_002c-considerations-for-reentrant-scanners-421"></a><a name="index-reentrant_002c-initialization-422"></a><a name="index-yylex_005finit-423"></a><a name="index-yylex_005fdestroy-424"></a>
<code>yylex_init</code> and <code>yylex_destroy</code> must be called before and
after <code>yylex</code>, respectively.

<pre class="example"><pre class="verbatim">     
         int yylex_init ( yyscan_t * ptr_yy_globals ) ;
         int yylex ( yyscan_t yyscanner ) ;
         int yylex_destroy ( yyscan_t yyscanner ) ;
</pre>
</pre>
   <p>The function <code>yylex_init</code> must be called before calling any other
function. The argument to <code>yylex_init</code> is the address of an
uninitialized pointer to be filled in by <code>flex</code>. The contents of
<code>ptr_yy_globals</code> need not be initialized, since <code>flex</code> will
overwrite it anyway. The value stored in <code>ptr_yy_globals</code> should
thereafter be passed to <code>yylex()</code> and <b>yylex_destroy()</b>.  Flex
does not save the argument passed to <code>yylex_init</code>, so it is safe to
pass the address of a local pointer to <code>yylex_init</code>.  The function
<code>yylex</code> should be familiar to you by now. The reentrant version
takes one argument, which is the value returned (via an argument) by
<code>yylex_init</code>.  Otherwise, it behaves the same as the non-reentrant
version of <code>yylex</code>.

   <p><code>yylex_init</code> returns 0 (zero) on success, or non-zero on failure,
in which case, errno is set to one of the following values:

     <ul>
<li>ENOMEM
Memory allocation error. See <a href="#memory_002dmanagement">memory-management</a>. 
<li>EINVAL
Invalid argument. 
</ul>

   <p>The function <code>yylex_destroy</code> should be
called to free resources used by the scanner. After <code>yylex_destroy</code>
is called, the contents of <code>yyscanner</code> should not be used.  Of
course, there is no need to destroy a scanner if you plan to reuse it. 
A <code>flex</code> scanner (both reentrant and non-reentrant) may be
restarted by calling <code>yyrestart</code>.

   <p>Below is an example of a program that creates a scanner, uses it, then destroys
it when done:

<pre class="example"><pre class="verbatim">     
         int main ()
         {
             yyscan_t scanner;
             int tok;
     
             yylex_init(&amp;scanner);
     
             while ((tok=yylex()) > 0)
                 printf("tok=%d  yytext=%s\n", tok, yyget_text(scanner));
     
             yylex_destroy(scanner);
             return 0;
         }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Accessor-Methods"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Extra-Data">Extra Data</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Init-and-Destroy-Functions">Init and Destroy Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.5 Accessing Variables with Reentrant Scanners</h4>

<p><a name="index-reentrant_002c-accessor-functions-425"></a>Accessor methods (get/set functions) provide access to common
<code>flex</code> variables.

   <p>Many scanners that you build will be part of a larger project. Portions
of your project will need access to <code>flex</code> values, such as
<code>yytext</code>.  In a non-reentrant scanner, these values are global, so
there is no problem accessing them. However, in a reentrant scanner, there are no
global <code>flex</code> values. You can not access them directly.  Instead,
you must access <code>flex</code> values using accessor methods (get/set
functions). Each accessor method is named <code>yyget_NAME</code> or
<code>yyset_NAME</code>, where <code>NAME</code> is the name of the <code>flex</code>
variable you want. For example:

   <p><a name="index-accessor-functions_002c-use-of-426"></a>
<pre class="example"><pre class="verbatim">     
         /* Set the last character of yytext to NULL. */
         void chop ( yyscan_t scanner )
         {
             int len = yyget_leng( scanner );
             yyget_text( scanner )[len - 1] = '\0';
         }
</pre>
</pre>
   <p>The above code may be called from within an action like this:

<pre class="example"><pre class="verbatim">     
         %%
         .+\n    { chop( yyscanner );}
</pre>
</pre>
   <p>You may find that <code>%option header-file</code> is particularly useful for generating
prototypes of all the accessor functions. See <a href="#option_002dheader">option-header</a>.

<div class="node">
<p><hr>
<a name="Extra-Data"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#About-yyscan_005ft">About yyscan_t</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Accessor-Methods">Accessor Methods</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.6 Extra Data</h4>

<p><a name="index-reentrant_002c-extra-data-427"></a><a name="index-yyextra-428"></a>User-specific data can be stored in <code>yyextra</code>.

   <p>In a reentrant scanner, it is unwise to use global variables to
communicate with or maintain state between different pieces of your program. 
However, you may need access to external data or invoke external functions
from within the scanner actions. 
Likewise, you may need to pass information to your scanner
(e.g., open file descriptors, or database connections). 
In a non-reentrant scanner, the only way to do this would be through the
use of global variables. 
<code>Flex</code> allows you to store arbitrary, &ldquo;extra&rdquo; data in a scanner. 
This data is accessible through the accessor methods
<code>yyget_extra</code>
and
<code>yyset_extra</code>
from outside the scanner, and through the shortcut macro
<code>yyextra</code>
from within the scanner itself. They are defined as follows:

   <p><a name="index-YY_005fEXTRA_005fTYPE-_0028reentrant-only_0029-429"></a><a name="index-yyget_005fextra-430"></a><a name="index-yyset_005fextra-431"></a>
<pre class="example"><pre class="verbatim">     
         #define YY_EXTRA_TYPE  void*
         YY_EXTRA_TYPE  yyget_extra ( yyscan_t scanner );
         void           yyset_extra ( YY_EXTRA_TYPE arbitrary_data , yyscan_t scanner);
</pre>
</pre>
   <p>By default, <code>YY_EXTRA_TYPE</code> is defined as type <code>void *</code>.  You
will have to cast <code>yyextra</code> and the return value from
<code>yyget_extra</code> to the appropriate value each time you access the
extra data.  To avoid casting, you may override the default type by
defining <code>YY_EXTRA_TYPE</code> in section 1 of your scanner:

   <p><a name="index-YY_005fEXTRA_005fTYPE_002c-defining-your-own-type-432"></a>
<pre class="example"><pre class="verbatim">     
         /* An example of overriding YY_EXTRA_TYPE. */
         %{
         #include &lt;sys/stat.h>
         #include &lt;unistd.h>
         #define YY_EXTRA_TYPE  struct stat*
         %}
         %option reentrant
         %%
     
         __filesize__     printf( "%ld", yyextra->st_size  );
         __lastmod__      printf( "%ld", yyextra->st_mtime );
         %%
         void scan_file( char* filename )
         {
             yyscan_t scanner;
             struct stat buf;
     
             yylex_init ( &amp;scanner );
             yyset_in( fopen(filename,"r"), scanner );
     
             stat( filename, &amp;buf);
             yyset_extra( &amp;buf, scanner );
             yylex ( scanner );
             yylex_destroy( scanner );
        }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="About-yyscan_t"></a>
<a name="About-yyscan_005ft"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Extra-Data">Extra Data</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant-Detail">Reentrant Detail</a>

</div>

<h4 class="subsection">19.4.7 About yyscan_t</h4>

<p><a name="index-yyscan_005ft-_0028reentrant-only_0029-433"></a><code>yyscan_t</code> is defined as:

<pre class="example"><pre class="verbatim">     
          typedef void* yyscan_t;
</pre>
</pre>
   <p>It is initialized by <code>yylex_init()</code> to point to
an internal structure. You should never access this value
directly. In particular, you should never attempt to free it
(use <code>yylex_destroy()</code> instead.)

<div class="node">
<p><hr>
<a name="Reentrant-Functions"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant-Detail">Reentrant Detail</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Reentrant">Reentrant</a>

</div>

<h3 class="section">19.5 Functions and Macros Available in Reentrant C Scanners</h3>

<p>The following Functions are available in a reentrant scanner:

   <p><a name="index-yyget_005ftext-434"></a><a name="index-yyget_005fleng-435"></a><a name="index-yyget_005fin-436"></a><a name="index-yyget_005fout-437"></a><a name="index-yyget_005flineno-438"></a><a name="index-yyset_005fin-439"></a><a name="index-yyset_005fout-440"></a><a name="index-yyset_005flineno-441"></a><a name="index-yyget_005fdebug-442"></a><a name="index-yyset_005fdebug-443"></a><a name="index-yyget_005fextra-444"></a><a name="index-yyset_005fextra-445"></a>
<pre class="example"><pre class="verbatim">     
         char *yyget_text ( yyscan_t scanner );
         int yyget_leng ( yyscan_t scanner );
         FILE *yyget_in ( yyscan_t scanner );
         FILE *yyget_out ( yyscan_t scanner );
         int yyget_lineno ( yyscan_t scanner );
         YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
         int  yyget_debug ( yyscan_t scanner );
     
         void yyset_debug ( int flag, yyscan_t scanner );
         void yyset_in  ( FILE * in_str , yyscan_t scanner );
         void yyset_out  ( FILE * out_str , yyscan_t scanner );
         void yyset_lineno ( int line_number , yyscan_t scanner );
         void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t scanner );
</pre>
</pre>
   <p>There are no &ldquo;set&rdquo; functions for yytext and yyleng. This is intentional.

   <p>The following Macro shortcuts are available in actions in a reentrant
scanner:

<pre class="example"><pre class="verbatim">     
         yytext
         yyleng
         yyin
         yyout
         yylineno
         yyextra
         yy_flex_debug
</pre>
</pre>
   <p><a name="index-yylineno_002c-in-a-reentrant-scanner-446"></a>In a reentrant C scanner, support for yylineno is always present
(i.e., you may access yylineno), but the value is never modified by
<code>flex</code> unless <code>%option yylineno</code> is enabled. This is to allow
the user to maintain the line count independently of <code>flex</code>.

   <p><a name="bison_002dfunctions"></a>
The following functions and macros are made available when <code>%option
bison-bridge</code> (`<samp><span class="samp">--bison-bridge</span></samp>') is specified:

<pre class="example"><pre class="verbatim">     
         YYSTYPE * yyget_lval ( yyscan_t scanner );
         void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner );
         yylval
</pre>
</pre>
   <p>The following functions and macros are made available
when <code>%option bison-locations</code> (`<samp><span class="samp">--bison-locations</span></samp>') is specified:

<pre class="example"><pre class="verbatim">     
         YYLTYPE *yyget_lloc ( yyscan_t scanner );
         void yyset_lloc ( YYLTYPE * yyllocp , yyscan_t scanner );
         yylloc
</pre>
</pre>
   <p>Support for yylval assumes that <code>YYSTYPE</code> is a valid type.  Support for
yylloc assumes that <code>YYSLYPE</code> is a valid type.  Typically, these types are
generated by <code>bison</code>, and are included in section 1 of the <code>flex</code>
input.

<div class="node">
<p><hr>
<a name="Lex-and-Posix"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Memory-Management">Memory Management</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reentrant">Reentrant</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">20 Incompatibilities with Lex and Posix</h2>

<p><a name="index-POSIX-and-lex-447"></a><a name="index-lex-_0028traditional_0029-and-POSIX-448"></a>
<code>flex</code> is a rewrite of the AT&amp;T Unix <em>lex</em> tool (the two
implementations do not share any code, though), with some extensions and
incompatibilities, both of which are of concern to those who wish to
write scanners acceptable to both implementations.  <code>flex</code> is fully
compliant with the POSIX <code>lex</code> specification, except that when
using <code>%pointer</code> (the default), a call to <code>unput()</code> destroys
the contents of <code>yytext</code>, which is counter to the POSIX
specification.  In this section we discuss all of the known areas of
incompatibility between <code>flex</code>, AT&amp;T <code>lex</code>, and the POSIX
specification.  <code>flex</code>'s `<samp><span class="samp">-l</span></samp>' option turns on maximum
compatibility with the original AT&amp;T <code>lex</code> implementation, at the
cost of a major loss in the generated scanner's performance.  We note
below which incompatibilities can be overcome using the `<samp><span class="samp">-l</span></samp>'
option.  <code>flex</code> is fully compatible with <code>lex</code> with the
following exceptions:

     <ul>
<li>The undocumented <code>lex</code> scanner internal variable <code>yylineno</code> is
not supported unless `<samp><span class="samp">-l</span></samp>' or <code>%option yylineno</code> is used.

     <li><code>yylineno</code> should be maintained on a per-buffer basis, rather than
a per-scanner (single global variable) basis.

     <li><code>yylineno</code> is not part of the POSIX specification.

     <li>The <code>input()</code> routine is not redefinable, though it may be called
to read characters following whatever has been matched by a rule.  If
<code>input()</code> encounters an end-of-file the normal <code>yywrap()</code>
processing is done.  A &ldquo;real&rdquo; end-of-file is returned by
<code>input()</code> as <code>EOF</code>.

     <li>Input is instead controlled by defining the <code>YY_INPUT()</code> macro.

     <li>The <code>flex</code> restriction that <code>input()</code> cannot be redefined is
in accordance with the POSIX specification, which simply does not
specify any way of controlling the scanner's input other than by making
an initial assignment to <samp><span class="file">yyin</span></samp>.

     <li>The <code>unput()</code> routine is not redefinable.  This restriction is in
accordance with POSIX.

     <li><code>flex</code> scanners are not as reentrant as <code>lex</code> scanners.  In
particular, if you have an interactive scanner and an interrupt handler
which long-jumps out of the scanner, and the scanner is subsequently
called again, you may get the following message:

     <p><a name="index-error-messages_002c-end-of-buffer-missed-449"></a>
     <pre class="example">     <pre class="verbatim">          
              fatal @code{flex} scanner internal error--end of buffer missed
     </pre>
     </pre>
     <p>To reenter the scanner, first use:

     <p><a name="index-restarting-the-scanner-450"></a>
     <pre class="example">     <pre class="verbatim">          
              yyrestart( yyin );
     </pre>
     </pre>
     <p>Note that this call will throw away any buffered input; usually this
isn't a problem with an interactive scanner. See <a href="#Reentrant">Reentrant</a>, for
<code>flex</code>'s reentrant API.

     <li>Also note that <code>flex</code> C++ scanner classes
<em>are</em>
reentrant, so if using C++ is an option for you, you should use
them instead.  See <a href="#Cxx">Cxx</a>, and <a href="#Reentrant">Reentrant</a>  for details.

     <li><code>output()</code> is not supported.  Output from the <b>ECHO</b> macro is
done to the file-pointer <code>yyout</code> (default <samp><span class="file">stdout)</span></samp>.

     <li><code>output()</code> is not part of the POSIX specification.

     <li><code>lex</code> does not support exclusive start conditions (%x), though they
are in the POSIX specification.

     <li>When definitions are expanded, <code>flex</code> encloses them in parentheses. 
With <code>lex</code>, the following:

     <p><a name="index-name-definitions_002c-not-POSIX-451"></a>
     <pre class="example">     <pre class="verbatim">          
              NAME    [A-Z][A-Z0-9]*
              %%
              foo{NAME}?      printf( "Found it\n" );
              %%
     </pre>
     </pre>
     <p>will not match the string `<samp><span class="samp">foo</span></samp>' because when the macro is expanded
the rule is equivalent to `<samp><span class="samp">foo[A-Z][A-Z0-9]*?</span></samp>'  and the precedence
is such that the `<samp><span class="samp">?</span></samp>' is associated with `<samp><span class="samp">[A-Z0-9]*</span></samp>'.  With
<code>flex</code>, the rule will be expanded to `<samp><span class="samp">foo([A-Z][A-Z0-9]*)?</span></samp>'
and so the string `<samp><span class="samp">foo</span></samp>' will match.

     <li>Note that if the definition begins with `<samp><span class="samp">^</span></samp>' or ends with `<samp><span class="samp">$</span></samp>'
then it is <em>not</em> expanded with parentheses, to allow these
operators to appear in definitions without losing their special
meanings.  But the `<samp><span class="samp">&lt;s&gt;</span></samp>', `<samp><span class="samp">/</span></samp>', and <code>&lt;&lt;EOF&gt;&gt;</code> operators
cannot be used in a <code>flex</code> definition.

     <li>Using `<samp><span class="samp">-l</span></samp>' results in the <code>lex</code> behavior of no parentheses
around the definition.

     <li>The POSIX specification is that the definition be enclosed in parentheses.

     <li>Some implementations of <code>lex</code> allow a rule's action to begin on a
separate line, if the rule's pattern has trailing whitespace:

     <p><a name="index-patterns-and-actions-on-different-lines-452"></a>
     <pre class="example">     <pre class="verbatim">          
              %%
              foo|bar&lt;space here>
                { foobar_action();}
     </pre>
     </pre>
     <p><code>flex</code> does not support this feature.

     <li>The <code>lex</code> <code>%r</code> (generate a Ratfor scanner) option is not
supported.  It is not part of the POSIX specification.

     <li>After a call to <code>unput()</code>, <em>yytext</em> is undefined until the
next token is matched, unless the scanner was built using <code>%array</code>. 
This is not the case with <code>lex</code> or the POSIX specification.  The
`<samp><span class="samp">-l</span></samp>' option does away with this incompatibility.

     <li>The precedence of the `<samp><span class="samp">{,}</span></samp>' (numeric range) operator is
different.  The AT&amp;T and POSIX specifications of <code>lex</code>
interpret `<samp><span class="samp">abc{1,3}</span></samp>' as match one, two,
or three occurrences of `<samp><span class="samp">abc</span></samp>'&rdquo;, whereas <code>flex</code> interprets it
as &ldquo;match `<samp><span class="samp">ab</span></samp>' followed by one, two, or three occurrences of
`<samp><span class="samp">c</span></samp>'&rdquo;.  The `<samp><span class="samp">-l</span></samp>' and `<samp><span class="samp">--posix</span></samp>' options do away with this
incompatibility.

     <li>The precedence of the `<samp><span class="samp">^</span></samp>' operator is different.  <code>lex</code>
interprets `<samp><span class="samp">^foo|bar</span></samp>' as &ldquo;match either 'foo' at the beginning of a
line, or 'bar' anywhere&rdquo;, whereas <code>flex</code> interprets it as &ldquo;match
either `<samp><span class="samp">foo</span></samp>' or `<samp><span class="samp">bar</span></samp>' if they come at the beginning of a
line&rdquo;.  The latter is in agreement with the POSIX specification.

     <li>The special table-size declarations such as <code>%a</code> supported by
<code>lex</code> are not required by <code>flex</code> scanners..  <code>flex</code>
ignores them. 
<li>The name <code>FLEX_SCANNER</code> is <code>#define</code>'d so scanners may be
written for use with either <code>flex</code> or <code>lex</code>.  Scanners also
include <code>YY_FLEX_MAJOR_VERSION</code>,  <code>YY_FLEX_MINOR_VERSION</code>
and <code>YY_FLEX_SUBMINOR_VERSION</code>
indicating which version of <code>flex</code> generated the scanner. For
example, for the 2.5.22 release, these defines would be 2,  5 and 22
respectively. If the version of <code>flex</code> being used is a beta
version, then the symbol <code>FLEX_BETA</code> is defined. 
</ul>

   <p><a name="index-POSIX-comp_003bcompliance-453"></a><a name="index-non_002dPOSIX-features-of-flex-454"></a>The following <code>flex</code> features are not included in <code>lex</code> or the
POSIX specification:

     <ul>
<li>C++ scanners
<li>%option
<li>start condition scopes
<li>start condition stacks
<li>interactive/non-interactive scanners
<li>yy_scan_string() and friends
<li>yyterminate()
<li>yy_set_interactive()
<li>yy_set_bol()
<li>YY_AT_BOL()
   &lt;&lt;EOF&gt;&gt;
<li>&lt;*&gt;
<li>YY_DECL
<li>YY_START
<li>YY_USER_ACTION
<li>YY_USER_INIT
<li>#line directives
<li>%{}'s around actions
<li>reentrant C API
<li>multiple actions on a line
<li>almost all of the <code>flex</code> command-line options
</ul>

   <p>The feature &ldquo;multiple actions on a line&rdquo;
refers to the fact that with <code>flex</code> you can put multiple actions on
the same line, separated with semi-colons, while with <code>lex</code>, the
following:

<pre class="example"><pre class="verbatim">     
         foo    handle_foo(); ++num_foos_seen;
</pre>
</pre>
   <p>is (rather surprisingly) truncated to

<pre class="example"><pre class="verbatim">     
         foo    handle_foo();
</pre>
</pre>
   <p><code>flex</code> does not truncate the action.  Actions that are not enclosed
in braces are simply terminated at the end of the line.

<div class="node">
<p><hr>
<a name="Memory-Management"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Serialized-Tables">Serialized Tables</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Lex-and-Posix">Lex and Posix</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">21 Memory Management</h2>

<p><a name="index-memory-management-455"></a><a name="memory_002dmanagement"></a>
This chapter describes how flex handles dynamic memory, and how you can
override the default behavior.

<ul class="menu">
<li><a accesskey="1" href="#The-Default-Memory-Management">The Default Memory Management</a>
<li><a accesskey="2" href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a>
<li><a accesskey="3" href="#A-Note-About-yytext-And-Memory">A Note About yytext And Memory</a>
</ul>

<div class="node">
<p><hr>
<a name="The-Default-Memory-Management"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Memory-Management">Memory Management</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Memory-Management">Memory Management</a>

</div>

<h3 class="section">21.1 The Default Memory Management</h3>

<p>Flex allocates dynamic memory during initialization, and once in a while from
within a call to yylex(). Initialization takes place during the first call to
yylex(). Thereafter, flex may reallocate more memory if it needs to enlarge a
buffer. As of version 2.5.9 Flex will clean up all memory when you call <code>yylex_destroy</code>
See <a href="#faq_002dmemory_002dleak">faq-memory-leak</a>.

   <p>Flex allocates dynamic memory for four purposes, listed below <a rel="footnote" href="#fn-2" name="fnd-2"><sup>2</sup></a>

     <dl>
<dt>16kB for the input buffer.<dd>Flex allocates memory for the character buffer used to perform pattern
matching.  Flex must read ahead from the input stream and store it in a large
character buffer.  This buffer is typically the largest chunk of dynamic memory
flex consumes. This buffer will grow if necessary, doubling the size each time. 
Flex frees this memory when you call yylex_destroy().  The default size of this
buffer (16384 bytes) is almost always too large.  The ideal size for this
buffer is the length of the longest token expected.  Flex will allocate a few
extra bytes for housekeeping.

     <br><dt>16kb for the REJECT state. This will only be allocated if you use REJECT.<dd>The size is the same as the input buffer, so if you override the size of the
input buffer, then you automatically override the size of this buffer as well.

     <br><dt>100 bytes for the start condition stack.<dd>Flex allocates memory for the start condition stack. This is the stack used
for pushing start states, i.e., with yy_push_state(). It will grow if
necessary.  Since the states are simply integers, this stack doesn't consume
much memory.  This stack is not present if <code>%option stack</code> is not
specified.  You will rarely need to tune this buffer. The ideal size for this
stack is the maximum depth expected.  The memory for this stack is
automatically destroyed when you call yylex_destroy(). See <a href="#option_002dstack">option-stack</a>.

     <br><dt>40 bytes for each YY_BUFFER_STATE.<dd>Flex allocates memory for each YY_BUFFER_STATE. The buffer state itself
is about 40 bytes, plus an additional large character buffer (described above.) 
The initial buffer state is created during initialization, and with each call
to yy_create_buffer(). You can't tune the size of this, but you can tune the
character buffer as described above. Any buffer state that you explicitly
create by calling yy_create_buffer() is <em>NOT</em> destroyed automatically. You
must call yy_delete_buffer() to free the memory. The exception to this rule is
that flex will delete the current buffer automatically when you call
yylex_destroy(). If you delete the current buffer, be sure to set it to NULL. 
That way, flex will not try to delete the buffer a second time (possibly
crashing your program!) At the time of this writing, flex does not provide a
growable stack for the buffer states.  You have to manage that yourself. 
See <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a>.

     <br><dt>84 bytes for the reentrant scanner guts<dd>Flex allocates about 84 bytes for the reentrant scanner structure when
you call yylex_init(). It is destroyed when the user calls yylex_destroy().

   </dl>

<div class="node">
<p><hr>
<a name="Overriding-The-Default-Memory-Management"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#A-Note-About-yytext-And-Memory">A Note About yytext And Memory</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#The-Default-Memory-Management">The Default Memory Management</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Memory-Management">Memory Management</a>

</div>

<h3 class="section">21.2 Overriding The Default Memory Management</h3>

<p><a name="index-yyalloc_002c-overriding-456"></a><a name="index-yyrealloc_002c-overriding-457"></a><a name="index-yyfree_002c-overriding-458"></a>
Flex calls the functions <code>yyalloc</code>, <code>yyrealloc</code>, and <code>yyfree</code>
when it needs to allocate or free memory. By default, these functions are
wrappers around the standard C functions, <code>malloc</code>, <code>realloc</code>, and
<code>free</code>, respectively. You can override the default implementations by telling
flex that you will provide your own implementations.

   <p>To override the default implementations, you must do two things:

     <ol type=1 start=1>

     <li>Suppress the default implementations by specifying one or more of the
following options:

          
<a name="index-noyyalloc-459"></a>
<ul><li><code>%option noyyalloc</code>
<li><code>%option noyyrealloc</code>
<li><code>%option noyyfree</code>. 
</ul>

     <li>Provide your own implementation of the following functions: <a rel="footnote" href="#fn-3" name="fnd-3"><sup>3</sup></a>

     <pre class="example">     <pre class="verbatim">          
          // For a non-reentrant scanner
          void * yyalloc (size_t bytes);
          void * yyrealloc (void * ptr, size_t bytes);
          void   yyfree (void * ptr);
          
          // For a reentrant scanner
          void * yyalloc (size_t bytes, void * yyscanner);
          void * yyrealloc (void * ptr, size_t bytes, void * yyscanner);
          void   yyfree (void * ptr, void * yyscanner);
     </pre>
     </pre>
        </ol>

   <p>In the following example, we will override all three memory routines. We assume
that there is a custom allocator with garbage collection. In order to make this
example interesting, we will use a reentrant scanner, passing a pointer to the
custom allocator through <code>yyextra</code>.

   <p><a name="index-overriding-the-memory-routines-460"></a>
<pre class="example"><pre class="verbatim">     
     %{
     #include "some_allocator.h"
     %}
     
     /* Suppress the default implementations. */
     %option noyyalloc noyyrealloc noyyfree
     %option reentrant
     
     /* Initialize the allocator. */
     #define YY_EXTRA_TYPE  struct allocator*
     #define YY_USER_INIT  yyextra = allocator_create();
     
     %%
     .|\n   ;
     %%
     
     /* Provide our own implementations. */
     void * yyalloc (size_t bytes, void* yyscanner) {
         return allocator_alloc (yyextra, bytes);
     }
     
     void * yyrealloc (void * ptr, size_t bytes, void* yyscanner) {
         return allocator_realloc (yyextra, bytes);
     }
     
     void yyfree (void * ptr, void * yyscanner) {      
         /* Do nothing -- we leave it to the garbage collector. */
     }
     
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="A-Note-About-yytext-And-Memory"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Memory-Management">Memory Management</a>

</div>

<h3 class="section">21.3 A Note About yytext And Memory</h3>

<p><a name="index-yytext_002c-memory-considerations-461"></a>
When flex finds a match, <code>yytext</code> points to the first character of the
match in the input buffer. The string itself is part of the input buffer, and
is <em>NOT</em> allocated separately. The value of yytext will be overwritten the next
time yylex() is called. In short, the value of yytext is only valid from within
the matched rule's action.

   <p>Often, you want the value of yytext to persist for later processing, i.e., by a
parser with non-zero lookahead. In order to preserve yytext, you will have to
copy it with strdup() or a similar function. But this introduces some headache
because your parser is now responsible for freeing the copy of yytext. If you
use a yacc or bison parser, (commonly used with flex), you will discover that
the error recovery mechanisms can cause memory to be leaked.

   <p>To prevent memory leaks from strdup'd yytext, you will have to track the memory
somehow. Our experience has shown that a garbage collection mechanism or a
pooled memory mechanism will save you a lot of grief when writing parsers.

<div class="node">
<p><hr>
<a name="Serialized-Tables"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Diagnostics">Diagnostics</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Memory-Management">Memory Management</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">22 Serialized Tables</h2>

<p><a name="index-serialization-462"></a><a name="index-memory_002c-serialized-tables-463"></a>
<a name="serialization"></a>
A <code>flex</code> scanner has the ability to save the DFA tables to a file, and
load them at runtime when needed.  The motivation for this feature is to reduce
the runtime memory footprint.  Traditionally, these tables have been compiled into
the scanner as C arrays, and are sometimes quite large.  Since the tables are
compiled into the scanner, the memory used by the tables can never be freed. 
This is a waste of memory, especially if an application uses several scanners,
but none of them at the same time.

   <p>The serialization feature allows the tables to be loaded at runtime, before
scanning begins. The tables may be discarded when scanning is finished.

<ul class="menu">
<li><a accesskey="1" href="#Creating-Serialized-Tables">Creating Serialized Tables</a>
<li><a accesskey="2" href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a>
<li><a accesskey="3" href="#Tables-File-Format">Tables File Format</a>
</ul>

<div class="node">
<p><hr>
<a name="Creating-Serialized-Tables"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Serialized-Tables">Serialized Tables</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Serialized-Tables">Serialized Tables</a>

</div>

<h3 class="section">22.1 Creating Serialized Tables</h3>

<p><a name="index-tables_002c-creating-serialized-464"></a><a name="index-serialization-of-tables-465"></a>
You may create a scanner with serialized tables by specifying:

<pre class="example"><pre class="verbatim">     
         %option tables-file=FILE
     or
         --tables-file=FILE
</pre>
</pre>
   <p>These options instruct flex to save the DFA tables to the file <var>FILE</var>. The tables
will <em>not</em> be embedded in the generated scanner. The scanner will not
function on its own. The scanner will be dependent upon the serialized tables. You must
load the tables from this file at runtime before you can scan anything.

   <p>If you do not specify a filename to <code>--tables-file</code>, the tables will be
saved to <samp><span class="file">lex.yy.tables</span></samp>, where `<samp><span class="samp">yy</span></samp>' is the appropriate prefix.

   <p>If your project uses several different scanners, you can concatenate the
serialized tables into one file, and flex will find the correct set of tables,
using the scanner prefix as part of the lookup key. An example follows:

   <p><a name="index-serialized-tables_002c-multiple-scanners-466"></a>
<pre class="example"><pre class="verbatim">     
     $ flex --tables-file --prefix=cpp cpp.l
     $ flex --tables-file --prefix=c   c.l
     $ cat lex.cpp.tables lex.c.tables  >  all.tables
</pre>
</pre>
   <p>The above example created two scanners, `<samp><span class="samp">cpp</span></samp>', and `<samp><span class="samp">c</span></samp>'. Since we did
not specify a filename, the tables were serialized to <samp><span class="file">lex.c.tables</span></samp> and
<samp><span class="file">lex.cpp.tables</span></samp>, respectively. Then, we concatenated the two files
together into <samp><span class="file">all.tables</span></samp>, which we will distribute with our project. At
runtime, we will open the file and tell flex to load the tables from it.  Flex
will find the correct tables automatically. (See next section).

<div class="node">
<p><hr>
<a name="Loading-and-Unloading-Serialized-Tables"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Tables-File-Format">Tables File Format</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Creating-Serialized-Tables">Creating Serialized Tables</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Serialized-Tables">Serialized Tables</a>

</div>

<h3 class="section">22.2 Loading and Unloading Serialized Tables</h3>

<p><a name="index-tables_002c-loading-and-unloading-467"></a><a name="index-loading-tables-at-runtime-468"></a><a name="index-tables_002c-freeing-469"></a><a name="index-freeing-tables-470"></a><a name="index-memory_002c-serialized-tables-471"></a>
If you've built your scanner with <code>%option tables-file</code>, then you must
load the scanner tables at runtime. This can be accomplished with the following
function:

<div class="defun">
&mdash; Function: int <b>yytables_fload</b> (<var>FILE* fp </var>[<var>, yyscan_t scanner</var>])<var><a name="index-yytables_005ffload-472"></a></var><br>
<blockquote><p>Locates scanner tables in the stream pointed to by <var>fp</var> and loads them. 
Memory for the tables is allocated via <code>yyalloc</code>.  You must call this
function before the first call to <code>yylex</code>. The argument <var>scanner</var>
only appears in the reentrant scanner. 
This function returns `<samp><span class="samp">0</span></samp>' (zero) on success, or non-zero on error. 
</p></blockquote></div>

   <p>The loaded tables are <strong>not</strong> automatically destroyed (unloaded) when you
call <code>yylex_destroy</code>. The reason is that you may create several scanners
of the same type (in a reentrant scanner), each of which needs access to these
tables.  To avoid a nasty memory leak, you must call the following function:

<div class="defun">
&mdash; Function: int <b>yytables_destroy</b> ([<var>yyscan_t scanner</var>])<var><a name="index-yytables_005fdestroy-473"></a></var><br>
<blockquote><p>Unloads the scanner tables. The tables must be loaded again before you can scan
any more data.  The argument <var>scanner</var> only appears in the reentrant
scanner.  This function returns `<samp><span class="samp">0</span></samp>' (zero) on success, or non-zero on
error. 
</p></blockquote></div>

   <p><strong>The functions </strong><code>yytables_fload</code><strong> and </strong><code>yytables_destroy</code><strong> are not
thread-safe.</strong> You must ensure that these functions are called exactly once (for
each scanner type) in a threaded program, before any thread calls <code>yylex</code>. 
After the tables are loaded, they are never written to, and no thread
protection is required thereafter &ndash; until you destroy them.

<div class="node">
<p><hr>
<a name="Tables-File-Format"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Serialized-Tables">Serialized Tables</a>

</div>

<h3 class="section">22.3 Tables File Format</h3>

<p><a name="index-tables_002c-file-format-474"></a><a name="index-file-format_002c-serialized-tables-475"></a>
This section defines the file format of serialized <code>flex</code> tables.

   <p>The tables format allows for one or more sets of tables to be
specified, where each set corresponds to a given scanner. Scanners are
indexed by name, as described below. The file format is as follows:

<pre class="example"><pre class="verbatim">     
                      TABLE SET 1
                     +-------------------------------+
             Header  | uint32          th_magic;     |
                     | uint32          th_hsize;     |
                     | uint32          th_ssize;     |
                     | uint16          th_flags;     |
                     | char            th_version[]; |
                     | char            th_name[];    |
                     | uint8           th_pad64[];   |
                     +-------------------------------+
             Table 1 | uint16          td_id;        |
                     | uint16          td_flags;     |
                     | uint32          td_lolen;     |
                     | uint32          td_hilen;     |
                     | void            td_data[];    |
                     | uint8           td_pad64[];   |
                     +-------------------------------+
             Table 2 |                               |
                .    .                               .
                .    .                               .
                .    .                               .
                .    .                               .
             Table n |                               |
                     +-------------------------------+
                      TABLE SET 2
                           .
                           .
                           .
                      TABLE SET N
</pre>
</pre>
   <p>The above diagram shows that a complete set of tables consists of a header
followed by multiple individual tables. Furthermore, multiple complete sets may
be present in the same file, each set with its own header and tables. The sets
are contiguous in the file. The only way to know if another set follows is to
check the next four bytes for the magic number (or check for EOF). The header
and tables sections are padded to 64-bit boundaries. Below we describe each
field in detail. This format does not specify how the scanner will expand the
given data, i.e., data may be serialized as int8, but expanded to an int32
array at runtime. This is to reduce the size of the serialized data where
possible.  Remember, <em>all integer values are in network byte order</em>.

<p class="noindent">Fields of a table header:

     <dl>
<dt><code>th_magic</code><dd>Magic number, always 0xF13C57B1.

     <br><dt><code>th_hsize</code><dd>Size of this entire header, in bytes, including all fields plus any padding.

     <br><dt><code>th_ssize</code><dd>Size of this entire set, in bytes, including the header, all tables, plus
any padding.

     <br><dt><code>th_flags</code><dd>Bit flags for this table set. Currently unused.

     <br><dt><code>th_version[]</code><dd>Flex version in NULL-termninated string format. e.g., `<samp><span class="samp">2.5.13a</span></samp>'. This is
the version of flex that was used to create the serialized tables.

     <br><dt><code>th_name[]</code><dd>Contains the name of this table set. The default is `<samp><span class="samp">yytables</span></samp>',
and is prefixed accordingly, e.g., `<samp><span class="samp">footables</span></samp>'. Must be NULL-terminated.

     <br><dt><code>th_pad64[]</code><dd>Zero or more NULL bytes, padding the entire header to the next 64-bit boundary
as calculated from the beginning of the header. 
</dl>

<p class="noindent">Fields of a table:

     <dl>
<dt><code>td_id</code><dd>Specifies the table identifier. Possible values are:
          <dl>
<dt><code>YYTD_ID_ACCEPT (0x01)</code><dd><code>yy_accept</code>
<br><dt><code>YYTD_ID_BASE   (0x02)</code><dd><code>yy_base</code>
<br><dt><code>YYTD_ID_CHK    (0x03)</code><dd><code>yy_chk</code>
<br><dt><code>YYTD_ID_DEF    (0x04)</code><dd><code>yy_def</code>
<br><dt><code>YYTD_ID_EC     (0x05)</code><dd><code>yy_ec </code>
<br><dt><code>YYTD_ID_META   (0x06)</code><dd><code>yy_meta</code>
<br><dt><code>YYTD_ID_NUL_TRANS (0x07)</code><dd><code>yy_NUL_trans</code>
<br><dt><code>YYTD_ID_NXT (0x08)</code><dd><code>yy_nxt</code>. This array may be two dimensional. See the <code>td_hilen</code>
field below. 
<br><dt><code>YYTD_ID_RULE_CAN_MATCH_EOL (0x09)</code><dd><code>yy_rule_can_match_eol</code>
<br><dt><code>YYTD_ID_START_STATE_LIST (0x0A)</code><dd><code>yy_start_state_list</code>. This array is handled specially because it is an
array of pointers to structs. See the <code>td_flags</code> field below. 
<br><dt><code>YYTD_ID_TRANSITION (0x0B)</code><dd><code>yy_transition</code>. This array is handled specially because it is an array of
structs. See the <code>td_lolen</code> field below. 
<br><dt><code>YYTD_ID_ACCLIST (0x0C)</code><dd><code>yy_acclist</code>
</dl>

     <br><dt><code>td_flags</code><dd>Bit flags describing how to interpret the data in <code>td_data</code>. 
The data arrays are one-dimensional by default, but may be
two dimensional as specified in the <code>td_hilen</code> field.

          <dl>
<dt><code>YYTD_DATA8 (0x01)</code><dd>The data is serialized as an array of type int8. 
<br><dt><code>YYTD_DATA16 (0x02)</code><dd>The data is serialized as an array of type int16. 
<br><dt><code>YYTD_DATA32 (0x04)</code><dd>The data is serialized as an array of type int32. 
<br><dt><code>YYTD_PTRANS (0x08)</code><dd>The data is a list of indexes of entries in the expanded <code>yy_transition</code>
array.  Each index should be expanded to a pointer to the corresponding entry
in the <code>yy_transition</code> array. We count on the fact that the
<code>yy_transition</code> array has already been seen. 
<br><dt><code>YYTD_STRUCT (0x10)</code><dd>The data is a list of yy_trans_info structs, each of which consists of
two integers. There is no padding between struct elements or between structs. 
The type of each member is determined by the <code>YYTD_DATA*</code> bits. 
</dl>

     <br><dt><code>td_lolen</code><dd>Specifies the number of elements in the lowest dimension array. If this is
a one-dimensional array, then it is simply the number of elements in this array. 
The element size is determined by the <code>td_flags</code> field.

     <br><dt><code>td_hilen</code><dd>If <code>td_hilen</code> is non-zero, then the data is a two-dimensional array. 
Otherwise, the data is a one-dimensional array. <code>td_hilen</code> contains the
number of elements in the higher dimensional array, and <code>td_lolen</code> contains
the number of elements in the lowest dimension.

     <p>Conceptually, <code>td_data</code> is either <code>sometype td_data[td_lolen]</code>, or
<code>sometype td_data[td_hilen][td_lolen]</code>, where <code>sometype</code> is specified
by the <code>td_flags</code> field.  It is possible for both <code>td_lolen</code> and
<code>td_hilen</code> to be zero, in which case <code>td_data</code> is a zero length
array, and no data is loaded, i.e., this table is simply skipped. Flex does not
currently generate tables of zero length.

     <br><dt><code>td_data[]</code><dd>The table data. This array may be a one- or two-dimensional array, of type
<code>int8</code>, <code>int16</code>, <code>int32</code>, <code>struct yy_trans_info</code>, or
<code>struct yy_trans_info*</code>,  depending upon the values in the
<code>td_flags</code>, <code>td_lolen</code>, and <code>td_hilen</code> fields.

     <br><dt><code>td_pad64[]</code><dd>Zero or more NULL bytes, padding the entire table to the next 64-bit boundary as
calculated from the beginning of this table. 
</dl>

<div class="node">
<p><hr>
<a name="Diagnostics"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Limitations">Limitations</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Serialized-Tables">Serialized Tables</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">23 Diagnostics</h2>

<p><a name="index-error-reporting_002c-diagnostic-messages-476"></a><a name="index-warnings_002c-diagnostic-messages-477"></a>
The following is a list of <code>flex</code> diagnostic messages:

     <ul>
<li>`<samp><span class="samp">warning, rule cannot be matched</span></samp>' indicates that the given rule
cannot be matched because it follows other rules that will always match
the same text as it.  For example, in the following `<samp><span class="samp">foo</span></samp>' cannot be
matched because it comes after an identifier &ldquo;catch-all&rdquo; rule:

     <p><a name="index-warning_002c-rule-cannot-be-matched-478"></a>
     <pre class="example">     <pre class="verbatim">          
              [a-z]+    got_identifier();
              foo       got_foo();
     </pre>
     </pre>
     <p>Using <code>REJECT</code> in a scanner suppresses this warning.

     <li>`<samp><span class="samp">warning, -s option given but default rule can be matched</span></samp>' means
that it is possible (perhaps only in a particular start condition) that
the default rule (match any single character) is the only one that will
match a particular input.  Since `<samp><span class="samp">-s</span></samp>' was given, presumably this is
not intended.

     <li><code>reject_used_but_not_detected undefined</code> or
<code>yymore_used_but_not_detected undefined</code>. These errors can occur
at compile time.  They indicate that the scanner uses <code>REJECT</code> or
<code>yymore()</code> but that <code>flex</code> failed to notice the fact, meaning
that <code>flex</code> scanned the first two sections looking for occurrences
of these actions and failed to find any, but somehow you snuck some in
(via a #include file, for example).  Use <code>%option reject</code> or
<code>%option yymore</code> to indicate to <code>flex</code> that you really do use
these features.

     <li>`<samp><span class="samp">flex scanner jammed</span></samp>'. a scanner compiled with
`<samp><span class="samp">-s</span></samp>' has encountered an input string which wasn't matched by any of
its rules.  This error can also occur due to internal problems.

     <li>`<samp><span class="samp">token too large, exceeds YYLMAX</span></samp>'. your scanner uses <code>%array</code>
and one of its rules matched a string longer than the <code>YYLMAX</code>
constant (8K bytes by default).  You can increase the value by
#define'ing <code>YYLMAX</code> in the definitions section of your <code>flex</code>
input.

     <li>`<samp><span class="samp">scanner requires -8 flag to use the character 'x'</span></samp>'. Your scanner
specification includes recognizing the 8-bit character `<samp><span class="samp">'x'</span></samp>' and
you did not specify the -8 flag, and your scanner defaulted to 7-bit
because you used the `<samp><span class="samp">-Cf</span></samp>' or `<samp><span class="samp">-CF</span></samp>' table compression options. 
See the discussion of the `<samp><span class="samp">-7</span></samp>' flag, <a href="#Scanner-Options">Scanner Options</a>, for
details.

     <li>`<samp><span class="samp">flex scanner push-back overflow</span></samp>'. you used <code>unput()</code> to push
back so much text that the scanner's buffer could not hold both the
pushed-back text and the current token in <code>yytext</code>.  Ideally the
scanner should dynamically resize the buffer in this case, but at
present it does not.

     <li>`<samp><span class="samp">input buffer overflow, can't enlarge buffer because scanner uses
REJECT</span></samp>'.  the scanner was working on matching an extremely large token
and needed to expand the input buffer.  This doesn't work with scanners
that use <code>REJECT</code>.

     <li>`<samp><span class="samp">fatal flex scanner internal error--end of buffer missed</span></samp>'. This can
occur in a scanner which is reentered after a long-jump has jumped out
(or over) the scanner's activation frame.  Before reentering the
scanner, use:
     <pre class="example">     <pre class="verbatim">          
              yyrestart( yyin );
     </pre>
     </pre>
     <p>or, as noted above, switch to using the C++ scanner class.

     <li>`<samp><span class="samp">too many start conditions in &lt;&gt; construct!</span></samp>'  you listed more start
conditions in a &lt;&gt; construct than exist (so you must have listed at
least one of them twice). 
</ul>

<div class="node">
<p><hr>
<a name="Limitations"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Bibliography">Bibliography</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Diagnostics">Diagnostics</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">24 Limitations</h2>

<p><a name="index-limitations-of-flex-479"></a>
Some trailing context patterns cannot be properly matched and generate
warning messages (`<samp><span class="samp">dangerous trailing context</span></samp>').  These are
patterns where the ending of the first part of the rule matches the
beginning of the second part, such as `<samp><span class="samp">zx*/xy*</span></samp>', where the 'x*'
matches the 'x' at the beginning of the trailing context.  (Note that
the POSIX draft states that the text matched by such patterns is
undefined.)  For some trailing context rules, parts which are actually
fixed-length are not recognized as such, leading to the abovementioned
performance loss.  In particular, parts using `<samp><span class="samp">|</span></samp>' or `<samp><span class="samp">{n}</span></samp>'
(such as `<samp><span class="samp">foo{3}</span></samp>') are always considered variable-length. 
Combining trailing context with the special `<samp><span class="samp">|</span></samp>' action can result
in <em>fixed</em> trailing context being turned into the more expensive
<em>variable</em> trailing context.  For example, in the following:

   <p><a name="index-warning_002c-dangerous-trailing-context-480"></a>
<pre class="example"><pre class="verbatim">     
         %%
         abc      |
         xyz/def
</pre>
</pre>
   <p>Use of <code>unput()</code> invalidates yytext and yyleng, unless the
<code>%array</code> directive or the `<samp><span class="samp">-l</span></samp>' option has been used. 
Pattern-matching of <code>NUL</code>s is substantially slower than matching
other characters.  Dynamic resizing of the input buffer is slow, as it
entails rescanning all the text matched so far by the current (generally
huge) token.  Due to both buffering of input and read-ahead, you cannot
intermix calls to <samp><span class="file">&lt;stdio.h&gt;</span></samp> routines, such as, <b>getchar()</b>,
with <code>flex</code> rules and expect it to work.  Call <code>input()</code>
instead.  The total table entries listed by the `<samp><span class="samp">-v</span></samp>' flag excludes
the number of table entries needed to determine what rule has been
matched.  The number of entries is equal to the number of DFA states if
the scanner does not use <code>REJECT</code>, and somewhat greater than the
number of states if it does.  <code>REJECT</code> cannot be used with the
`<samp><span class="samp">-f</span></samp>' or `<samp><span class="samp">-F</span></samp>' options.

   <p>The <code>flex</code> internal algorithms need documentation.

<div class="node">
<p><hr>
<a name="Bibliography"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#FAQ">FAQ</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Limitations">Limitations</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">25 Additional Reading</h2>

<p>You may wish to read more about the following programs:
     <ul>
<li>lex
<li>yacc
<li>sed
<li>awk
</ul>

   <p>The following books may contain material of interest:

   <p>John Levine, Tony Mason, and Doug Brown,
<em>Lex &amp; Yacc</em>,
O'Reilly and Associates.  Be sure to get the 2nd edition.

   <p>M. E. Lesk and E. Schmidt,
<em>LEX &ndash; Lexical Analyzer Generator</em>

   <p>Alfred Aho, Ravi Sethi and Jeffrey Ullman, <em>Compilers: Principles,
Techniques and Tools</em>, Addison-Wesley (1986).  Describes the
pattern-matching techniques used by <code>flex</code> (deterministic finite
automata).

<div class="node">
<p><hr>
<a name="FAQ"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Appendices">Appendices</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Bibliography">Bibliography</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="unnumbered">FAQ</h2>

<p>From time to time, the <code>flex</code> maintainer receives certain
questions. Rather than repeat answers to well-understood problems, we
publish them here.

<ul class="menu">
<li><a accesskey="1" href="#When-was-flex-born_003f">When was flex born?</a>
<li><a accesskey="2" href="#How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f">How do I expand \ escape sequences in C-style quoted strings?</a>
<li><a accesskey="3" href="#Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f">Why do flex scanners call fileno if it is not ANSI compatible?</a>
<li><a accesskey="4" href="#Does-flex-support-recursive-pattern-definitions_003f">Does flex support recursive pattern definitions?</a>
<li><a accesskey="5" href="#How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f">How do I skip huge chunks of input (tens of megabytes) while using flex?</a>
<li><a accesskey="6" href="#Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e">Flex is not matching my patterns in the same order that I defined them.</a>
<li><a accesskey="7" href="#My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e">My actions are executing out of order or sometimes not at all.</a>
<li><a accesskey="8" href="#How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f">How can I have multiple input sources feed into the same scanner at the same time?</a>
<li><a accesskey="9" href="#Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f">Can I build nested parsers that work with the same input file?</a>
<li><a href="#How-can-I-match-text-only-at-the-end-of-a-file_003f">How can I match text only at the end of a file?</a>
<li><a href="#How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f">How can I make REJECT cascade across start condition boundaries?</a>
<li><a href="#Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f">Why cant I use fast or full tables with interactive mode?</a>
<li><a href="#How-much-faster-is-_002dF-or-_002df-than-_002dC_003f">How much faster is -F or -f than -C?</a>
<li><a href="#If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f">If I have a simple grammar cant I just parse it with flex?</a>
<li><a href="#Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f">Why doesnt yyrestart() set the start state back to INITIAL?</a>
<li><a href="#How-can-I-match-C_002dstyle-comments_003f">How can I match C-style comments?</a>
<li><a href="#The-period-isnt-working-the-way-I-expected_002e">The period isnt working the way I expected.</a>
<li><a href="#Can-I-get-the-flex-manual-in-another-format_003f">Can I get the flex manual in another format?</a>
<li><a href="#Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f">Does there exist a "faster" NDFA-&gt;DFA algorithm?</a>
<li><a href="#How-does-flex-compile-the-DFA-so-quickly_003f">How does flex compile the DFA so quickly?</a>
<li><a href="#How-can-I-use-more-than-8192-rules_003f">How can I use more than 8192 rules?</a>
<li><a href="#How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f">How do I abandon a file in the middle of a scan and switch to a new file?</a>
<li><a href="#How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f">How do I execute code only during initialization (only before the first scan)?</a>
<li><a href="#How-do-I-execute-code-at-termination_003f">How do I execute code at termination?</a>
<li><a href="#Where-else-can-I-find-help_003f">Where else can I find help?</a>
<li><a href="#Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f">Can I include comments in the "rules" section of the file?</a>
<li><a href="#I-get-an-error-about-undefined-yywrap_0028_0029_002e">I get an error about undefined yywrap().</a>
<li><a href="#How-can-I-change-the-matching-pattern-at-run-time_003f">How can I change the matching pattern at run time?</a>
<li><a href="#How-can-I-expand-macros-in-the-input_003f">How can I expand macros in the input?</a>
<li><a href="#How-can-I-build-a-two_002dpass-scanner_003f">How can I build a two-pass scanner?</a>
<li><a href="#How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f">How do I match any string not matched in the preceding rules?</a>
<li><a href="#I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</a>
<li><a href="#Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f">Is there a way to make flex treat NULL like a regular character?</a>
<li><a href="#Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e">Whenever flex can not match the input it says "flex scanner jammed".</a>
<li><a href="#Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f">Why doesnt flex have non-greedy operators like perl does?</a>
<li><a href="#Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e">Memory leak - 16386 bytes allocated by malloc.</a>
<li><a href="#How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f">How do I track the byte offset for lseek()?</a>
<li><a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a>
<li><a href="#How-do-I-skip-as-many-chars-as-possible_003f">How do I skip as many chars as possible?</a>
<li><a href="#deleteme00">deleteme00</a>
<li><a href="#Are-certain-equivalent-patterns-faster-than-others_003f">Are certain equivalent patterns faster than others?</a>
<li><a href="#Is-backing-up-a-big-deal_003f">Is backing up a big deal?</a>
<li><a href="#Can-I-fake-multi_002dbyte-character-support_003f">Can I fake multi-byte character support?</a>
<li><a href="#deleteme01">deleteme01</a>
<li><a href="#Can-you-discuss-some-flex-internals_003f">Can you discuss some flex internals?</a>
<li><a href="#unput_0028_0029-messes-up-yy_005fat_005fbol">unput() messes up yy_at_bol</a>
<li><a href="#The-_007c-operator-is-not-doing-what-I-want">The | operator is not doing what I want</a>
<li><a href="#Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f">Why can't flex understand this variable trailing context pattern?</a>
<li><a href="#The-_005e-operator-isn_0027t-working">The ^ operator isn't working</a>
<li><a href="#Trailing-context-is-getting-confused-with-trailing-optional-patterns">Trailing context is getting confused with trailing optional patterns</a>
<li><a href="#Is-flex-GNU-or-not_003f">Is flex GNU or not?</a>
<li><a href="#ERASEME53">ERASEME53</a>
<li><a href="#I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops">I need to scan if-then-else blocks and while loops</a>
<li><a href="#ERASEME55">ERASEME55</a>
<li><a href="#ERASEME56">ERASEME56</a>
<li><a href="#ERASEME57">ERASEME57</a>
<li><a href="#Is-there-a-repository-for-flex-scanners_003f">Is there a repository for flex scanners?</a>
<li><a href="#How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f">How can I conditionally compile or preprocess my flex input file?</a>
<li><a href="#Where-can-I-find-grammars-for-lex-and-yacc_003f">Where can I find grammars for lex and yacc?</a>
<li><a href="#I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e">I get an end-of-buffer message for each character scanned.</a>
<li><a href="#unnamed_002dfaq_002d62">unnamed-faq-62</a>
<li><a href="#unnamed_002dfaq_002d63">unnamed-faq-63</a>
<li><a href="#unnamed_002dfaq_002d64">unnamed-faq-64</a>
<li><a href="#unnamed_002dfaq_002d65">unnamed-faq-65</a>
<li><a href="#unnamed_002dfaq_002d66">unnamed-faq-66</a>
<li><a href="#unnamed_002dfaq_002d67">unnamed-faq-67</a>
<li><a href="#unnamed_002dfaq_002d68">unnamed-faq-68</a>
<li><a href="#unnamed_002dfaq_002d69">unnamed-faq-69</a>
<li><a href="#unnamed_002dfaq_002d70">unnamed-faq-70</a>
<li><a href="#unnamed_002dfaq_002d71">unnamed-faq-71</a>
<li><a href="#unnamed_002dfaq_002d72">unnamed-faq-72</a>
<li><a href="#unnamed_002dfaq_002d73">unnamed-faq-73</a>
<li><a href="#unnamed_002dfaq_002d74">unnamed-faq-74</a>
<li><a href="#unnamed_002dfaq_002d75">unnamed-faq-75</a>
<li><a href="#unnamed_002dfaq_002d76">unnamed-faq-76</a>
<li><a href="#unnamed_002dfaq_002d77">unnamed-faq-77</a>
<li><a href="#unnamed_002dfaq_002d78">unnamed-faq-78</a>
<li><a href="#unnamed_002dfaq_002d79">unnamed-faq-79</a>
<li><a href="#unnamed_002dfaq_002d80">unnamed-faq-80</a>
<li><a href="#unnamed_002dfaq_002d81">unnamed-faq-81</a>
<li><a href="#unnamed_002dfaq_002d82">unnamed-faq-82</a>
<li><a href="#unnamed_002dfaq_002d83">unnamed-faq-83</a>
<li><a href="#unnamed_002dfaq_002d84">unnamed-faq-84</a>
<li><a href="#unnamed_002dfaq_002d85">unnamed-faq-85</a>
<li><a href="#unnamed_002dfaq_002d86">unnamed-faq-86</a>
<li><a href="#unnamed_002dfaq_002d87">unnamed-faq-87</a>
<li><a href="#unnamed_002dfaq_002d88">unnamed-faq-88</a>
<li><a href="#unnamed_002dfaq_002d90">unnamed-faq-90</a>
<li><a href="#unnamed_002dfaq_002d91">unnamed-faq-91</a>
<li><a href="#unnamed_002dfaq_002d92">unnamed-faq-92</a>
<li><a href="#unnamed_002dfaq_002d93">unnamed-faq-93</a>
<li><a href="#unnamed_002dfaq_002d94">unnamed-faq-94</a>
<li><a href="#unnamed_002dfaq_002d95">unnamed-faq-95</a>
<li><a href="#unnamed_002dfaq_002d96">unnamed-faq-96</a>
<li><a href="#unnamed_002dfaq_002d97">unnamed-faq-97</a>
<li><a href="#unnamed_002dfaq_002d98">unnamed-faq-98</a>
<li><a href="#unnamed_002dfaq_002d99">unnamed-faq-99</a>
<li><a href="#unnamed_002dfaq_002d100">unnamed-faq-100</a>
<li><a href="#unnamed_002dfaq_002d101">unnamed-faq-101</a>
</ul>

<div class="node">
<p><hr>
<a name="When-was-flex-born%3f"></a>
<a name="When-was-flex-born_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f">How do I expand \ escape sequences in C-style quoted strings?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">When was flex born?</h3>

<p>Vern Paxson took over
the <cite>Software Tools</cite> lex project from Jef Poskanzer in 1982.  At that point it
was written in Ratfor.  Around 1987 or so, Paxson translated it into C, and
a legend was born :-).

<div class="node">
<p><hr>
<a name="How-do-I-expand-%5c-escape-sequences-in-C-style-quoted-strings%3f"></a>
<a name="How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f">Why do flex scanners call fileno if it is not ANSI compatible?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#When-was-flex-born_003f">When was flex born?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I expand \ escape sequences in C-style quoted strings?</h3>

<p>A key point when scanning quoted strings is that you cannot (easily) write
a single rule that will precisely match the string if you allow things
like embedded escape sequences and newlines.  If you try to match strings
with a single rule then you'll wind up having to rescan the string anyway
to find any escape sequences.

   <p>Instead you can use exclusive start conditions and a set of rules, one for
matching non-escaped text, one for matching a single escape, one for
matching an embedded newline, and one for recognizing the end of the
string.  Each of these rules is then faced with the question of where to
put its intermediary results.  The best solution is for the rules to
append their local value of <code>yytext</code> to the end of a &ldquo;string literal&rdquo;
buffer.  A rule like the escape-matcher will append to the buffer the
meaning of the escape sequence rather than the literal text in <code>yytext</code>. 
In this way, <code>yytext</code> does not need to be modified at all.

<div class="node">
<p><hr>
<a name="Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible%3f"></a>
<a name="Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Does-flex-support-recursive-pattern-definitions_003f">Does flex support recursive pattern definitions?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-expand-_005c-escape-sequences-in-C_002dstyle-quoted-strings_003f">How do I expand \ escape sequences in C-style quoted strings?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Why do flex scanners call fileno if it is not ANSI compatible?</h3>

<p>Flex scanners call <code>fileno()</code> in order to get the file descriptor
corresponding to <code>yyin</code>. The file descriptor may be passed to
<code>isatty()</code> or <code>read()</code>, depending upon which <code>%options</code> you specified. 
If your system does not have <code>fileno()</code> support, to get rid of the
<code>read()</code> call, do not specify <code>%option read</code>. To get rid of the <code>isatty()</code>
call, you must specify one of <code>%option always-interactive</code> or
<code>%option never-interactive</code>.

<div class="node">
<p><hr>
<a name="Does-flex-support-recursive-pattern-definitions%3f"></a>
<a name="Does-flex-support-recursive-pattern-definitions_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f">How do I skip huge chunks of input (tens of megabytes) while using flex?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Why-do-flex-scanners-call-fileno-if-it-is-not-ANSI-compatible_003f">Why do flex scanners call fileno if it is not ANSI compatible?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Does flex support recursive pattern definitions?</h3>

<p>e.g.,

<pre class="example"><pre class="verbatim">     
     %%
     block   "{"({block}|{statement})*"}"
</pre>
</pre>
   <p>No. You cannot have recursive definitions.  The pattern-matching power of
regular expressions in general (and therefore flex scanners, too) is
limited.  In particular, regular expressions cannot &ldquo;balance&rdquo; parentheses
to an arbitrary degree.  For example, it's impossible to write a regular
expression that matches all strings containing the same number of '{'s
as '}'s.  For more powerful pattern matching, you need a parser, such
as <cite>GNU bison</cite>.

<div class="node">
<p><hr>
<a name="How-do-I-skip-huge-chunks-of-input-(tens-of-megabytes)-while-using-flex%3f"></a>
<a name="How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e">Flex is not matching my patterns in the same order that I defined them.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Does-flex-support-recursive-pattern-definitions_003f">Does flex support recursive pattern definitions?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I skip huge chunks of input (tens of megabytes) while using flex?</h3>

<p>Use <code>fseek()</code> (or <code>lseek()</code>) to position yyin, then call <code>yyrestart()</code>.

<div class="node">
<p><hr>
<a name="Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them."></a>
<a name="Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e">My actions are executing out of order or sometimes not at all.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-skip-huge-chunks-of-input-_0028tens-of-megabytes_0029-while-using-flex_003f">How do I skip huge chunks of input (tens of megabytes) while using flex?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Flex is not matching my patterns in the same order that I defined them.</h3>

<p><code>flex</code> picks the
rule that matches the most text (i.e., the longest possible input string). 
This is because <code>flex</code> uses an entirely different matching technique
(&ldquo;deterministic finite automata&rdquo;) that actually does all of the matching
simultaneously, in parallel.  (Seems impossible, but it's actually a fairly
simple technique once you understand the principles.)

   <p>A side-effect of this parallel matching is that when the input matches more
than one rule, <code>flex</code> scanners pick the rule that matched the <em>most</em> text. This
is explained further in the manual, in the section See <a href="#Matching">Matching</a>.

   <p>If you want <code>flex</code> to choose a shorter match, then you can work around this
behavior by expanding your short
rule to match more text, then put back the extra:

<pre class="example"><pre class="verbatim">     
     data_.*        yyless( 5 ); BEGIN BLOCKIDSTATE;
</pre>
</pre>
   <p>Another fix would be to make the second rule active only during the
<code>&lt;BLOCKIDSTATE&gt;</code> start condition, and make that start condition exclusive
by declaring it with <code>%x</code> instead of <code>%s</code>.

   <p>A final fix is to change the input language so that the ambiguity for
`<samp><span class="samp">data_</span></samp>' is removed, by adding characters to it that don't match the
identifier rule, or by removing characters (such as `<samp><span class="samp">_</span></samp>') from the
identifier rule so it no longer matches `<samp><span class="samp">data_</span></samp>'.  (Of course, you might
also not have the option of changing the input language.)

<div class="node">
<p><hr>
<a name="My-actions-are-executing-out-of-order-or-sometimes-not-at-all."></a>
<a name="My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f">How can I have multiple input sources feed into the same scanner at the same time?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Flex-is-not-matching-my-patterns-in-the-same-order-that-I-defined-them_002e">Flex is not matching my patterns in the same order that I defined them.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">My actions are executing out of order or sometimes not at all.</h3>

<p>Most likely, you have (in error) placed the opening `<samp><span class="samp">{</span></samp>' of the action
block on a different line than the rule, e.g.,

<pre class="example"><pre class="verbatim">     
     ^(foo|bar)
     {  &lt;&lt;&lt;--- WRONG!
     
     }
</pre>
</pre>
   <p><code>flex</code> requires that the opening `<samp><span class="samp">{</span></samp>' of an action associated with a rule
begin on the same line as does the rule.  You need instead to write your rules
as follows:

<pre class="example"><pre class="verbatim">     
     ^(foo|bar)   {  // CORRECT!
     
     }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time%3f"></a>
<a name="How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f">Can I build nested parsers that work with the same input file?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#My-actions-are-executing-out-of-order-or-sometimes-not-at-all_002e">My actions are executing out of order or sometimes not at all.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I have multiple input sources feed into the same scanner at the same time?</h3>

<p>If <small class="dots">...</small>
     <ul>
<li>your scanner is free of backtracking (verified using <code>flex</code>'s `<samp><span class="samp">-b</span></samp>' flag),
<li>AND you run your scanner interactively (`<samp><span class="samp">-I</span></samp>' option; default unless using special table
compression options),
<li>AND you feed it one character at a time by redefining <code>YY_INPUT</code> to do so,
</ul>

   <p>then every time it matches a token, it will have exhausted its input
buffer (because the scanner is free of backtracking).  This means you
can safely use <code>select()</code> at the point and only call <code>yylex()</code> for another
token if <code>select()</code> indicates there's data available.

   <p>That is, move the <code>select()</code> out from the input function to a point where
it determines whether <code>yylex()</code> gets called for the next token.

   <p>With this approach, you will still have problems if your input can arrive
piecemeal; <code>select()</code> could inform you that the beginning of a token is
available, you call <code>yylex()</code> to get it, but it winds up blocking waiting
for the later characters in the token.

   <p>Here's another way:  Move your input multiplexing inside of <code>YY_INPUT</code>.  That
is, whenever <code>YY_INPUT</code> is called, it <code>select()</code>'s to see where input is
available.  If input is available for the scanner, it reads and returns the
next byte.  If input is available from another source, it calls whatever
function is responsible for reading from that source.  (If no input is
available, it blocks until some input is available.)  I've used this technique in an
interpreter I wrote that both reads keyboard input using a <code>flex</code> scanner and
IPC traffic from sockets, and it works fine.

<div class="node">
<p><hr>
<a name="Can-I-build-nested-parsers-that-work-with-the-same-input-file%3f"></a>
<a name="Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-match-text-only-at-the-end-of-a-file_003f">How can I match text only at the end of a file?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-have-multiple-input-sources-feed-into-the-same-scanner-at-the-same-time_003f">How can I have multiple input sources feed into the same scanner at the same time?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Can I build nested parsers that work with the same input file?</h3>

<p>This is not going to work without some additional effort.  The reason is
that <code>flex</code> block-buffers the input it reads from <code>yyin</code>.  This means that the
&ldquo;outermost&rdquo; <code>yylex()</code>, when called, will automatically slurp up the first 8K
of input available on yyin, and subsequent calls to other <code>yylex()</code>'s won't
see that input.  You might be tempted to work around this problem by
redefining <code>YY_INPUT</code> to only return a small amount of text, but it turns out
that that approach is quite difficult.  Instead, the best solution is to
combine all of your scanners into one large scanner, using a different
exclusive start condition for each.

<div class="node">
<p><hr>
<a name="How-can-I-match-text-only-at-the-end-of-a-file%3f"></a>
<a name="How-can-I-match-text-only-at-the-end-of-a-file_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f">How can I make REJECT cascade across start condition boundaries?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Can-I-build-nested-parsers-that-work-with-the-same-input-file_003f">Can I build nested parsers that work with the same input file?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I match text only at the end of a file?</h3>

<p>There is no way to write a rule which is &ldquo;match this text, but only if
it comes at the end of the file&rdquo;.  You can fake it, though, if you happen
to have a character lying around that you don't allow in your input. 
Then you redefine <code>YY_INPUT</code> to call your own routine which, if it sees
an `<samp><span class="samp">EOF</span></samp>', returns the magic character first (and remembers to return a
real <code>EOF</code> next time it's called).  Then you could write:

<pre class="example"><pre class="verbatim">     
     &lt;COMMENT>(.|\n)*{EOF_CHAR}    /* saw comment at EOF */
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="How-can-I-make-REJECT-cascade-across-start-condition-boundaries%3f"></a>
<a name="How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f">Why cant I use fast or full tables with interactive mode?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-match-text-only-at-the-end-of-a-file_003f">How can I match text only at the end of a file?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I make REJECT cascade across start condition boundaries?</h3>

<p>You can do this as follows.  Suppose you have a start condition `<samp><span class="samp">A</span></samp>', and
after exhausting all of the possible matches in `<samp><span class="samp">&lt;A&gt;</span></samp>', you want to try
matches in `<samp><span class="samp">&lt;INITIAL&gt;</span></samp>'.  Then you could use the following:

<pre class="example"><pre class="verbatim">     
     %x A
     %%
     &lt;A>rule_that_is_long    ...; REJECT;
     &lt;A>rule                 ...; REJECT; /* shorter rule */
     &lt;A>etc.
     ...
     &lt;A>.|\n  {
     /* Shortest and last rule in &lt;A>, so
     * cascaded REJECT's will eventually
     * wind up matching this rule.  We want
     * to now switch to the initial state
     * and try matching from there instead.
     */
     yyless(0);    /* put back matched text */
     BEGIN(INITIAL);
     }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="Why-cant-I-use-fast-or-full-tables-with-interactive-mode%3f"></a>
<a name="Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-much-faster-is-_002dF-or-_002df-than-_002dC_003f">How much faster is -F or -f than -C?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-make-REJECT-cascade-across-start-condition-boundaries_003f">How can I make REJECT cascade across start condition boundaries?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Why can't I use fast or full tables with interactive mode?</h3>

<p>One of the assumptions
flex makes is that interactive applications are inherently slow (they're
waiting on a human after all). 
It has to do with how the scanner detects that it must be finished scanning
a token.  For interactive scanners, after scanning each character the current
state is looked up in a table (essentially) to see whether there's a chance
of another input character possibly extending the length of the match.  If
not, the scanner halts.  For non-interactive scanners, the end-of-token test
is much simpler, basically a compare with 0, so no memory bus cycles.  Since
the test occurs in the innermost scanning loop, one would like to make it go
as fast as possible.

   <p>Still, it seems reasonable to allow the user to choose to trade off a bit
of performance in this area to gain the corresponding flexibility.  There
might be another reason, though, why fast scanners don't support the
interactive option.

<div class="node">
<p><hr>
<a name="How-much-faster-is--F-or--f-than--C%3f"></a>
<a name="How-much-faster-is-_002dF-or-_002df-than-_002dC_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f">If I have a simple grammar cant I just parse it with flex?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Why-cant-I-use-fast-or-full-tables-with-interactive-mode_003f">Why cant I use fast or full tables with interactive mode?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How much faster is -F or -f than -C?</h3>

<p>Much faster (factor of 2-3).

<div class="node">
<p><hr>
<a name="If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex%3f"></a>
<a name="If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f">Why doesnt yyrestart() set the start state back to INITIAL?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-much-faster-is-_002dF-or-_002df-than-_002dC_003f">How much faster is -F or -f than -C?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">If I have a simple grammar can't I just parse it with flex?</h3>

<p>Is your grammar recursive? That's almost always a sign that you're
better off using a parser/scanner rather than just trying to use a scanner
alone.

<div class="node">
<p><hr>
<a name="Why-doesnt-yyrestart()-set-the-start-state-back-to-INITIAL%3f"></a>
<a name="Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-match-C_002dstyle-comments_003f">How can I match C-style comments?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#If-I-have-a-simple-grammar-cant-I-just-parse-it-with-flex_003f">If I have a simple grammar cant I just parse it with flex?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Why doesn't yyrestart() set the start state back to INITIAL?</h3>

<p>There are two reasons.  The first is that there might
be programs that rely on the start state not changing across file changes. 
The second is that beginning with <code>flex</code> version 2.4, use of <code>yyrestart()</code> is no longer required,
so fixing the problem there doesn't solve the more general problem.

<div class="node">
<p><hr>
<a name="How-can-I-match-C-style-comments%3f"></a>
<a name="How-can-I-match-C_002dstyle-comments_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#The-period-isnt-working-the-way-I-expected_002e">The period isnt working the way I expected.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Why-doesnt-yyrestart_0028_0029-set-the-start-state-back-to-INITIAL_003f">Why doesnt yyrestart() set the start state back to INITIAL?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I match C-style comments?</h3>

<p>You might be tempted to try something like this:

<pre class="example"><pre class="verbatim">     
     "/*".*"*/"       // WRONG!
</pre>
</pre>
   <p>or, worse, this:

<pre class="example"><pre class="verbatim">     
     "/*"(.|\n)"*/"   // WRONG!
</pre>
</pre>
   <p>The above rules will eat too much input, and blow up on things like:

<pre class="example"><pre class="verbatim">     
     /* a comment */ do_my_thing( "oops */" );
</pre>
</pre>
   <p>Here is one way which allows you to track line information:

<pre class="example"><pre class="verbatim">     
     &lt;INITIAL>{
     "/*"              BEGIN(IN_COMMENT);
     }
     &lt;IN_COMMENT>{
     "*/"      BEGIN(INITIAL);
     [^*\n]+   // eat comment in chunks
     "*"       // eat the lone star
     \n        yylineno++;
     }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="The-period-isnt-working-the-way-I-expected."></a>
<a name="The-period-isnt-working-the-way-I-expected_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Can-I-get-the-flex-manual-in-another-format_003f">Can I get the flex manual in another format?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-match-C_002dstyle-comments_003f">How can I match C-style comments?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">The '.' isn't working the way I expected.</h3>

<p>Here are some tips for using `<samp><span class="samp">.</span></samp>':

     <ul>
<li>A common mistake is to place the grouping parenthesis AFTER an operator, when
you really meant to place the parenthesis BEFORE the operator, e.g., you
probably want this <code>(foo|bar)+</code> and NOT this <code>(foo|bar+)</code>.

     <p>The first pattern matches the words `<samp><span class="samp">foo</span></samp>' or `<samp><span class="samp">bar</span></samp>' any number of
times, e.g., it matches the text `<samp><span class="samp">barfoofoobarfoo</span></samp>'. The
second pattern matches a single instance of <code>foo</code> or a single instance of
<code>bar</code> followed by one or more `<samp><span class="samp">r</span></samp>'s, e.g., it matches the text <code>barrrr</code> . 
<li>A `<samp><span class="samp">.</span></samp>' inside `<samp><span class="samp">[]</span></samp>''s just means a literal`<samp><span class="samp">.</span></samp>' (period),
and NOT &ldquo;any character except newline&rdquo;. 
<li>Remember that `<samp><span class="samp">.</span></samp>' matches any character EXCEPT `<samp><span class="samp">\n</span></samp>' (and `<samp><span class="samp">EOF</span></samp>'). 
If you really want to match ANY character, including newlines, then use <code>(.|\n)</code>
Beware that the regex <code>(.|\n)+</code> will match your entire input! 
<li>Finally, if you want to match a literal `<samp><span class="samp">.</span></samp>' (a period), then use `<samp><span class="samp">[.]</span></samp>' or `<samp><span class="samp">"."</span></samp>'
</ul>

<div class="node">
<p><hr>
<a name="Can-I-get-the-flex-manual-in-another-format%3f"></a>
<a name="Can-I-get-the-flex-manual-in-another-format_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f">Does there exist a &quot;faster&quot; NDFA-&gt;DFA algorithm?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#The-period-isnt-working-the-way-I-expected_002e">The period isnt working the way I expected.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Can I get the flex manual in another format?</h3>

<p>The <code>flex</code> source distribution  includes a texinfo manual. You are
free to convert that texinfo into whatever format you desire. The
<code>texinfo</code> package includes tools for conversion to a number of formats.

<div class="node">
<p><hr>
<a name="Does-there-exist-a-%22faster%22-NDFA-%3eDFA-algorithm%3f"></a>
<a name="Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-does-flex-compile-the-DFA-so-quickly_003f">How does flex compile the DFA so quickly?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Can-I-get-the-flex-manual-in-another-format_003f">Can I get the flex manual in another format?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Does there exist a "faster" NDFA-&gt;DFA algorithm?</h3>

<p>There's no way around the potential exponential running time - it
can take you exponential time just to enumerate all of the DFA states. 
In practice, though, the running time is closer to linear, or sometimes
quadratic.

<div class="node">
<p><hr>
<a name="How-does-flex-compile-the-DFA-so-quickly%3f"></a>
<a name="How-does-flex-compile-the-DFA-so-quickly_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-use-more-than-8192-rules_003f">How can I use more than 8192 rules?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Does-there-exist-a-_0022faster_0022-NDFA_002d_003eDFA-algorithm_003f">Does there exist a &quot;faster&quot; NDFA-&gt;DFA algorithm?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How does flex compile the DFA so quickly?</h3>

<p>There are two big speed wins that <code>flex</code> uses:

     <ol type=1 start=1>
<li>It analyzes the input rules to construct equivalence classes for those
characters that always make the same transitions.  It then rewrites the NFA
using equivalence classes for transitions instead of characters.  This cuts
down the NFA-&gt;DFA computation time dramatically, to the point where, for
uncompressed DFA tables, the DFA generation is often I/O bound in writing out
the tables. 
<li>It maintains hash values for previously computed DFA states, so testing
whether a newly constructed DFA state is equivalent to a previously constructed
state can be done very quickly, by first comparing hash values.
        </ol>

<div class="node">
<p><hr>
<a name="How-can-I-use-more-than-8192-rules%3f"></a>
<a name="How-can-I-use-more-than-8192-rules_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f">How do I abandon a file in the middle of a scan and switch to a new file?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-does-flex-compile-the-DFA-so-quickly_003f">How does flex compile the DFA so quickly?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I use more than 8192 rules?</h3>

<p><code>Flex</code> is compiled with an upper limit of 8192 rules per scanner. 
If you need more than 8192 rules in your scanner, you'll have to recompile <code>flex</code>
with the following changes in <samp><span class="file">flexdef.h</span></samp>:

<pre class="example"><pre class="verbatim">     
     &lt;    #define YY_TRAILING_MASK 0x2000
     &lt;    #define YY_TRAILING_HEAD_MASK 0x4000
     --
     >    #define YY_TRAILING_MASK 0x20000000
     >    #define YY_TRAILING_HEAD_MASK 0x40000000
</pre>
</pre>
   <p>This should work okay as long as your C compiler uses 32 bit integers. 
But you might want to think about whether using such a huge number of rules
is the best way to solve your problem.

   <p>The following may also be relevant:

   <p>With luck, you should be able to increase the definitions in flexdef.h for:

<pre class="example"><pre class="verbatim">     
     #define JAMSTATE -32766 /* marks a reference to the state that always jams */
     #define MAXIMUM_MNS 31999
     #define BAD_SUBSCRIPT -32767
</pre>
</pre>
   <p>recompile everything, and it'll all work.  Flex only has these 16-bit-like
values built into it because a long time ago it was developed on a machine
with 16-bit ints.  I've given this advice to others in the past but haven't
heard back from them whether it worked okay or not...

<div class="node">
<p><hr>
<a name="How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file%3f"></a>
<a name="How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f">How do I execute code only during initialization (only before the first scan)?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-use-more-than-8192-rules_003f">How can I use more than 8192 rules?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I abandon a file in the middle of a scan and switch to a new file?</h3>

<p>Just call <code>yyrestart(newfile)</code>. Be sure to reset the start state if you want a
&ldquo;fresh start, since <code>yyrestart</code> does NOT reset the start state back to <code>INITIAL</code>.

<div class="node">
<p><hr>
<a name="How-do-I-execute-code-only-during-initialization-(only-before-the-first-scan)%3f"></a>
<a name="How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-execute-code-at-termination_003f">How do I execute code at termination?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-abandon-a-file-in-the-middle-of-a-scan-and-switch-to-a-new-file_003f">How do I abandon a file in the middle of a scan and switch to a new file?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I execute code only during initialization (only before the first scan)?</h3>

<p>You can specify an initial action by defining the macro <code>YY_USER_INIT</code> (though
note that <code>yyout</code> may not be available at the time this macro is executed).  Or you
can add to the beginning of your rules section:

<pre class="example"><pre class="verbatim">     
     %%
     /* Must be indented! */
     static int did_init = 0;
     
     if ( ! did_init ){
     do_my_init();
     did_init = 1;
     }
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="How-do-I-execute-code-at-termination%3f"></a>
<a name="How-do-I-execute-code-at-termination_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Where-else-can-I-find-help_003f">Where else can I find help?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-execute-code-only-during-initialization-_0028only-before-the-first-scan_0029_003f">How do I execute code only during initialization (only before the first scan)?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I execute code at termination?</h3>

<p>You can specify an action for the <code>&lt;&lt;EOF&gt;&gt;</code> rule.

<div class="node">
<p><hr>
<a name="Where-else-can-I-find-help%3f"></a>
<a name="Where-else-can-I-find-help_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f">Can I include comments in the &quot;rules&quot; section of the file?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-execute-code-at-termination_003f">How do I execute code at termination?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Where else can I find help?</h3>

<p>You can find the flex homepage on the web at
<a href="http://lex.sourceforge.net/">http://lex.sourceforge.net/</a>. See that page for details about flex
mailing lists as well.

<div class="node">
<p><hr>
<a name="Can-I-include-comments-in-the-%22rules%22-section-of-the-file%3f"></a>
<a name="Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#I-get-an-error-about-undefined-yywrap_0028_0029_002e">I get an error about undefined yywrap().</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Where-else-can-I-find-help_003f">Where else can I find help?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Can I include comments in the "rules" section of the file?</h3>

<p>Yes, just about anywhere you want to. See the manual for the specific syntax.

<div class="node">
<p><hr>
<a name="I-get-an-error-about-undefined-yywrap()."></a>
<a name="I-get-an-error-about-undefined-yywrap_0028_0029_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-change-the-matching-pattern-at-run-time_003f">How can I change the matching pattern at run time?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Can-I-include-comments-in-the-_0022rules_0022-section-of-the-file_003f">Can I include comments in the &quot;rules&quot; section of the file?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">I get an error about undefined yywrap().</h3>

<p>You must supply a <code>yywrap()</code> function of your own, or link to <samp><span class="file">libfl.a</span></samp>
(which provides one), or use

<pre class="example"><pre class="verbatim">     
     %option noyywrap
</pre>
</pre>
   <p>in your source to say you don't want a <code>yywrap()</code> function.

<div class="node">
<p><hr>
<a name="How-can-I-change-the-matching-pattern-at-run-time%3f"></a>
<a name="How-can-I-change-the-matching-pattern-at-run-time_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-expand-macros-in-the-input_003f">How can I expand macros in the input?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#I-get-an-error-about-undefined-yywrap_0028_0029_002e">I get an error about undefined yywrap().</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I change the matching pattern at run time?</h3>

<p>You can't, it's compiled into a static table when flex builds the scanner.

<div class="node">
<p><hr>
<a name="How-can-I-expand-macros-in-the-input%3f"></a>
<a name="How-can-I-expand-macros-in-the-input_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-build-a-two_002dpass-scanner_003f">How can I build a two-pass scanner?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-change-the-matching-pattern-at-run-time_003f">How can I change the matching pattern at run time?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I expand macros in the input?</h3>

<p>The best way to approach this problem is at a higher level, e.g., in the parser.

   <p>However, you can do this using multiple input buffers.

<pre class="example"><pre class="verbatim">     
     %%
     macro/[a-z]+	{
     /* Saw the macro "macro" followed by extra stuff. */
     main_buffer = YY_CURRENT_BUFFER;
     expansion_buffer = yy_scan_string(expand(yytext));
     yy_switch_to_buffer(expansion_buffer);
     }
     
     &lt;&lt;EOF>>	{
     if ( expansion_buffer )
     {
     // We were doing an expansion, return to where
     // we were.
     yy_switch_to_buffer(main_buffer);
     yy_delete_buffer(expansion_buffer);
     expansion_buffer = 0;
     }
     else
     yyterminate();
     }
</pre>
</pre>
   <p>You probably will want a stack of expansion buffers to allow nested macros. 
From the above though hopefully the idea is clear.

<div class="node">
<p><hr>
<a name="How-can-I-build-a-two-pass-scanner%3f"></a>
<a name="How-can-I-build-a-two_002dpass-scanner_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f">How do I match any string not matched in the preceding rules?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-expand-macros-in-the-input_003f">How can I expand macros in the input?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I build a two-pass scanner?</h3>

<p>One way to do it is to filter the first pass to a temporary file,
then process the temporary file on the second pass. You will probably see a
performance hit, do to all the disk I/O.

   <p>When you need to look ahead far forward like this, it almost always means
that the right solution is to build a parse tree of the entire input, then
walk it after the parse in order to generate the output.  In a sense, this
is a two-pass approach, once through the text and once through the parse
tree, but the performance hit for the latter is usually an order of magnitude
smaller, since everything is already classified, in binary format, and
residing in memory.

<div class="node">
<p><hr>
<a name="How-do-I-match-any-string-not-matched-in-the-preceding-rules%3f"></a>
<a name="How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-build-a-two_002dpass-scanner_003f">How can I build a two-pass scanner?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I match any string not matched in the preceding rules?</h3>

<p>One way to assign precedence, is to place the more specific rules first. If
two rules would match the same input (same sequence of characters) then the
first rule listed in the <code>flex</code> input wins. e.g.,

<pre class="example"><pre class="verbatim">     
     %%
     foo[a-zA-Z_]+    return FOO_ID;
     bar[a-zA-Z_]+    return BAR_ID;
     [a-zA-Z_]+       return GENERIC_ID;
</pre>
</pre>
   <p>Note that the rule <code>[a-zA-Z_]+</code> must come *after* the others.  It will match the
same amount of text as the more specific rules, and in that case the
<code>flex</code> scanner will pick the first rule listed in your scanner as the
one to match.

<div class="node">
<p><hr>
<a name="I-am-trying-to-port-code-from-AT%26T-lex-that-uses-yysptr-and-yysbuf."></a>
<a name="I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f">Is there a way to make flex treat NULL like a regular character?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-match-any-string-not-matched-in-the-preceding-rules_003f">How do I match any string not matched in the preceding rules?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</h3>

<p>Those are internal variables pointing into the AT&amp;T scanner's input buffer.  I
imagine they're being manipulated in user versions of the <code>input()</code> and <code>unput()</code>
functions.  If so, what you need to do is analyze those functions to figure out
what they're doing, and then replace <code>input()</code> with an appropriate definition of
<code>YY_INPUT</code>.  You shouldn't need to (and must not) replace
<code>flex</code>'s <code>unput()</code> function.

<div class="node">
<p><hr>
<a name="Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character%3f"></a>
<a name="Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e">Whenever flex can not match the input it says &quot;flex scanner jammed&quot;.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#I-am-trying-to-port-code-from-AT_0026T-lex-that-uses-yysptr-and-yysbuf_002e">I am trying to port code from AT&amp;T lex that uses yysptr and yysbuf.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Is there a way to make flex treat NULL like a regular character?</h3>

<p>Yes, `<samp><span class="samp">\0</span></samp>' and `<samp><span class="samp">\x00</span></samp>' should both do the trick.  Perhaps you have an ancient
version of <code>flex</code>.  The latest release is version 2.5.31.

<div class="node">
<p><hr>
<a name="Whenever-flex-can-not-match-the-input-it-says-%22flex-scanner-jammed%22."></a>
<a name="Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f">Why doesnt flex have non-greedy operators like perl does?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Is-there-a-way-to-make-flex-treat-NULL-like-a-regular-character_003f">Is there a way to make flex treat NULL like a regular character?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Whenever flex can not match the input it says "flex scanner jammed".</h3>

<p>You need to add a rule that matches the otherwise-unmatched text. 
e.g.,

<pre class="example"><pre class="verbatim">     
     %option yylineno
     %%
     [[a bunch of rules here]]
     
     .	printf("bad input character '%s' at line %d\n", yytext, yylineno);
</pre>
</pre>
   <p>See <code>%option default</code> for more information.

<div class="node">
<p><hr>
<a name="Why-doesnt-flex-have-non-greedy-operators-like-perl-does%3f"></a>
<a name="Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e">Memory leak - 16386 bytes allocated by malloc.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Whenever-flex-can-not-match-the-input-it-says-_0022flex-scanner-jammed_0022_002e">Whenever flex can not match the input it says &quot;flex scanner jammed&quot;.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Why doesn't flex have non-greedy operators like perl does?</h3>

<p>A DFA can do a non-greedy match by stopping
the first time it enters an accepting state, instead of consuming input until
it determines that no further matching is possible (a &ldquo;jam&rdquo; state).  This
is actually easier to implement than longest leftmost match (which flex does).

   <p>But it's also much less useful than longest leftmost match.  In general,
when you find yourself wishing for non-greedy matching, that's usually a
sign that you're trying to make the scanner do some parsing.  That's
generally the wrong approach, since it lacks the power to do a decent job. 
Better is to either introduce a separate parser, or to split the scanner
into multiple scanners using (exclusive) start conditions.

   <p>You might have
a separate start state once you've seen the `<samp><span class="samp">BEGIN</span></samp>'. In that state, you
might then have a regex that will match `<samp><span class="samp">END</span></samp>' (to kick you out of the
state), and perhaps `<samp><span class="samp">(.|\n)</span></samp>' to get a single character within the chunk ...

   <p>This approach also has much better error-reporting properties.

<div class="node">
<p><hr>
<a name="Memory-leak---16386-bytes-allocated-by-malloc."></a>
<a name="Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f">How do I track the byte offset for lseek()?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f">Why doesnt flex have non-greedy operators like perl does?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Memory leak - 16386 bytes allocated by malloc.</h3>

<p><a name="faq_002dmemory_002dleak"></a>

   <p>UPDATED 2002-07-10: As of <code>flex</code> version 2.5.9, this leak means that you did not
call <code>yylex_destroy()</code>. If you are using an earlier version of <code>flex</code>, then read
on.

   <p>The leak is about 16426 bytes.  That is, (8192 * 2 + 2) for the read-buffer, and
about 40 for <code>struct yy_buffer_state</code> (depending upon alignment). The leak is in
the non-reentrant C scanner only (NOT in the reentrant scanner, NOT in the C++
scanner). Since <code>flex</code> doesn't know when you are done, the buffer is never freed.

   <p>However, the leak won't multiply since the buffer is reused no matter how many
times you call <code>yylex()</code>.

   <p>If you want to reclaim the memory when you are completely done scanning, then
you might try this:

<pre class="example"><pre class="verbatim">     
     /* For non-reentrant C scanner only. */
     yy_delete_buffer(YY_CURRENT_BUFFER);
     yy_init = 1;
</pre>
</pre>
   <p>Note: <code>yy_init</code> is an "internal variable", and hasn't been tested in this
situation. It is possible that some other globals may need resetting as well.

<div class="node">
<p><hr>
<a name="How-do-I-track-the-byte-offset-for-lseek()%3f"></a>
<a name="How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Memory-leak-_002d-16386-bytes-allocated-by-malloc_002e">Memory leak - 16386 bytes allocated by malloc.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I track the byte offset for lseek()?</h3>

<pre class="example"><pre class="verbatim">     
     >   We thought that it would be possible to have this number through the
     >   evaluation of the following expression:
     >
     >   seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf
</pre>
</pre>
   <p>While this is the right idea, it has two problems.  The first is that
it's possible that <code>flex</code> will request less than <code>YY_READ_BUF_SIZE</code> during
an invocation of <code>YY_INPUT</code> (or that your input source will return less
even though <code>YY_READ_BUF_SIZE</code> bytes were requested).  The second problem
is that when refilling its internal buffer, <code>flex</code> keeps some characters
from the previous buffer (because usually it's in the middle of a match,
and needs those characters to construct <code>yytext</code> for the match once it's
done).  Because of this, <code>yy_c_buf_p - YY_CURRENT_BUFFER-&gt;yy_ch_buf</code> won't
be exactly the number of characters already read from the current buffer.

   <p>An alternative solution is to count the number of characters you've matched
since starting to scan.  This can be done by using <code>YY_USER_ACTION</code>.  For
example,

<pre class="example"><pre class="verbatim">     
     #define YY_USER_ACTION num_chars += yyleng;
</pre>
</pre>
   <p>(You need to be careful to update your bookkeeping if you use <code>yymore(</code>),
<code>yyless()</code>, <code>unput()</code>, or <code>input()</code>.)

<div class="node">
<p><hr>
<a name="How-do-I-use-my-own-I%2fO-classes-in-a-C++-scanner%3f"></a>
<a name="How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-do-I-skip-as-many-chars-as-possible_003f">How do I skip as many chars as possible?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-track-the-byte-offset-for-lseek_0028_0029_003f">How do I track the byte offset for lseek()?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="section">How do I use my own I/O classes in a C++ scanner?</h3>

<p>When the flex C++ scanning class rewrite finally happens, then this sort of thing should become much easier.

   <p><a name="index-LexerOutput_002c-overriding-481"></a><a name="index-LexerInput_002c-overriding-482"></a><a name="index-overriding-LexerOutput-483"></a><a name="index-overriding-LexerInput-484"></a><a name="index-customizing-I_002fO-in-C_002b_002b-scanners-485"></a><a name="index-C_002b_002b-I_002fO_002c-customizing-486"></a>You can do this by passing the various functions (such as <code>LexerInput()</code>
and <code>LexerOutput()</code>) NULL <code>iostream*</code>'s, and then
dealing with your own I/O classes surreptitiously (i.e., stashing them in
special member variables).  This works because the only assumption about
the lexer regarding what's done with the iostream's is that they're
ultimately passed to <code>LexerInput()</code> and <code>LexerOutput</code>, which then do whatever
is necessary with them.

<!-- faq edit stopped here -->
<div class="node">
<p><hr>
<a name="How-do-I-skip-as-many-chars-as-possible%3f"></a>
<a name="How-do-I-skip-as-many-chars-as-possible_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#deleteme00">deleteme00</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How do I skip as many chars as possible?</h3>

<p>How do I skip as many chars as possible &ndash; without interfering with the other
patterns?

   <p>In the example below, we want to skip over characters until we see the phrase
"endskip". The following will <em>NOT</em> work correctly (do you see why not?)

<pre class="example"><pre class="verbatim">     
     /* INCORRECT SCANNER */
     %x SKIP
     %%
     &lt;INITIAL>startskip   BEGIN(SKIP);
     ...
     &lt;SKIP>"endskip"       BEGIN(INITIAL);
     &lt;SKIP>.*             ;
</pre>
</pre>
   <p>The problem is that the pattern .* will eat up the word "endskip." 
The simplest (but slow) fix is:

<pre class="example"><pre class="verbatim">     
     &lt;SKIP>"endskip"      BEGIN(INITIAL);
     &lt;SKIP>.              ;
</pre>
</pre>
   <p>The fix involves making the second rule match more, without
making it match "endskip" plus something else.  So for example:

<pre class="example"><pre class="verbatim">     
     &lt;SKIP>"endskip"     BEGIN(INITIAL);
     &lt;SKIP>[^e]+         ;
     &lt;SKIP>.		        ;/* so you eat up e's, too */
</pre>
</pre>
   <!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="deleteme00"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Are-certain-equivalent-patterns-faster-than-others_003f">Are certain equivalent patterns faster than others?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-do-I-skip-as-many-chars-as-possible_003f">How do I skip as many chars as possible?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">deleteme00</h3>

<pre class="example"><pre class="verbatim">     
     QUESTION:
     When was flex born?
     
     Vern Paxson took over
     the Software Tools lex project from Jef Poskanzer in 1982.  At that point it
     was written in Ratfor.  Around 1987 or so, Paxson translated it into C, and
     a legend was born :-).
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Are-certain-equivalent-patterns-faster-than-others%3f"></a>
<a name="Are-certain-equivalent-patterns-faster-than-others_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Is-backing-up-a-big-deal_003f">Is backing up a big deal?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#deleteme00">deleteme00</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Are certain equivalent patterns faster than others?</h3>

<pre class="example"><pre class="verbatim">     
     To: Adoram Rogel &lt;adoram@orna.hybridge.com>
     Subject: Re: Flex 2.5.2 performance questions
     In-reply-to: Your message of Wed, 18 Sep 96 11:12:17 EDT.
     Date: Wed, 18 Sep 96 10:51:02 PDT
     From: Vern Paxson &lt;vern>
     
     [Note, the most recent flex release is 2.5.4, which you can get from
     ftp.ee.lbl.gov.  It has bug fixes over 2.5.2 and 2.5.3.]
     
     > 1. Using the pattern
     >    ([Ff](oot)?)?[Nn](ote)?(\.)?
     >    instead of
     >    (((F|f)oot(N|n)ote)|((N|n)ote)|((N|n)\.)|((F|f)(N|n)(\.)))
     >    (in a very complicated flex program) caused the program to slow from
     >    300K+/min to 100K/min (no other changes were done).
     
     These two are not equivalent.  For example, the first can match "footnote."
     but the second can only match "footnote".  This is almost certainly the
     cause in the discrepancy - the slower scanner run is matching more tokens,
     and/or having to do more backing up.
     
     > 2. Which of these two are better: [Ff]oot or (F|f)oot ?
     
     From a performance point of view, they're equivalent (modulo presumably
     minor effects such as memory cache hit rates; and the presence of trailing
     context, see below).  From a space point of view, the first is slightly
     preferable.
     
     > 3. I have a pattern that look like this:
     >    pats {p1}|{p2}|{p3}|...|{p50}     (50 patterns ORd)
     >
     >    running yet another complicated program that includes the following rule:
     >    &lt;snext>{and}/{no4}{bb}{pats}
     >
     >    gets me to "too complicated - over 32,000 states"...
     
     I can't tell from this example whether the trailing context is variable-length
     or fixed-length (it could be the latter if {and} is fixed-length).  If it's
     variable length, which flex -p will tell you, then this reflects a basic
     performance problem, and if you can eliminate it by restructuring your
     scanner, you will see significant improvement.
     
     >    so I divided {pats} to {pats1}, {pats2},..., {pats5} each consists of about
     >    10 patterns and changed the rule to be 5 rules.
     >    This did compile, but what is the rule of thumb here ?
     
     The rule is to avoid trailing context other than fixed-length, in which for
     a/b, either the 'a' pattern or the 'b' pattern have a fixed length.  Use
     of the '|' operator automatically makes the pattern variable length, so in
     this case '[Ff]oot' is preferred to '(F|f)oot'.
     
     > 4. I changed a rule that looked like this:
     >    &lt;snext8>{and}{bb}/{ROMAN}[^A-Za-z] { BEGIN...
     >
     >    to the next 2 rules:
     >    &lt;snext8>{and}{bb}/{ROMAN}[A-Za-z] { ECHO;}
     >    &lt;snext8>{and}{bb}/{ROMAN}         { BEGIN...
     >
     >    Again, I understand the using [^...] will cause a great performance loss
     
     Actually, it doesn't cause any sort of performance loss.  It's a surprising
     fact about regular expressions that they always match in linear time
     regardless of how complex they are.
     
     >    but are there any specific rules about it ?
     
     See the "Performance Considerations" section of the man page, and also
     the example in MISC/fastwc/.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Is-backing-up-a-big-deal%3f"></a>
<a name="Is-backing-up-a-big-deal_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Can-I-fake-multi_002dbyte-character-support_003f">Can I fake multi-byte character support?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Are-certain-equivalent-patterns-faster-than-others_003f">Are certain equivalent patterns faster than others?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Is backing up a big deal?</h3>

<pre class="example"><pre class="verbatim">     
     To: Adoram Rogel &lt;adoram@hybridge.com>
     Subject: Re: Flex 2.5.2 performance questions
     In-reply-to: Your message of Thu, 19 Sep 96 10:16:04 EDT.
     Date: Thu, 19 Sep 96 09:58:00 PDT
     From: Vern Paxson &lt;vern>
     
     > a lot about the backing up problem.
     > I believe that there lies my biggest problem, and I'll try to improve
     > it.
     
     Since you have variable trailing context, this is a bigger performance
     problem.  Fixing it is usually easier than fixing backing up, which in a
     complicated scanner (yours seems to fit the bill) can be extremely
     difficult to do correctly.
     
     You also don't mention what flags you are using for your scanner.
     -f makes a large speed difference, and -Cfe buys you nearly as much
     speed but the resulting scanner is considerably smaller.
     
     > I have an | operator in {and} and in {pats} so both of them are variable
     > length.
     
     -p should have reported this.
     
     > Is changing one of them to fixed-length is enough ?
     
     Yes.
     
     > Is it possible to change the 32,000 states limit ?
     
     Yes.  I've appended instructions on how.  Before you make this change,
     though, you should think about whether there are ways to fundamentally
     simplify your scanner - those are certainly preferable!
     
     		Vern
     
     To increase the 32K limit (on a machine with 32 bit integers), you increase
     the magnitude of the following in flexdef.h:
     
     #define JAMSTATE -32766 /* marks a reference to the state that always jams */
     #define MAXIMUM_MNS 31999
     #define BAD_SUBSCRIPT -32767
     #define MAX_SHORT 32700
     
     Adding a 0 or two after each should do the trick.
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Can-I-fake-multi-byte-character-support%3f"></a>
<a name="Can-I-fake-multi_002dbyte-character-support_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#deleteme01">deleteme01</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Is-backing-up-a-big-deal_003f">Is backing up a big deal?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Can I fake multi-byte character support?</h3>

<pre class="example"><pre class="verbatim">     
     To: Heeman_Lee@hp.com
     Subject: Re: flex - multi-byte support?
     In-reply-to: Your message of Thu, 03 Oct 1996 17:24:04 PDT.
     Date: Fri, 04 Oct 1996 11:42:18 PDT
     From: Vern Paxson &lt;vern>
     
     >      I assume as long as my *.l file defines the
     >      range of expected character code values (in octal format), flex will
     >      scan the file and read multi-byte characters correctly. But I have no
     >      confidence in this assumption.
     
     Your lack of confidence is justified - this won't work.
     
     Flex has in it a widespread assumption that the input is processed
     one byte at a time.  Fixing this is on the to-do list, but is involved,
     so it won't happen any time soon.  In the interim, the best I can suggest
     (unless you want to try fixing it yourself) is to write your rules in
     terms of pairs of bytes, using definitions in the first section:
     
     	X	\xfe\xc2
     	...
     	%%
     	foo{X}bar	found_foo_fe_c2_bar();
     
     etc.  Definitely a pain - sorry about that.
     
     By the way, the email address you used for me is ancient, indicating you
     have a very old version of flex.  You can get the most recent, 2.5.4, from
     ftp.ee.lbl.gov.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="deleteme01"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Can-you-discuss-some-flex-internals_003f">Can you discuss some flex internals?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Can-I-fake-multi_002dbyte-character-support_003f">Can I fake multi-byte character support?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">deleteme01</h3>

<pre class="example"><pre class="verbatim">     
     To: moleary@primus.com
     Subject: Re: Flex / Unicode compatibility question
     In-reply-to: Your message of Tue, 22 Oct 1996 10:15:42 PDT.
     Date: Tue, 22 Oct 1996 11:06:13 PDT
     From: Vern Paxson &lt;vern>
     
     Unfortunately flex at the moment has a widespread assumption within it
     that characters are processed 8 bits at a time.  I don't see any easy
     fix for this (other than writing your rules in terms of double characters -
     a pain).  I also don't know of a wider lex, though you might try surfing
     the Plan 9 stuff because I know it's a Unicode system, and also the PCCT
     toolkit (try searching say Alta Vista for "Purdue Compiler Construction
     Toolkit").
     
     Fixing flex to handle wider characters is on the long-term to-do list.
     But since flex is a strictly spare-time project these days, this probably
     won't happen for quite a while, unless someone else does it first.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Can-you-discuss-some-flex-internals%3f"></a>
<a name="Can-you-discuss-some-flex-internals_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unput_0028_0029-messes-up-yy_005fat_005fbol">unput() messes up yy_at_bol</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#deleteme01">deleteme01</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Can you discuss some flex internals?</h3>

<pre class="example"><pre class="verbatim">     
     To: Johan Linde &lt;jl@theophys.kth.se>
     Subject: Re: translation of flex
     In-reply-to: Your message of Sun, 10 Nov 1996 09:16:36 PST.
     Date: Mon, 11 Nov 1996 10:33:50 PST
     From: Vern Paxson &lt;vern>
     
     > I'm working for the Swedish team translating GNU program, and I'm currently
     > working with flex. I have a few questions about some of the messages which
     > I hope you can answer.
     
     All of the things you're wondering about, by the way, concerning flex
     internals - probably the only person who understands what they mean in
     English is me!  So I wouldn't worry too much about getting them right.
     That said ...
     
     > #: main.c:545
     > msgid "  %d protos created\n"
     >
     > Does proto mean prototype?
     
     Yes - prototypes of state compression tables.
     
     > #: main.c:539
     > msgid "  %d/%d (peak %d) template nxt-chk entries created\n"
     >
     > Here I'm mainly puzzled by 'nxt-chk'. I guess it means 'next-check'. (?)
     > However, 'template next-check entries' doesn't make much sense to me. To be
     > able to find a good translation I need to know a little bit more about it.
     
     There is a scheme in the Aho/Sethi/Ullman compiler book for compressing
     scanner tables.  It involves creating two pairs of tables.  The first has
     "base" and "default" entries, the second has "next" and "check" entries.
     The "base" entry is indexed by the current state and yields an index into
     the next/check table.  The "default" entry gives what to do if the state
     transition isn't found in next/check.  The "next" entry gives the next
     state to enter, but only if the "check" entry verifies that this entry is
     correct for the current state.  Flex creates templates of series of
     next/check entries and then encodes differences from these templates as a
     way to compress the tables.
     
     > #: main.c:533
     > msgid "  %d/%d base-def entries created\n"
     >
     > The same problem here for 'base-def'.
     
     See above.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unput()-messes-up-yy_at_bol"></a>
<a name="unput_0028_0029-messes-up-yy_005fat_005fbol"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#The-_007c-operator-is-not-doing-what-I-want">The | operator is not doing what I want</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Can-you-discuss-some-flex-internals_003f">Can you discuss some flex internals?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unput() messes up yy_at_bol</h3>

<pre class="example"><pre class="verbatim">     
     To: Xinying Li &lt;xli@npac.syr.edu>
     Subject: Re: FLEX ?
     In-reply-to: Your message of Wed, 13 Nov 1996 17:28:38 PST.
     Date: Wed, 13 Nov 1996 19:51:54 PST
     From: Vern Paxson &lt;vern>
     
     > "unput()" them to input flow, question occurs. If I do this after I scan
     > a carriage, the variable "YY_CURRENT_BUFFER->yy_at_bol" is changed. That
     > means the carriage flag has gone.
     
     You can control this by calling yy_set_bol().  It's described in the manual.
     
     >      And if in pre-reading it goes to the end of file, is anything done
     > to control the end of curren buffer and end of file?
     
     No, there's no way to put back an end-of-file.
     
     >      By the way I am using flex 2.5.2 and using the "-l".
     
     The latest release is 2.5.4, by the way.  It fixes some bugs in 2.5.2 and
     2.5.3.  You can get it from ftp.ee.lbl.gov.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="The-%7c-operator-is-not-doing-what-I-want"></a>
<a name="The-_007c-operator-is-not-doing-what-I-want"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f">Why can't flex understand this variable trailing context pattern?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unput_0028_0029-messes-up-yy_005fat_005fbol">unput() messes up yy_at_bol</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">The | operator is not doing what I want</h3>

<pre class="example"><pre class="verbatim">     
     To: Alain.ISSARD@st.com
     Subject: Re: Start condition with FLEX
     In-reply-to: Your message of Mon, 18 Nov 1996 09:45:02 PST.
     Date: Mon, 18 Nov 1996 10:41:34 PST
     From: Vern Paxson &lt;vern>
     
     > I am not able to use the start condition scope and to use the | (OR) with
     > rules having start conditions.
     
     The problem is that if you use '|' as a regular expression operator, for
     example "a|b" meaning "match either 'a' or 'b'", then it must *not* have
     any blanks around it.  If you instead want the special '|' *action* (which
     from your scanner appears to be the case), which is a way of giving two
     different rules the same action:
     
     	foo	|
     	bar	matched_foo_or_bar();
     
     then '|' *must* be separated from the first rule by whitespace and *must*
     be followed by a new line.  You *cannot* write it as:
     
     	foo | bar	matched_foo_or_bar();
     
     even though you might think you could because yacc supports this syntax.
     The reason for this unfortunately incompatibility is historical, but it's
     unlikely to be changed.
     
     Your problems with start condition scope are simply due to syntax errors
     from your use of '|' later confusing flex.
     
     Let me know if you still have problems.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Why-can't-flex-understand-this-variable-trailing-context-pattern%3f"></a>
<a name="Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#The-_005e-operator-isn_0027t-working">The ^ operator isn't working</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#The-_007c-operator-is-not-doing-what-I-want">The | operator is not doing what I want</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Why can't flex understand this variable trailing context pattern?</h3>

<pre class="example"><pre class="verbatim">     
     To: Gregory Margo &lt;gmargo@newton.vip.best.com>
     Subject: Re: flex-2.5.3 bug report
     In-reply-to: Your message of Sat, 23 Nov 1996 16:50:09 PST.
     Date: Sat, 23 Nov 1996 17:07:32 PST
     From: Vern Paxson &lt;vern>
     
     > Enclosed is a lex file that "real" lex will process, but I cannot get
     > flex to process it.  Could you try it and maybe point me in the right direction?
     
     Your problem is that some of the definitions in the scanner use the '/'
     trailing context operator, and have it enclosed in ()'s.  Flex does not
     allow this operator to be enclosed in ()'s because doing so allows undefined
     regular expressions such as "(a/b)+".  So the solution is to remove the
     parentheses.  Note that you must also be building the scanner with the -l
     option for AT&amp;T lex compatibility.  Without this option, flex automatically
     encloses the definitions in parentheses.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="The-%5e-operator-isn't-working"></a>
<a name="The-_005e-operator-isn_0027t-working"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Trailing-context-is-getting-confused-with-trailing-optional-patterns">Trailing context is getting confused with trailing optional patterns</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Why-can_0027t-flex-understand-this-variable-trailing-context-pattern_003f">Why can't flex understand this variable trailing context pattern?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">The ^ operator isn't working</h3>

<pre class="example"><pre class="verbatim">     
     To: Thomas Hadig &lt;hadig@toots.physik.rwth-aachen.de>
     Subject: Re: Flex Bug ?
     In-reply-to: Your message of Tue, 26 Nov 1996 14:35:01 PST.
     Date: Tue, 26 Nov 1996 11:15:05 PST
     From: Vern Paxson &lt;vern>
     
     > In my lexer code, i have the line :
     > ^\*.*          { }
     >
     > Thus all lines starting with an astrix (*) are comment lines.
     > This does not work !
     
     I can't get this problem to reproduce - it works fine for me.  Note
     though that if what you have is slightly different:
     
     	COMMENT	^\*.*
     	%%
     	{COMMENT}	{ }
     
     then it won't work, because flex pushes back macro definitions enclosed
     in ()'s, so the rule becomes
     
     	(^\*.*)		{ }
     
     and now that the '^' operator is not at the immediate beginning of the
     line, it's interpreted as just a regular character.  You can avoid this
     behavior by using the "-l" lex-compatibility flag, or "%option lex-compat".
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Trailing-context-is-getting-confused-with-trailing-optional-patterns"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Is-flex-GNU-or-not_003f">Is flex GNU or not?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#The-_005e-operator-isn_0027t-working">The ^ operator isn't working</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Trailing context is getting confused with trailing optional patterns</h3>

<pre class="example"><pre class="verbatim">     
     To: Adoram Rogel &lt;adoram@hybridge.com>
     Subject: Re: Flex 2.5.4 BOF ???
     In-reply-to: Your message of Tue, 26 Nov 1996 16:10:41 PST.
     Date: Wed, 27 Nov 1996 10:56:25 PST
     From: Vern Paxson &lt;vern>
     
     >     Organization(s)?/[a-z]
     >
     > This matched "Organizations" (looking in debug mode, the trailing s
     > was matched with trailing context instead of the optional (s) in the
     > end of the word.
     
     That should only happen with lex.  Flex can properly match this pattern.
     (That might be what you're saying, I'm just not sure.)
     
     > Is there a way to avoid this dangerous trailing context problem ?
     
     Unfortunately, there's no easy way.  On the other hand, I don't see why
     it should be a problem.  Lex's matching is clearly wrong, and I'd hope
     that usually the intent remains the same as expressed with the pattern,
     so flex's matching will be correct.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Is-flex-GNU-or-not%3f"></a>
<a name="Is-flex-GNU-or-not_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#ERASEME53">ERASEME53</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Trailing-context-is-getting-confused-with-trailing-optional-patterns">Trailing context is getting confused with trailing optional patterns</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Is flex GNU or not?</h3>

<pre class="example"><pre class="verbatim">     
     To: Cameron MacKinnon &lt;mackin@interlog.com>
     Subject: Re: Flex documentation bug
     In-reply-to: Your message of Mon, 02 Dec 1996 00:07:08 PST.
     Date: Sun, 01 Dec 1996 22:29:39 PST
     From: Vern Paxson &lt;vern>
     
     > I'm not sure how or where to submit bug reports (documentation or
     > otherwise) for the GNU project stuff ...
     
     Well, strictly speaking flex isn't part of the GNU project.  They just
     distribute it because no one's written a decent GPL'd lex replacement.
     So you should send bugs directly to me.  Those sent to the GNU folks
     sometimes find there way to me, but some may drop between the cracks.
     
     > In GNU Info, under the section 'Start Conditions', and also in the man
     > page (mine's dated April '95) is a nice little snippet showing how to
     > parse C quoted strings into a buffer, defined to be MAX_STR_CONST in
     > size. Unfortunately, no overflow checking is ever done ...
     
     This is already mentioned in the manual:
     
     Finally, here's an example of how to  match  C-style  quoted
     strings using exclusive start conditions, including expanded
     escape sequences (but not including checking  for  a  string
     that's too long):
     
     The reason for not doing the overflow checking is that it will needlessly
     clutter up an example whose main purpose is just to demonstrate how to
     use flex.
     
     The latest release is 2.5.4, by the way, available from ftp.ee.lbl.gov.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="ERASEME53"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops">I need to scan if-then-else blocks and while loops</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Is-flex-GNU-or-not_003f">Is flex GNU or not?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">ERASEME53</h3>

<pre class="example"><pre class="verbatim">     
     To: tsv@cs.UManitoba.CA
     Subject: Re: Flex (reg)..
     In-reply-to: Your message of Thu, 06 Mar 1997 23:50:16 PST.
     Date: Thu, 06 Mar 1997 15:54:19 PST
     From: Vern Paxson &lt;vern>
     
     > [:alpha:] ([:alnum:] | \\_)*
     
     If your rule really has embedded blanks as shown above, then it won't
     work, as the first blank delimits the rule from the action.  (It wouldn't
     even compile ...)  You need instead:
     
     [:alpha:]([:alnum:]|\\_)*
     
     and that should work fine - there's no restriction on what can go inside
     of ()'s except for the trailing context operator, '/'.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="I-need-to-scan-if-then-else-blocks-and-while-loops"></a>
<a name="I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#ERASEME55">ERASEME55</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#ERASEME53">ERASEME53</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">I need to scan if-then-else blocks and while loops</h3>

<pre class="example"><pre class="verbatim">     
     To: "Mike Stolnicki" &lt;mstolnic@ford.com>
     Subject: Re: FLEX help
     In-reply-to: Your message of Fri, 30 May 1997 13:33:27 PDT.
     Date: Fri, 30 May 1997 10:46:35 PDT
     From: Vern Paxson &lt;vern>
     
     > We'd like to add "if-then-else", "while", and "for" statements to our
     > language ...
     > We've investigated many possible solutions.  The one solution that seems
     > the most reasonable involves knowing the position of a TOKEN in yyin.
     
     I strongly advise you to instead build a parse tree (abstract syntax tree)
     and loop over that instead.  You'll find this has major benefits in keeping
     your interpreter simple and extensible.
     
     That said, the functionality you mention for get_position and set_position
     have been on the to-do list for a while.  As flex is a purely spare-time
     project for me, no guarantees when this will be added (in particular, it
     for sure won't be for many months to come).
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="ERASEME55"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#ERASEME56">ERASEME56</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#I-need-to-scan-if_002dthen_002delse-blocks-and-while-loops">I need to scan if-then-else blocks and while loops</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">ERASEME55</h3>

<pre class="example"><pre class="verbatim">     
     To: Colin Paul Adams &lt;colin@colina.demon.co.uk>
     Subject: Re: Flex C++ classes and Bison
     In-reply-to: Your message of 09 Aug 1997 17:11:41 PDT.
     Date: Fri, 15 Aug 1997 10:48:19 PDT
     From: Vern Paxson &lt;vern>
     
     > #define YY_DECL   int yylex (YYSTYPE *lvalp, struct parser_control
     > *parm)
     >
     > I have been trying  to get this to work as a C++ scanner, but it does
     > not appear to be possible (warning that it matches no declarations in
     > yyFlexLexer, or something like that).
     >
     > Is this supposed to be possible, or is it being worked on (I DID
     > notice the comment that scanner classes are still experimental, so I'm
     > not too hopeful)?
     
     What you need to do is derive a subclass from yyFlexLexer that provides
     the above yylex() method, squirrels away lvalp and parm into member
     variables, and then invokes yyFlexLexer::yylex() to do the regular scanning.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="ERASEME56"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#ERASEME57">ERASEME57</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#ERASEME55">ERASEME55</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">ERASEME56</h3>

<pre class="example"><pre class="verbatim">     
     To: Mikael.Latvala@lmf.ericsson.se
     Subject: Re: Possible mistake in Flex v2.5 document
     In-reply-to: Your message of Fri, 05 Sep 1997 16:07:24 PDT.
     Date: Fri, 05 Sep 1997 10:01:54 PDT
     From: Vern Paxson &lt;vern>
     
     > In that example you show how to count comment lines when using
     > C style /* ... */ comments. My question is, shouldn't you take into
     > account a scenario where end of a comment marker occurs inside
     > character or string literals?
     
     The scanner certainly needs to also scan character and string literals.
     However it does that (there's an example in the man page for strings), the
     lexer will recognize the beginning of the literal before it runs across the
     embedded "/*".  Consequently, it will finish scanning the literal before it
     even considers the possibility of matching "/*".
     
     Example:
     
     	'([^']*|{ESCAPE_SEQUENCE})'
     
     will match all the text between the ''s (inclusive).  So the lexer
     considers this as a token beginning at the first ', and doesn't even
     attempt to match other tokens inside it.
     
     I thinnk this subtlety is not worth putting in the manual, as I suspect
     it would confuse more people than it would enlighten.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="ERASEME57"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Is-there-a-repository-for-flex-scanners_003f">Is there a repository for flex scanners?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#ERASEME56">ERASEME56</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">ERASEME57</h3>

<pre class="example"><pre class="verbatim">     
     To: "Marty Leisner" &lt;leisner@sdsp.mc.xerox.com>
     Subject: Re: flex limitations
     In-reply-to: Your message of Sat, 06 Sep 1997 11:27:21 PDT.
     Date: Mon, 08 Sep 1997 11:38:08 PDT
     From: Vern Paxson &lt;vern>
     
     > %%
     > [a-zA-Z]+       /* skip a line */
     >                 {  printf("got %s\n", yytext); }
     > %%
     
     What version of flex are you using?  If I feed this to 2.5.4, it complains:
     
     	"bug.l", line 5: EOF encountered inside an action
     	"bug.l", line 5: unrecognized rule
     	"bug.l", line 5: fatal parse error
     
     Not the world's greatest error message, but it manages to flag the problem.
     
     (With the introduction of start condition scopes, flex can't accommodate
     an action on a separate line, since it's ambiguous with an indented rule.)
     
     You can get 2.5.4 from ftp.ee.lbl.gov.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Is-there-a-repository-for-flex-scanners%3f"></a>
<a name="Is-there-a-repository-for-flex-scanners_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f">How can I conditionally compile or preprocess my flex input file?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#ERASEME57">ERASEME57</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Is there a repository for flex scanners?</h3>

<p>Not that we know of. You might try asking on comp.compilers.

<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="How-can-I-conditionally-compile-or-preprocess-my-flex-input-file%3f"></a>
<a name="How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Where-can-I-find-grammars-for-lex-and-yacc_003f">Where can I find grammars for lex and yacc?</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Is-there-a-repository-for-flex-scanners_003f">Is there a repository for flex scanners?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">How can I conditionally compile or preprocess my flex input file?</h3>

<p>Flex doesn't have a preprocessor like C does.  You might try using m4, or the C
preprocessor plus a sed script to clean up the result.

<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="Where-can-I-find-grammars-for-lex-and-yacc%3f"></a>
<a name="Where-can-I-find-grammars-for-lex-and-yacc_003f"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e">I get an end-of-buffer message for each character scanned.</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#How-can-I-conditionally-compile-or-preprocess-my-flex-input-file_003f">How can I conditionally compile or preprocess my flex input file?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">Where can I find grammars for lex and yacc?</h3>

<p>In the sources for flex and bison.

<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="I-get-an-end-of-buffer-message-for-each-character-scanned."></a>
<a name="I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d62">unnamed-faq-62</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Where-can-I-find-grammars-for-lex-and-yacc_003f">Where can I find grammars for lex and yacc?</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">I get an end-of-buffer message for each character scanned.</h3>

<p>This will happen if your LexerInput() function returns only one character
at a time, which can happen either if you're scanner is "interactive", or
if the streams library on your platform always returns 1 for yyin-&gt;gcount().

   <p>Solution: override LexerInput() with a version that returns whole buffers.

<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-62"></a>
<a name="unnamed_002dfaq_002d62"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d63">unnamed-faq-63</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#I-get-an-end_002dof_002dbuffer-message-for-each-character-scanned_002e">I get an end-of-buffer message for each character scanned.</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-62</h3>

<pre class="example"><pre class="verbatim">     
     To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
     Subject: Re: Flex maximums
     In-reply-to: Your message of Mon, 17 Nov 1997 17:16:06 PST.
     Date: Mon, 17 Nov 1997 17:16:15 PST
     From: Vern Paxson &lt;vern>
     
     > I took a quick look into the flex-sources and altered some #defines in
     > flexdefs.h:
     >
     > 	#define INITIAL_MNS 64000
     > 	#define MNS_INCREMENT 1024000
     > 	#define MAXIMUM_MNS 64000
     
     The things to fix are to add a couple of zeroes to:
     
     #define JAMSTATE -32766 /* marks a reference to the state that always jams */
     #define MAXIMUM_MNS 31999
     #define BAD_SUBSCRIPT -32767
     #define MAX_SHORT 32700
     
     and, if you get complaints about too many rules, make the following change too:
     
     	#define YY_TRAILING_MASK 0x200000
     	#define YY_TRAILING_HEAD_MASK 0x400000
     
     - Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-63"></a>
<a name="unnamed_002dfaq_002d63"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d64">unnamed-faq-64</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d62">unnamed-faq-62</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-63</h3>

<pre class="example"><pre class="verbatim">     
     To: jimmey@lexis-nexis.com (Jimmey Todd)
     Subject: Re: FLEX question regarding istream vs ifstream
     In-reply-to: Your message of Mon, 08 Dec 1997 15:54:15 PST.
     Date: Mon, 15 Dec 1997 13:21:35 PST
     From: Vern Paxson &lt;vern>
     
     >         stdin_handle = YY_CURRENT_BUFFER;
     >         ifstream fin( "aFile" );
     >         yy_switch_to_buffer( yy_create_buffer( fin, YY_BUF_SIZE ) );
     >
     > What I'm wanting to do, is pass the contents of a file thru one set
     > of rules and then pass stdin thru another set... It works great if, I
     > don't use the C++ classes. But since everything else that I'm doing is
     > in C++, I thought I'd be consistent.
     >
     > The problem is that 'yy_create_buffer' is expecting an istream* as it's
     > first argument (as stated in the man page). However, fin is a ifstream
     > object. Any ideas on what I might be doing wrong? Any help would be
     > appreciated. Thanks!!
     
     You need to pass &amp;fin, to turn it into an ifstream* instead of an ifstream.
     Then its type will be compatible with the expected istream*, because ifstream
     is derived from istream.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-64"></a>
<a name="unnamed_002dfaq_002d64"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d65">unnamed-faq-65</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d63">unnamed-faq-63</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-64</h3>

<pre class="example"><pre class="verbatim">     
     To: Enda Fadian &lt;fadiane@piercom.ie>
     Subject: Re: Question related to Flex man page?
     In-reply-to: Your message of Tue, 16 Dec 1997 15:17:34 PST.
     Date: Tue, 16 Dec 1997 14:17:09 PST
     From: Vern Paxson &lt;vern>
     
     > Can you explain to me what is ment by a long-jump in relation to flex?
     
     Using the longjmp() function while inside yylex() or a routine called by it.
     
     > what is the flex activation frame.
     
     Just yylex()'s stack frame.
     
     > As far as I can see yyrestart will bring me back to the sart of the input
     > file and using flex++ isnot really an option!
     
     No, yyrestart() doesn't imply a rewind, even though its name might sound
     like it does.  It tells the scanner to flush its internal buffers and
     start reading from the given file at its present location.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-65"></a>
<a name="unnamed_002dfaq_002d65"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d66">unnamed-faq-66</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d64">unnamed-faq-64</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-65</h3>

<pre class="example"><pre class="verbatim">     
     To: hassan@larc.info.uqam.ca (Hassan Alaoui)
     Subject: Re: Need urgent Help
     In-reply-to: Your message of Sat, 20 Dec 1997 19:38:19 PST.
     Date: Sun, 21 Dec 1997 21:30:46 PST
     From: Vern Paxson &lt;vern>
     
     > /usr/lib/yaccpar: In function `int yyparse()':
     > /usr/lib/yaccpar:184: warning: implicit declaration of function `int yylex(...)'
     >
     > ld: Undefined symbol
     >    _yylex
     >    _yyparse
     >    _yyin
     
     This is a known problem with Solaris C++ (and/or Solaris yacc).  I believe
     the fix is to explicitly insert some 'extern "C"' statements for the
     corresponding routines/symbols.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-66"></a>
<a name="unnamed_002dfaq_002d66"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d67">unnamed-faq-67</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d65">unnamed-faq-65</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-66</h3>

<pre class="example"><pre class="verbatim">     
     To: mc0307@mclink.it
     Cc: gnu@prep.ai.mit.edu
     Subject: Re: [mc0307@mclink.it: Help request]
     In-reply-to: Your message of Fri, 12 Dec 1997 17:57:29 PST.
     Date: Sun, 21 Dec 1997 22:33:37 PST
     From: Vern Paxson &lt;vern>
     
     > This is my definition for float and integer types:
     > . . .
     > NZD          [1-9]
     > ...
     > I've tested my program on other lex version (on UNIX Sun Solaris an HP
     > UNIX) and it work well, so I think that my definitions are correct.
     > There are any differences between Lex and Flex?
     
     There are indeed differences, as discussed in the man page.  The one
     you are probably running into is that when flex expands a name definition,
     it puts parentheses around the expansion, while lex does not.  There's
     an example in the man page of how this can lead to different matching.
     Flex's behavior complies with the POSIX standard (or at least with the
     last POSIX draft I saw).
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-67"></a>
<a name="unnamed_002dfaq_002d67"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d68">unnamed-faq-68</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d66">unnamed-faq-66</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-67</h3>

<pre class="example"><pre class="verbatim">     
     To: hassan@larc.info.uqam.ca (Hassan Alaoui)
     Subject: Re: Thanks
     In-reply-to: Your message of Mon, 22 Dec 1997 16:06:35 PST.
     Date: Mon, 22 Dec 1997 14:35:05 PST
     From: Vern Paxson &lt;vern>
     
     > Thank you very much for your help. I compile and link well with C++ while
     > declaring 'yylex ...' extern, But a little problem remains. I get a
     > segmentation default when executing ( I linked with lfl library) while it
     > works well when using LEX instead of flex. Do you have some ideas about the
     > reason for this ?
     
     The one possible reason for this that comes to mind is if you've defined
     yytext as "extern char yytext[]" (which is what lex uses) instead of
     "extern char *yytext" (which is what flex uses).  If it's not that, then
     I'm afraid I don't know what the problem might be.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-68"></a>
<a name="unnamed_002dfaq_002d68"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d69">unnamed-faq-69</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d67">unnamed-faq-67</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-68</h3>

<pre class="example"><pre class="verbatim">     
     To: "Bart Niswonger" &lt;NISWONGR@almaden.ibm.com>
     Subject: Re: flex 2.5: c++ scanners &amp; start conditions
     In-reply-to: Your message of Tue, 06 Jan 1998 10:34:21 PST.
     Date: Tue, 06 Jan 1998 19:19:30 PST
     From: Vern Paxson &lt;vern>
     
     > The problem is that when I do this (using %option c++) start
     > conditions seem to not apply.
     
     The BEGIN macro modifies the yy_start variable.  For C scanners, this
     is a static with scope visible through the whole file.  For C++ scanners,
     it's a member variable, so it only has visible scope within a member
     function.  Your lexbegin() routine is not a member function when you
     build a C++ scanner, so it's not modifying the correct yy_start.  The
     diagnostic that indicates this is that you found you needed to add
     a declaration of yy_start in order to get your scanner to compile when
     using C++; instead, the correct fix is to make lexbegin() a member
     function (by deriving from yyFlexLexer).
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-69"></a>
<a name="unnamed_002dfaq_002d69"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d70">unnamed-faq-70</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d68">unnamed-faq-68</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-69</h3>

<pre class="example"><pre class="verbatim">     
     To: "Boris Zinin" &lt;boris@ippe.rssi.ru>
     Subject: Re: current position in flex buffer
     In-reply-to: Your message of Mon, 12 Jan 1998 18:58:23 PST.
     Date: Mon, 12 Jan 1998 12:03:15 PST
     From: Vern Paxson &lt;vern>
     
     > The problem is how to determine the current position in flex active
     > buffer when a rule is matched....
     
     You will need to keep track of this explicitly, such as by redefining
     YY_USER_ACTION to count the number of characters matched.
     
     The latest flex release, by the way, is 2.5.4, available from ftp.ee.lbl.gov.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-70"></a>
<a name="unnamed_002dfaq_002d70"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d71">unnamed-faq-71</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d69">unnamed-faq-69</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-70</h3>

<pre class="example"><pre class="verbatim">     
     To: Bik.Dhaliwal@bis.org
     Subject: Re: Flex question
     In-reply-to: Your message of Mon, 26 Jan 1998 13:05:35 PST.
     Date: Tue, 27 Jan 1998 22:41:52 PST
     From: Vern Paxson &lt;vern>
     
     > That requirement involves knowing
     > the character position at which a particular token was matched
     > in the lexer.
     
     The way you have to do this is by explicitly keeping track of where
     you are in the file, by counting the number of characters scanned
     for each token (available in yyleng).  It may prove convenient to
     do this by redefining YY_USER_ACTION, as described in the manual.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-71"></a>
<a name="unnamed_002dfaq_002d71"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d72">unnamed-faq-72</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d70">unnamed-faq-70</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-71</h3>

<pre class="example"><pre class="verbatim">     
     To: Vladimir Alexiev &lt;vladimir@cs.ualberta.ca>
     Subject: Re: flex: how to control start condition from parser?
     In-reply-to: Your message of Mon, 26 Jan 1998 05:50:16 PST.
     Date: Tue, 27 Jan 1998 22:45:37 PST
     From: Vern Paxson &lt;vern>
     
     > It seems useful for the parser to be able to tell the lexer about such
     > context dependencies, because then they don't have to be limited to
     > local or sequential context.
     
     One way to do this is to have the parser call a stub routine that's
     included in the scanner's .l file, and consequently that has access ot
     BEGIN.  The only ugliness is that the parser can't pass in the state
     it wants, because those aren't visible - but if you don't have many
     such states, then using a different set of names doesn't seem like
     to much of a burden.
     
     While generating a .h file like you suggests is certainly cleaner,
     flex development has come to a virtual stand-still :-(, so a workaround
     like the above is much more pragmatic than waiting for a new feature.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-72"></a>
<a name="unnamed_002dfaq_002d72"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d73">unnamed-faq-73</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d71">unnamed-faq-71</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-72</h3>

<pre class="example"><pre class="verbatim">     
     To: Barbara Denny &lt;denny@3com.com>
     Subject: Re: freebsd flex bug?
     In-reply-to: Your message of Fri, 30 Jan 1998 12:00:43 PST.
     Date: Fri, 30 Jan 1998 12:42:32 PST
     From: Vern Paxson &lt;vern>
     
     > lex.yy.c:1996: parse error before `='
     
     This is the key, identifying this error.  (It may help to pinpoint
     it by using flex -L, so it doesn't generate #line directives in its
     output.)  I will bet you heavy money that you have a start condition
     name that is also a variable name, or something like that; flex spits
     out #define's for each start condition name, mapping them to a number,
     so you can wind up with:
     
     	%x foo
     	%%
     		...
     	%%
     	void bar()
     		{
     		int foo = 3;
     		}
     
     and the penultimate will turn into "int 1 = 3" after C preprocessing,
     since flex will put "#define foo 1" in the generated scanner.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-73"></a>
<a name="unnamed_002dfaq_002d73"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d74">unnamed-faq-74</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d72">unnamed-faq-72</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-73</h3>

<pre class="example"><pre class="verbatim">     
     To: Maurice Petrie &lt;mpetrie@infoscigroup.com>
     Subject: Re: Lost flex .l file
     In-reply-to: Your message of Mon, 02 Feb 1998 14:10:01 PST.
     Date: Mon, 02 Feb 1998 11:15:12 PST
     From: Vern Paxson &lt;vern>
     
     > I am curious as to
     > whether there is a simple way to backtrack from the generated source to
     > reproduce the lost list of tokens we are searching on.
     
     In theory, it's straight-forward to go from the DFA representation
     back to a regular-expression representation - the two are isomorphic.
     In practice, a huge headache, because you have to unpack all the tables
     back into a single DFA representation, and then write a program to munch
     on that and translate it into an RE.
     
     Sorry for the less-than-happy news ...
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-74"></a>
<a name="unnamed_002dfaq_002d74"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d75">unnamed-faq-75</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d73">unnamed-faq-73</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-74</h3>

<pre class="example"><pre class="verbatim">     
     To: jimmey@lexis-nexis.com (Jimmey Todd)
     Subject: Re: Flex performance question
     In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
     Date: Thu, 19 Feb 1998 08:48:51 PST
     From: Vern Paxson &lt;vern>
     
     > What I have found, is that the smaller the data chunk, the faster the
     > program executes. This is the opposite of what I expected. Should this be
     > happening this way?
     
     This is exactly what will happen if your input file has embedded NULs.
     From the man page:
     
     A final note: flex is slow when matching NUL's, particularly
     when  a  token  contains multiple NUL's.  It's best to write
     rules which match short amounts of text if it's  anticipated
     that the text will often include NUL's.
     
     So that's the first thing to look for.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-75"></a>
<a name="unnamed_002dfaq_002d75"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d76">unnamed-faq-76</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d74">unnamed-faq-74</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-75</h3>

<pre class="example"><pre class="verbatim">     
     To: jimmey@lexis-nexis.com (Jimmey Todd)
     Subject: Re: Flex performance question
     In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
     Date: Thu, 19 Feb 1998 15:42:25 PST
     From: Vern Paxson &lt;vern>
     
     So there are several problems.
     
     First, to go fast, you want to match as much text as possible, which
     your scanners don't in the case that what they're scanning is *not*
     a &lt;RN> tag.  So you want a rule like:
     
     	[^&lt;]+
     
     Second, C++ scanners are particularly slow if they're interactive,
     which they are by default.  Using -B speeds it up by a factor of 3-4
     on my workstation.
     
     Third, C++ scanners that use the istream interface are slow, because
     of how poorly implemented istream's are.  I built two versions of
     the following scanner:
     
     	%%
     	.*\n
     	.*
     	%%
     
     and the C version inhales a 2.5MB file on my workstation in 0.8 seconds.
     The C++ istream version, using -B, takes 3.8 seconds.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-76"></a>
<a name="unnamed_002dfaq_002d76"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d77">unnamed-faq-77</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d75">unnamed-faq-75</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-76</h3>

<pre class="example"><pre class="verbatim">     
     To: "Frescatore, David (CRD, TAD)" &lt;frescatore@exc01crdge.crd.ge.com>
     Subject: Re: FLEX 2.5 &amp; THE YEAR 2000
     In-reply-to: Your message of Wed, 03 Jun 1998 11:26:22 PDT.
     Date: Wed, 03 Jun 1998 10:22:26 PDT
     From: Vern Paxson &lt;vern>
     
     > I am researching the Y2K problem with General Electric R&amp;D
     > and need to know if there are any known issues concerning
     > the above mentioned software and Y2K regardless of version.
     
     There shouldn't be, all it ever does with the date is ask the system
     for it and then print it out.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-77"></a>
<a name="unnamed_002dfaq_002d77"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d78">unnamed-faq-78</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d76">unnamed-faq-76</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-77</h3>

<pre class="example"><pre class="verbatim">     
     To: "Hans Dermot Doran" &lt;htd@ibhdoran.com>
     Subject: Re: flex problem
     In-reply-to: Your message of Wed, 15 Jul 1998 21:30:13 PDT.
     Date: Tue, 21 Jul 1998 14:23:34 PDT
     From: Vern Paxson &lt;vern>
     
     > To overcome this, I gets() the stdin into a string and lex the string. The
     > string is lexed OK except that the end of string isn't lexed properly
     > (yy_scan_string()), that is the lexer dosn't recognise the end of string.
     
     Flex doesn't contain mechanisms for recognizing buffer endpoints.  But if
     you use fgets instead (which you should anyway, to protect against buffer
     overflows), then the final \n will be preserved in the string, and you can
     scan that in order to find the end of the string.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-78"></a>
<a name="unnamed_002dfaq_002d78"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d79">unnamed-faq-79</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d77">unnamed-faq-77</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-78</h3>

<pre class="example"><pre class="verbatim">     
     To: soumen@almaden.ibm.com
     Subject: Re: Flex++ 2.5.3 instance member vs. static member
     In-reply-to: Your message of Mon, 27 Jul 1998 02:10:04 PDT.
     Date: Tue, 28 Jul 1998 01:10:34 PDT
     From: Vern Paxson &lt;vern>
     
     > %{
     > int mylineno = 0;
     > %}
     > ws      [ \t]+
     > alpha   [A-Za-z]
     > dig     [0-9]
     > %%
     >
     > Now you'd expect mylineno to be a member of each instance of class
     > yyFlexLexer, but is this the case?  A look at the lex.yy.cc file seems to
     > indicate otherwise; unless I am missing something the declaration of
     > mylineno seems to be outside any class scope.
     >
     > How will this work if I want to run a multi-threaded application with each
     > thread creating a FlexLexer instance?
     
     Derive your own subclass and make mylineno a member variable of it.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-79"></a>
<a name="unnamed_002dfaq_002d79"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d80">unnamed-faq-80</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d78">unnamed-faq-78</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-79</h3>

<pre class="example"><pre class="verbatim">     
     To: Adoram Rogel &lt;adoram@hybridge.com>
     Subject: Re: More than 32K states change hangs
     In-reply-to: Your message of Tue, 04 Aug 1998 16:55:39 PDT.
     Date: Tue, 04 Aug 1998 22:28:45 PDT
     From: Vern Paxson &lt;vern>
     
     > Vern Paxson,
     >
     > I followed your advice, posted on Usenet bu you, and emailed to me
     > personally by you, on how to overcome the 32K states limit. I'm running
     > on Linux machines.
     > I took the full source of version 2.5.4 and did the following changes in
     > flexdef.h:
     > #define JAMSTATE -327660
     > #define MAXIMUM_MNS 319990
     > #define BAD_SUBSCRIPT -327670
     > #define MAX_SHORT 327000
     >
     > and compiled.
     > All looked fine, including check and bigcheck, so I installed.
     
     Hmmm, you shouldn't increase MAX_SHORT, though looking through my email
     archives I see that I did indeed recommend doing so.  Try setting it back
     to 32700; that should suffice that you no longer need -Ca.  If it still
     hangs, then the interesting question is - where?
     
     > Compiling the same hanged program with a out-of-the-box (RedHat 4.2
     > distribution of Linux)
     > flex 2.5.4 binary works.
     
     Since Linux comes with source code, you should diff it against what
     you have to see what problems they missed.
     
     > Should I always compile with the -Ca option now ? even short and simple
     > filters ?
     
     No, definitely not.  It's meant to be for those situations where you
     absolutely must squeeze every last cycle out of your scanner.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-80"></a>
<a name="unnamed_002dfaq_002d80"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d81">unnamed-faq-81</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d79">unnamed-faq-79</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-80</h3>

<pre class="example"><pre class="verbatim">     
     To: "Schmackpfeffer, Craig" &lt;Craig.Schmackpfeffer@usa.xerox.com>
     Subject: Re: flex output for static code portion
     In-reply-to: Your message of Tue, 11 Aug 1998 11:55:30 PDT.
     Date: Mon, 17 Aug 1998 23:57:42 PDT
     From: Vern Paxson &lt;vern>
     
     > I would like to use flex under the hood to generate a binary file
     > containing the data structures that control the parse.
     
     This has been on the wish-list for a long time.  In principle it's
     straight-forward - you redirect mkdata() et al's I/O to another file,
     and modify the skeleton to have a start-up function that slurps these
     into dynamic arrays.  The concerns are (1) the scanner generation code
     is hairy and full of corner cases, so it's easy to get surprised when
     going down this path :-( ; and (2) being careful about buffering so
     that when the tables change you make sure the scanner starts in the
     correct state and reading at the right point in the input file.
     
     > I was wondering if you know of anyone who has used flex in this way.
     
     I don't - but it seems like a reasonable project to undertake (unlike
     numerous other flex tweaks :-).
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-81"></a>
<a name="unnamed_002dfaq_002d81"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d82">unnamed-faq-82</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d80">unnamed-faq-80</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-81</h3>

<pre class="example"><pre class="verbatim">     
     Received: from 131.173.17.11 (131.173.17.11 [131.173.17.11])
     	by ee.lbl.gov (8.9.1/8.9.1) with ESMTP id AAA03838
     	for &lt;vern@ee.lbl.gov>; Thu, 20 Aug 1998 00:47:57 -0700 (PDT)
     Received: from hal.cl-ki.uni-osnabrueck.de (hal.cl-ki.Uni-Osnabrueck.DE [131.173.141.2])
     	by deimos.rz.uni-osnabrueck.de (8.8.7/8.8.8) with ESMTP id JAA34694
     	for &lt;vern@ee.lbl.gov>; Thu, 20 Aug 1998 09:47:55 +0200
     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
     From: Georg Rehm &lt;georg@hal.cl-ki.uni-osnabrueck.de>
     Message-Id: &lt;199808200747.JAA34834@hal.cl-ki.uni-osnabrueck.de>
     Subject: "flex scanner push-back overflow"
     To: vern@ee.lbl.gov
     Date: Thu, 20 Aug 1998 09:47:54 +0200 (MEST)
     Reply-To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
     X-NoJunk: Do NOT send commercial mail, spam or ads to this address!
     X-URL: http://www.cl-ki.uni-osnabrueck.de/~georg/
     X-Mailer: ELM [version 2.4ME+ PL28 (25)]
     MIME-Version: 1.0
     Content-Type: text/plain; charset=US-ASCII
     Content-Transfer-Encoding: 7bit
     
     Hi Vern,
     
     Yesterday, I encountered a strange problem: I use the macro processor m4
     to include some lengthy lists into a .l file. Following is a flex macro
     definition that causes some serious pain in my neck:
     
     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"| [...])
     
     The complete list contains about 10kB. When I try to "flex" this file
     (on a Solaris 2.6 machine, using a modified flex 2.5.4 (I only increased
     some of the predefined values in flexdefs.h) I get the error:
     
     myflex/flex -8  sentag.tmp.l
     flex scanner push-back overflow
     
     When I remove the slashes in the macro definition everything works fine.
     As I understand it, the double quotes escape the slash-character so it
     really means "/" and not "trailing context". Furthermore, I tried to
     escape the slashes with backslashes, but with no use, the same error message
     appeared when flexing the code.
     
     Do you have an idea what's going on here?
     
     Greetings from Germany,
     	Georg
     --
     Georg Rehm                                     georg@cl-ki.uni-osnabrueck.de
     Institute for Semantic Information Processing, University of Osnabrueck, FRG
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-82"></a>
<a name="unnamed_002dfaq_002d82"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d83">unnamed-faq-83</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d81">unnamed-faq-81</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-82</h3>

<pre class="example"><pre class="verbatim">     
     To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
     Subject: Re: "flex scanner push-back overflow"
     In-reply-to: Your message of Thu, 20 Aug 1998 09:47:54 PDT.
     Date: Thu, 20 Aug 1998 07:05:35 PDT
     From: Vern Paxson &lt;vern>
     
     > myflex/flex -8  sentag.tmp.l
     > flex scanner push-back overflow
     
     Flex itself uses a flex scanner.  That scanner is running out of buffer
     space when it tries to unput() the humongous macro you've defined.  When
     you remove the '/'s, you make it small enough so that it fits in the buffer;
     removing spaces would do the same thing.
     
     The fix is to either rethink how come you're using such a big macro and
     perhaps there's another/better way to do it; or to rebuild flex's own
     scan.c with a larger value for
     
     	#define YY_BUF_SIZE 16384
     
     - Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-83"></a>
<a name="unnamed_002dfaq_002d83"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d84">unnamed-faq-84</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d82">unnamed-faq-82</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-83</h3>

<pre class="example"><pre class="verbatim">     
     To: Jan Kort &lt;jan@research.techforce.nl>
     Subject: Re: Flex
     In-reply-to: Your message of Fri, 04 Sep 1998 12:18:43 +0200.
     Date: Sat, 05 Sep 1998 00:59:49 PDT
     From: Vern Paxson &lt;vern>
     
     > %%
     >
     > "TEST1\n"       { fprintf(stderr, "TEST1\n"); yyless(5); }
     > ^\n             { fprintf(stderr, "empty line\n"); }
     > .               { }
     > \n              { fprintf(stderr, "new line\n"); }
     >
     > %%
     > -- input ---------------------------------------
     > TEST1
     > -- output --------------------------------------
     > TEST1
     > empty line
     > ------------------------------------------------
     
     IMHO, it's not clear whether or not this is in fact a bug.  It depends
     on whether you view yyless() as backing up in the input stream, or as
     pushing new characters onto the beginning of the input stream.  Flex
     interprets it as the latter (for implementation convenience, I'll admit),
     and so considers the newline as in fact matching at the beginning of a
     line, as after all the last token scanned an entire line and so the
     scanner is now at the beginning of a new line.
     
     I agree that this is counter-intuitive for yyless(), given its
     functional description (it's less so for unput(), depending on whether
     you're unput()'ing new text or scanned text).  But I don't plan to
     change it any time soon, as it's a pain to do so.  Consequently,
     you do indeed need to use yy_set_bol() and YY_AT_BOL() to tweak
     your scanner into the behavior you desire.
     
     Sorry for the less-than-completely-satisfactory answer.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-84"></a>
<a name="unnamed_002dfaq_002d84"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d85">unnamed-faq-85</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d83">unnamed-faq-83</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-84</h3>

<pre class="example"><pre class="verbatim">     
     To: Patrick Krusenotto &lt;krusenot@mac-info-link.de>
     Subject: Re: Problems with restarting flex-2.5.2-generated scanner
     In-reply-to: Your message of Thu, 24 Sep 1998 10:14:07 PDT.
     Date: Thu, 24 Sep 1998 23:28:43 PDT
     From: Vern Paxson &lt;vern>
     
     > I am using flex-2.5.2 and bison 1.25 for Solaris and I am desperately
     > trying to make my scanner restart with a new file after my parser stops
     > with a parse error. When my compiler restarts, the parser always
     > receives the token after the token (in the old file!) that caused the
     > parser error.
     
     I suspect the problem is that your parser has read ahead in order
     to attempt to resolve an ambiguity, and when it's restarted it picks
     up with that token rather than reading a fresh one.  If you're using
     yacc, then the special "error" production can sometimes be used to
     consume tokens in an attempt to get the parser into a consistent state.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-85"></a>
<a name="unnamed_002dfaq_002d85"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d86">unnamed-faq-86</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d84">unnamed-faq-84</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-85</h3>

<pre class="example"><pre class="verbatim">     
     To: Henric Jungheim &lt;junghelh@pe-nelson.com>
     Subject: Re: flex 2.5.4a
     In-reply-to: Your message of Tue, 27 Oct 1998 16:41:42 PST.
     Date: Tue, 27 Oct 1998 16:50:14 PST
     From: Vern Paxson &lt;vern>
     
     > This brings up a feature request:  How about a command line
     > option to specify the filename when reading from stdin?  That way one
     > doesn't need to create a temporary file in order to get the "#line"
     > directives to make sense.
     
     Use -o combined with -t (per the man page description of -o).
     
     > P.S., Is there any simple way to use non-blocking IO to parse multiple
     > streams?
     
     Simple, no.
     
     One approach might be to return a magic character on EWOULDBLOCK and
     have a rule
     
     	.*&lt;magic-character>	// put back .*, eat magic character
     
     This is off the top of my head, not sure it'll work.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-86"></a>
<a name="unnamed_002dfaq_002d86"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d87">unnamed-faq-87</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d85">unnamed-faq-85</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-86</h3>

<pre class="example"><pre class="verbatim">     
     To: "Repko, Billy D" &lt;billy.d.repko@intel.com>
     Subject: Re: Compiling scanners
     In-reply-to: Your message of Wed, 13 Jan 1999 10:52:47 PST.
     Date: Thu, 14 Jan 1999 00:25:30 PST
     From: Vern Paxson &lt;vern>
     
     > It appears that maybe it cannot find the lfl library.
     
     The Makefile in the distribution builds it, so you should have it.
     It's exceedingly trivial, just a main() that calls yylex() and
     a yyrap() that always returns 1.
     
     > %%
     >       \n      ++num_lines; ++num_chars;
     >       .       ++num_chars;
     
     You can't indent your rules like this - that's where the errors are coming
     from.  Flex copies indented text to the output file, it's how you do things
     like
     
     	int num_lines_seen = 0;
     
     to declare local variables.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-87"></a>
<a name="unnamed_002dfaq_002d87"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d88">unnamed-faq-88</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d86">unnamed-faq-86</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-87</h3>

<pre class="example"><pre class="verbatim">     
     To: Erick Branderhorst &lt;Erick.Branderhorst@asml.nl>
     Subject: Re: flex input buffer
     In-reply-to: Your message of Tue, 09 Feb 1999 13:53:46 PST.
     Date: Tue, 09 Feb 1999 21:03:37 PST
     From: Vern Paxson &lt;vern>
     
     > In the flex.skl file the size of the default input buffers is set.  Can you
     > explain why this size is set and why it is such a high number.
     
     It's large to optimize performance when scanning large files.  You can
     safely make it a lot lower if needed.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-88"></a>
<a name="unnamed_002dfaq_002d88"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d90">unnamed-faq-90</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d87">unnamed-faq-87</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-88</h3>

<pre class="example"><pre class="verbatim">     
     To: "Guido Minnen" &lt;guidomi@cogs.susx.ac.uk>
     Subject: Re: Flex error message
     In-reply-to: Your message of Wed, 24 Feb 1999 15:31:46 PST.
     Date: Thu, 25 Feb 1999 00:11:31 PST
     From: Vern Paxson &lt;vern>
     
     > I'm extending a larger scanner written in Flex and I keep running into
     > problems. More specifically, I get the error message:
     > "flex: input rules are too complicated (>= 32000 NFA states)"
     
     Increase the definitions in flexdef.h for:
     
     #define JAMSTATE -32766 /* marks a reference to the state that always j
     ams */
     #define MAXIMUM_MNS 31999
     #define BAD_SUBSCRIPT -32767
     
     recompile everything, and it should all work.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-90"></a>
<a name="unnamed_002dfaq_002d90"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d91">unnamed-faq-91</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d88">unnamed-faq-88</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-90</h3>

<pre class="example"><pre class="verbatim">     
     To: "Dmitriy Goldobin" &lt;gold@ems.chel.su>
     Subject: Re: FLEX trouble
     In-reply-to: Your message of Mon, 31 May 1999 18:44:49 PDT.
     Date: Tue, 01 Jun 1999 00:15:07 PDT
     From: Vern Paxson &lt;vern>
     
     >   I have a trouble with FLEX. Why rule "/*".*"*/" work properly,=20
     > but rule "/*"(.|\n)*"*/" don't work ?
     
     The second of these will have to scan the entire input stream (because
     "(.|\n)*" matches an arbitrary amount of any text) in order to see if
     it ends with "*/", terminating the comment.  That potentially will overflow
     the input buffer.
     
     >   More complex rule "/*"([^*]|(\*/[^/]))*"*/ give an error
     > 'unrecognized rule'.
     
     You can't use the '/' operator inside parentheses.  It's not clear
     what "(a/b)*" actually means.
     
     >   I now use workaround with state &lt;comment>, but single-rule is
     > better, i think.
     
     Single-rule is nice but will always have the problem of either setting
     restrictions on comments (like not allowing multi-line comments) and/or
     running the risk of consuming the entire input stream, as noted above.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-91"></a>
<a name="unnamed_002dfaq_002d91"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d92">unnamed-faq-92</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d90">unnamed-faq-90</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-91</h3>

<pre class="example"><pre class="verbatim">     
     Received: from mc-qout4.whowhere.com (mc-qout4.whowhere.com [209.185.123.18])
     	by ee.lbl.gov (8.9.3/8.9.3) with SMTP id IAA05100
     	for &lt;vern@ee.lbl.gov>; Tue, 15 Jun 1999 08:56:06 -0700 (PDT)
     Received: from Unknown/Local ([?.?.?.?]) by my-deja.com; Tue Jun 15 08:55:43 1999
     To: vern@ee.lbl.gov
     Date: Tue, 15 Jun 1999 08:55:43 -0700
     From: "Aki Niimura" &lt;neko@my-deja.com>
     Message-ID: &lt;KNONDOHDOBGAEAAA@my-deja.com>
     Mime-Version: 1.0
     Cc:
     X-Sent-Mail: on
     Reply-To:
     X-Mailer: MailCity Service
     Subject: A question on flex C++ scanner
     X-Sender-Ip: 12.72.207.61
     Organization: My Deja Email  (http://www.my-deja.com:80)
     Content-Type: text/plain; charset=us-ascii
     Content-Transfer-Encoding: 7bit
     
     Dear Dr. Paxon,
     
     I have been using flex for years.
     It works very well on many projects.
     Most case, I used it to generate a scanner on C language.
     However, one project I needed to generate  a scanner
     on C++ lanuage. Thanks to your enhancement, flex did
     the job.
     
     Currently, I'm working on enhancing my previous project.
     I need to deal with multiple input streams (recursive
     inclusion) in this scanner (C++).
     I did similar thing for another scanner (C) as you
     explained in your documentation.
     
     The generated scanner (C++) has necessary methods:
     - switch_to_buffer(struct yy_buffer_state *b)
     - yy_create_buffer(istream *is, int sz)
     - yy_delete_buffer(struct yy_buffer_state *b)
     
     However, I couldn't figure out how to access current
     buffer (yy_current_buffer).
     
     yy_current_buffer is a protected member of yyFlexLexer.
     I can't access it directly.
     Then, I thought yy_create_buffer() with is = 0 might
     return current stream buffer. But it seems not as far
     as I checked the source. (flex 2.5.4)
     
     I went through the Web in addition to Flex documentation.
     However, it hasn't been successful, so far.
     
     It is not my intention to bother you, but, can you
     comment about how to obtain the current stream buffer?
     
     Your response would be highly appreciated.
     
     Best regards,
     Aki Niimura
     
     --== Sent via Deja.com http://www.deja.com/ ==--
     Share what you know. Learn what you don't.
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-92"></a>
<a name="unnamed_002dfaq_002d92"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d93">unnamed-faq-93</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d91">unnamed-faq-91</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-92</h3>

<pre class="example"><pre class="verbatim">     
     To: neko@my-deja.com
     Subject: Re: A question on flex C++ scanner
     In-reply-to: Your message of Tue, 15 Jun 1999 08:55:43 PDT.
     Date: Tue, 15 Jun 1999 09:04:24 PDT
     From: Vern Paxson &lt;vern>
     
     > However, I couldn't figure out how to access current
     > buffer (yy_current_buffer).
     
     Derive your own subclass from yyFlexLexer.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-93"></a>
<a name="unnamed_002dfaq_002d93"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d94">unnamed-faq-94</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d92">unnamed-faq-92</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-93</h3>

<pre class="example"><pre class="verbatim">     
     To: "Stones, Darren" &lt;Darren.Stones@nectech.co.uk>
     Subject: Re: You're the man to see?
     In-reply-to: Your message of Wed, 23 Jun 1999 11:10:29 PDT.
     Date: Wed, 23 Jun 1999 09:01:40 PDT
     From: Vern Paxson &lt;vern>
     
     > I hope you can help me.  I am using Flex and Bison to produce an interpreted
     > language.  However all goes well until I try to implement an IF statement or
     > a WHILE.  I cannot get this to work as the parser parses all the conditions
     > eg. the TRUE and FALSE conditons to check for a rule match.  So I cannot
     > make a decision!!
     
     You need to use the parser to build a parse tree (= abstract syntax trwee),
     and when that's all done you recursively evaluate the tree, binding variables
     to values at that time.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-94"></a>
<a name="unnamed_002dfaq_002d94"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d95">unnamed-faq-95</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d93">unnamed-faq-93</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-94</h3>

<pre class="example"><pre class="verbatim">     
     To: Petr Danecek &lt;petr@ics.cas.cz>
     Subject: Re: flex - question
     In-reply-to: Your message of Mon, 28 Jun 1999 19:21:41 PDT.
     Date: Fri, 02 Jul 1999 16:52:13 PDT
     From: Vern Paxson &lt;vern>
     
     > file, it takes an enormous amount of time. It is funny, because the
     > source code has only 12 rules!!! I think it looks like an exponencial
     > growth.
     
     Right, that's the problem - some patterns (those with a lot of
     ambiguity, where yours has because at any given time the scanner can
     be in the middle of all sorts of combinations of the different
     rules) blow up exponentially.
     
     For your rules, there is an easy fix.  Change the ".*" that comes fater
     the directory name to "[^ ]*".  With that in place, the rules are no
     longer nearly so ambiguous, because then once one of the directories
     has been matched, no other can be matched (since they all require a
     leading blank).
     
     If that's not an acceptable solution, then you can enter a start state
     to pick up the .*\n after each directory is matched.
     
     Also note that for speed, you'll want to add a ".*" rule at the end,
     otherwise rules that don't match any of the patterns will be matched
     very slowly, a character at a time.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-95"></a>
<a name="unnamed_002dfaq_002d95"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d96">unnamed-faq-96</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d94">unnamed-faq-94</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-95</h3>

<pre class="example"><pre class="verbatim">     
     To: Tielman Koekemoer &lt;tielman@spi.co.za>
     Subject: Re: Please help.
     In-reply-to: Your message of Thu, 08 Jul 1999 13:20:37 PDT.
     Date: Thu, 08 Jul 1999 08:20:39 PDT
     From: Vern Paxson &lt;vern>
     
     > I was hoping you could help me with my problem.
     >
     > I tried compiling (gnu)flex on a Solaris 2.4 machine
     > but when I ran make (after configure) I got an error.
     >
     > --------------------------------------------------------------
     > gcc -c -I. -I. -g -O parse.c
     > ./flex -t -p  ./scan.l >scan.c
     > sh: ./flex: not found
     > *** Error code 1
     > make: Fatal error: Command failed for target `scan.c'
     > -------------------------------------------------------------
     >
     > What's strange to me is that I'm only
     > trying to install flex now. I then edited the Makefile to
     > and changed where it says "FLEX = flex" to "FLEX = lex"
     > ( lex: the native Solaris one ) but then it complains about
     > the "-p" option. Is there any way I can compile flex without
     > using flex or lex?
     >
     > Thanks so much for your time.
     
     You managed to step on the bootstrap sequence, which first copies
     initscan.c to scan.c in order to build flex.  Try fetching a fresh
     distribution from ftp.ee.lbl.gov.  (Or you can first try removing
     ".bootstrap" and doing a make again.)
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-96"></a>
<a name="unnamed_002dfaq_002d96"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d97">unnamed-faq-97</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d95">unnamed-faq-95</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-96</h3>

<pre class="example"><pre class="verbatim">     
     To: Tielman Koekemoer &lt;tielman@spi.co.za>
     Subject: Re: Please help.
     In-reply-to: Your message of Fri, 09 Jul 1999 09:16:14 PDT.
     Date: Fri, 09 Jul 1999 00:27:20 PDT
     From: Vern Paxson &lt;vern>
     
     > First I removed .bootstrap (and ran make) - no luck. I downloaded the
     > software but I still have the same problem. Is there anything else I
     > could try.
     
     Try:
     
     	cp initscan.c scan.c
     	touch scan.c
     	make scan.o
     
     If this last tries to first build scan.c from scan.l using ./flex, then
     your "make" is broken, in which case compile scan.c to scan.o by hand.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-97"></a>
<a name="unnamed_002dfaq_002d97"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d98">unnamed-faq-98</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d96">unnamed-faq-96</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-97</h3>

<pre class="example"><pre class="verbatim">     
     To: Sumanth Kamenani &lt;skamenan@crl.nmsu.edu>
     Subject: Re: Error
     In-reply-to: Your message of Mon, 19 Jul 1999 23:08:41 PDT.
     Date: Tue, 20 Jul 1999 00:18:26 PDT
     From: Vern Paxson &lt;vern>
     
     > I am getting a compilation error. The error is given as "unknown symbol- yylex".
     
     The parser relies on calling yylex(), but you're instead using the C++ scanning
     class, so you need to supply a yylex() "glue" function that calls an instance
     scanner of the scanner (e.g., "scanner->yylex()").
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-98"></a>
<a name="unnamed_002dfaq_002d98"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d99">unnamed-faq-99</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d97">unnamed-faq-97</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-98</h3>

<pre class="example"><pre class="verbatim">     
     To: daniel@synchrods.synchrods.COM (Daniel Senderowicz)
     Subject: Re: lex
     In-reply-to: Your message of Mon, 22 Nov 1999 11:19:04 PST.
     Date: Tue, 23 Nov 1999 15:54:30 PST
     From: Vern Paxson &lt;vern>
     
     Well, your problem is the
     
     switch (yybgin-yysvec-1) {      /* witchcraft */
     
     at the beginning of lex rules.  "witchcraft" == "non-portable".  It's
     assuming knowledge of the AT&amp;T lex's internal variables.
     
     For flex, you can probably do the equivalent using a switch on YYSTATE.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-99"></a>
<a name="unnamed_002dfaq_002d99"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d100">unnamed-faq-100</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d98">unnamed-faq-98</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-99</h3>

<pre class="example"><pre class="verbatim">     
     To: archow@hss.hns.com
     Subject: Re: Regarding distribution of flex and yacc based grammars
     In-reply-to: Your message of Sun, 19 Dec 1999 17:50:24 +0530.
     Date: Wed, 22 Dec 1999 01:56:24 PST
     From: Vern Paxson &lt;vern>
     
     > When we provide the customer with an object code distribution, is it
     > necessary for us to provide source
     > for the generated C files from flex and bison since they are generated by
     > flex and bison ?
     
     For flex, no.  I don't know what the current state of this is for bison.
     
     > Also, is there any requrirement for us to neccessarily  provide source for
     > the grammar files which are fed into flex and bison ?
     
     Again, for flex, no.
     
     See the file "COPYING" in the flex distribution for the legalese.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-100"></a>
<a name="unnamed_002dfaq_002d100"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#unnamed_002dfaq_002d101">unnamed-faq-101</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d99">unnamed-faq-99</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-100</h3>

<pre class="example"><pre class="verbatim">     
     To: Martin Gallwey &lt;gallweym@hyperion.moe.ul.ie>
     Subject: Re: Flex, and self referencing rules
     In-reply-to: Your message of Sun, 20 Feb 2000 01:01:21 PST.
     Date: Sat, 19 Feb 2000 18:33:16 PST
     From: Vern Paxson &lt;vern>
     
     > However, I do not use unput anywhere. I do use self-referencing
     > rules like this:
     >
     > UnaryExpr               ({UnionExpr})|("-"{UnaryExpr})
     
     You can't do this - flex is *not* a parser like yacc (which does indeed
     allow recursion), it is a scanner that's confined to regular expressions.
     
     		Vern
</pre>
</pre>
<!-- TODO: Evaluate this faq. -->
<div class="node">
<p><hr>
<a name="unnamed-faq-101"></a>
<a name="unnamed_002dfaq_002d101"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#unnamed_002dfaq_002d100">unnamed-faq-100</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#FAQ">FAQ</a>

</div>

<h3 class="unnumberedsec">unnamed-faq-101</h3>

<pre class="example"><pre class="verbatim">     
     To: slg3@lehigh.edu (SAMUEL L. GULDEN)
     Subject: Re: Flex problem
     In-reply-to: Your message of Thu, 02 Mar 2000 12:29:04 PST.
     Date: Thu, 02 Mar 2000 23:00:46 PST
     From: Vern Paxson &lt;vern>
     
     If this is exactly your program:
     
     > digit [0-9]
     > digits {digit}+
     > whitespace [ \t\n]+
     >
     > %%
     > "[" { printf("open_brac\n");}
     > "]" { printf("close_brac\n");}
     > "+" { printf("addop\n");}
     > "*" { printf("multop\n");}
     > {digits} { printf("NUMBER = %s\n", yytext);}
     > whitespace ;
     
     then the problem is that the last rule needs to be "{whitespace}" !
     
     		Vern
</pre>
</pre>
<div class="node">
<p><hr>
<a name="Appendices"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Indices">Indices</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#FAQ">FAQ</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="appendix">Appendix A Appendices</h2>

<ul class="menu">
<li><a accesskey="1" href="#Makefiles-and-Flex">Makefiles and Flex</a>
<li><a accesskey="2" href="#Bison-Bridge">Bison Bridge</a>
<li><a accesskey="3" href="#M4-Dependency">M4 Dependency</a>
</ul>

<div class="node">
<p><hr>
<a name="Makefiles-and-Flex"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Bison-Bridge">Bison Bridge</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Appendices">Appendices</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Appendices">Appendices</a>

</div>

<h3 class="appendixsec">A.1 Makefiles and Flex</h3>

<p><a name="index-Makefile_002c-syntax-487"></a>
In this appendix, we provide tips for writing Makefiles to build your scanners.

   <p>In a traditional build environment, we say that the <samp><span class="file">.c</span></samp> files are the
sources, and the <samp><span class="file">.o</span></samp> files are the intermediate files. When using
<code>flex</code>, however, the <samp><span class="file">.l</span></samp> files are the sources, and the generated
<samp><span class="file">.c</span></samp> files (along with the <samp><span class="file">.o</span></samp> files) are the intermediate files. 
This requires you to carefully plan your Makefile.

   <p>Modern <samp><span class="command">make</span></samp> programs understand that <samp><span class="file">foo.l</span></samp> is intended to
generate <samp><span class="file">lex.yy.c</span></samp> or <samp><span class="file">foo.c</span></samp>, and will behave
accordingly<a rel="footnote" href="#fn-4" name="fnd-4"><sup>4</sup></a>.  The
following Makefile does not explicitly instruct <samp><span class="command">make</span></samp> how to build
<samp><span class="file">foo.c</span></samp> from <samp><span class="file">foo.l</span></samp>. Instead, it relies on the implicit rules of the
<samp><span class="command">make</span></samp> program to build the intermediate file, <samp><span class="file">scan.c</span></samp>:

   <p><a name="index-Makefile_002c-example-of-implicit-rules-488"></a>
<pre class="example"><pre class="verbatim">     
         # Basic Makefile -- relies on implicit rules
         # Creates "myprogram" from "scan.l" and "myprogram.c"
         #
         LEX=flex
         myprogram: scan.o myprogram.o
         scan.o: scan.l
     
</pre>
</pre>
   <p>For simple cases, the above may be sufficient. For other cases,
you may have to explicitly instruct <samp><span class="command">make</span></samp> how to build your scanner. 
The following is an example of a Makefile containing explicit rules:

   <p><a name="index-Makefile_002c-explicit-example-489"></a>
<pre class="example"><pre class="verbatim">     
         # Basic Makefile -- provides explicit rules
         # Creates "myprogram" from "scan.l" and "myprogram.c"
         #
         LEX=flex
         myprogram: scan.o myprogram.o
                 $(CC) -o $@  $(LDFLAGS) $^
     
         myprogram.o: myprogram.c
                 $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
     
         scan.o: scan.c
                 $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
     
         scan.c: scan.l
                 $(LEX) $(LFLAGS) -o $@ $^
     
         clean:
                 $(RM) *.o scan.c
     
</pre>
</pre>
   <p>Notice in the above example that <samp><span class="file">scan.c</span></samp> is in the <code>clean</code> target. 
This is because we consider the file <samp><span class="file">scan.c</span></samp> to be an intermediate file.

   <p>Finally, we provide a realistic example of a <code>flex</code> scanner used with a
<code>bison</code> parser<a rel="footnote" href="#fn-5" name="fnd-5"><sup>5</sup></a>. 
There is a tricky problem we have to deal with. Since a <code>flex</code> scanner
will typically include a header file (e.g., <samp><span class="file">y.tab.h</span></samp>) generated by the
parser, we need to be sure that the header file is generated BEFORE the scanner
is compiled. We handle this case in the following example:

<pre class="example"><pre class="verbatim">     
         # Makefile example -- scanner and parser.
         # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
         #
         LEX     = flex
         YACC    = bison -y
         YFLAGS  = -d
         objects = scan.o parse.o myprogram.o
     
         myprogram: $(objects)
         scan.o: scan.l parse.c
         parse.o: parse.y
         myprogram.o: myprogram.c
     
</pre>
</pre>
   <p>In the above example, notice the line,

<pre class="example"><pre class="verbatim">     
         scan.o: scan.l parse.c
</pre>
</pre>
   <p>, which lists the file <samp><span class="file">parse.c</span></samp> (the generated parser) as a dependency of
<samp><span class="file">scan.o</span></samp>. We want to ensure that the parser is created before the scanner
is compiled, and the above line seems to do the trick. Feel free to experiment
with your specific implementation of <samp><span class="command">make</span></samp>.

   <p>For more details on writing Makefiles, see <a href="make.html#Top">Top</a>.

<div class="node">
<p><hr>
<a name="Bison-Bridge"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#M4-Dependency">M4 Dependency</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Makefiles-and-Flex">Makefiles and Flex</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Appendices">Appendices</a>

</div>

<h3 class="section">A.2 C Scanners with Bison Parsers</h3>

<p><a name="index-bison_002c-bridging-with-flex-490"></a><a name="index-yylval-491"></a><a name="index-yylloc-492"></a><a name="index-YYLTYPE-493"></a><a name="index-YYSTYPE-494"></a>
This section describes the <code>flex</code> features useful when integrating
<code>flex</code> with <code>GNU bison</code><a rel="footnote" href="#fn-6" name="fnd-6"><sup>6</sup></a>. 
Skip this section if you are not using
<code>bison</code> with your scanner.  Here we discuss only the <code>flex</code>
half of the <code>flex</code> and <code>bison</code> pair.  We do not discuss
<code>bison</code> in any detail.  For more information about generating
<code>bison</code> parsers, see <a href="bison.html#Top">Top</a>.

   <p>A compatible <code>bison</code> scanner is generated by declaring `<samp><span class="samp">%option
bison-bridge</span></samp>' or by supplying `<samp><span class="samp">--bison-bridge</span></samp>' when invoking <code>flex</code>
from the command line.  This instructs <code>flex</code> that the macro
<code>yylval</code> may be used. The data type for
<code>yylval</code>, <code>YYSTYPE</code>,
is typically defined in a header file, included in section 1 of the
<code>flex</code> input file.  For a list of functions and macros
available, See <a href="#bison_002dfunctions">bison-functions</a>.

   <p>The declaration of yylex becomes,

   <p><a name="index-yylex-_0028reentrant-version_0029-495"></a>
<pre class="example"><pre class="verbatim">     
           int yylex ( YYSTYPE * lvalp, yyscan_t scanner );
</pre>
</pre>
   <p>If <code>%option bison-locations</code> is specified, then the declaration
becomes,

   <p><a name="index-yylex-_0028reentrant-version_0029-496"></a>
<pre class="example"><pre class="verbatim">     
           int yylex ( YYSTYPE * lvalp, YYLTYPE * llocp, yyscan_t scanner );
</pre>
</pre>
   <p>Note that the macros <code>yylval</code> and <code>yylloc</code> evaluate to pointers. 
Support for <code>yylloc</code> is optional in <code>bison</code>, so it is optional in
<code>flex</code> as well. The following is an example of a <code>flex</code> scanner that
is compatible with <code>bison</code>.

   <p><a name="index-bison_002c-scanner-to-be-called-from-bison-497"></a>
<pre class="example"><pre class="verbatim">     
         /* Scanner for "C" assignment statements... sort of. */
         %{
         #include "y.tab.h"  /* Generated by bison. */
         %}
     
         %option bison-bridge bison-locations
         %
     
         [[:digit:]]+  { yylval->num = atoi(yytext);   return NUMBER;}
         [[:alnum:]]+  { yylval->str = strdup(yytext); return STRING;}
         "="|";"       { return yytext[0];}
         .  {}
         %
</pre>
</pre>
   <p>As you can see, there really is no magic here. We just use
<code>yylval</code> as we would any other variable. The data type of
<code>yylval</code> is generated by <code>bison</code>, and included in the file
<samp><span class="file">y.tab.h</span></samp>. Here is the corresponding <code>bison</code> parser:

   <p><a name="index-bison_002c-parser-498"></a>
<pre class="example"><pre class="verbatim">     
         /* Parser to convert "C" assignments to lisp. */
         %{
         /* Pass the argument to yyparse through to yylex. */
         #define YYPARSE_PARAM scanner
         #define YYLEX_PARAM   scanner
         %}
         %locations
         %pure_parser
         %union {
             int num;
             char* str;
         }
         %token &lt;str> STRING
         %token &lt;num> NUMBER
         %%
         assignment:
             STRING '=' NUMBER ';' {
                 printf( "(setf %s %d)", $1, $3 );
            }
         ;
</pre>
</pre>
   <div class="node">
<p><hr>
<a name="M4-Dependency"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Bison-Bridge">Bison Bridge</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Appendices">Appendices</a>

</div>

<h3 class="section">A.3 M4 Dependency</h3>

<p><a name="index-m4-499"></a>
The macro processor <code>m4</code><a rel="footnote" href="#fn-7" name="fnd-7"><sup>7</sup></a> must be installed wherever flex is installed. 
<code>flex</code> invokes `<samp><span class="samp">m4</span></samp>', found by searching the directories in the
<code>PATH</code> environment variable. Any code you place in section 1 or in the
actions will be sent through m4. Please follow these rules to protect your
code from unwanted <code>m4</code> processing.

     <ul>
<li>Do not use symbols that begin with, `<samp><span class="samp">m4_</span></samp>', such as, `<samp><span class="samp">m4_define</span></samp>',
or `<samp><span class="samp">m4_include</span></samp>', since those are reserved for <code>m4</code> macro names.

     <li>Do not use the strings `<samp><span class="samp">[[</span></samp>' or `<samp><span class="samp">]]</span></samp>' anywhere in your code. The
former is not valid in C, except within comments, but the latter is valid in
code such as <code>x[y[z]]</code>.

   </ul>

   <p><code>m4</code> is only required at the time you run <code>flex</code>. The generated
scanner is ordinary C or C++, and does <em>not</em> require <code>m4</code>.

<div class="node">
<p><hr>
<a name="Indices"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Appendices">Appendices</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="unnumbered">Indices</h2>

<ul class="menu">
<li><a accesskey="1" href="#Concept-Index">Concept Index</a>
<li><a accesskey="2" href="#Index-of-Functions-and-Macros">Index of Functions and Macros</a>
<li><a accesskey="3" href="#Index-of-Variables">Index of Variables</a>
<li><a accesskey="4" href="#Index-of-Data-Types">Index of Data Types</a>
<li><a accesskey="5" href="#Index-of-Hooks">Index of Hooks</a>
<li><a accesskey="6" href="#Index-of-Scanner-Options">Index of Scanner Options</a>
</ul>

<div class="node">
<p><hr>
<a name="Concept-Index"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index-of-Functions-and-Macros">Index of Functions and Macros</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Indices">Indices</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Concept Index</h3>

<ul class="index-cp" compact>
<li><a href="#index-g_t_0024-as-normal-character-in-patterns-75">$ as normal character in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-g_t_0025array_002c-advantages-of-94">%array, advantages of</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-g_t_0025array_002c-use-of-91">%array, use of</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-g_t_0025array_002c-with-C_002b_002b-95">%array, with C++</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-g_t_0025option-nowrap-155">%option nowrap</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-g_t_0025pointer_002c-and-unput_0028_0029-126">%pointer, and unput()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-g_t_0025pointer_002c-use-of-92">%pointer, use of</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-g_t_0025top-27">%top</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-g_t_0025_0040_007b-and-_0025_0040_007d_002c-in-Definitions-Section-24">%{ and %}, in Definitions Section</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-g_t_0025_0040_007b-and-_0025_0040_007d_002c-in-Rules-Section-100">%{ and %}, in Rules Section</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-g_t_003c_003cEOF_003e_003e_002c-use-of-217">&lt;&lt;EOF&gt;&gt;, use of</a>: <a href="#EOF">EOF</a></li>
<li><a href="#index-g_t_005b_005d-in-patterns-40">[] in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-g_t_005e-as-non_002dspecial-character-in-patterns-74">^ as non-special character in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-accessor-functions_002c-use-of-426">accessor functions, use of</a>: <a href="#Accessor-Methods">Accessor Methods</a></li>
<li><a href="#index-actions-96">actions</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-actions_002c-embedded-C-strings-102">actions, embedded C strings</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-actions_002c-redefining-YY_005fBREAK-227">actions, redefining YY_BREAK</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-actions_002c-use-of-_0040_007b-and-_0040_007d-101">actions, use of { and }</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-aliases_002c-how-to-define-18">aliases, how to define</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-arguments_002c-command_002dline-245">arguments, command-line</a>: <a href="#Scanner-Options">Scanner Options</a></li>
<li><a href="#index-array_002c-default-size-for-yytext-231">array, default size for yytext</a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-backing-up_002c-eliminating-380">backing up, eliminating</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-backing-up_002c-eliminating-by-adding-error-rules-382">backing up, eliminating by adding error rules</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-backing-up_002c-eliminating-with-catch_002dall-rule-383">backing up, eliminating with catch-all rule</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-backing-up_002c-example-of-eliminating-379">backing up, example of eliminating</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-BEGIN-111">BEGIN</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-BEGIN_002c-explanation-167">BEGIN, explanation</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-beginning-of-line_002c-in-patterns-55">beginning of line, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-bison_002c-bridging-with-flex-490">bison, bridging with flex</a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-bison_002c-parser-498">bison, parser</a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-bison_002c-scanner-to-be-called-from-bison-497">bison, scanner to be called from bison</a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-BOL_002c-checking-the-BOL-flag-225">BOL, checking the BOL flag</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-BOL_002c-in-patterns-56">BOL, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-BOL_002c-setting-it-223">BOL, setting it</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-braces-in-patterns-46">braces in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-bugs_002c-reporting-3">bugs, reporting</a>: <a href="#Reporting-Bugs">Reporting Bugs</a></li>
<li><a href="#index-C-code-in-flex-input-26">C code in flex input</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-C_002b_002b-391">C++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-C_002b_002b-and-_0025array-233">C++ and %array</a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-C_002b_002b-I_002fO_002c-customizing-486">C++ I/O, customizing</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-C_002b_002b-scanners_002c-including-multiple-scanners-412">C++ scanners, including multiple scanners</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-C_002b_002b-scanners_002c-use-of-408">C++ scanners, use of</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-c_002b_002b_002c-experimental-form-of-scanner-class-389">c++, experimental form of scanner class</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-C_002b_002b_002c-multiple-different-scanners-409">C++, multiple different scanners</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-C_002dstrings_002c-in-actions-103">C-strings, in actions</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-case_002dinsensitive_002c-effect-on-character-classes-70">case-insensitive, effect on character classes</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-character-classes-in-patterns-66">character classes in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-character-classes-in-patterns_002c-syntax-of-41">character classes in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-character-classes_002c-equivalence-of-68">character classes, equivalence of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-clearing-an-input-buffer-201">clearing an input buffer</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-command_002dline-options-243">command-line options</a>: <a href="#Scanner-Options">Scanner Options</a></li>
<li><a href="#index-comments-in-flex-input-23">comments in flex input</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-comments-in-the-input-35">comments in the input</a>: <a href="#Comments-in-the-Input">Comments in the Input</a></li>
<li><a href="#index-comments_002c-discarding-131">comments, discarding</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-comments_002c-example-of-scanning-C-comments-172">comments, example of scanning C comments</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-comments_002c-in-actions-104">comments, in actions</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-comments_002c-in-rules-section-33">comments, in rules section</a>: <a href="#Comments-in-the-Input">Comments in the Input</a></li>
<li><a href="#index-comments_002c-syntax-of-32">comments, syntax of</a>: <a href="#Comments-in-the-Input">Comments in the Input</a></li>
<li><a href="#index-comments_002c-valid-uses-of-34">comments, valid uses of</a>: <a href="#Comments-in-the-Input">Comments in the Input</a></li>
<li><a href="#index-compressing-whitespace-99">compressing whitespace</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-concatenation_002c-in-patterns-53">concatenation, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-copyright-of-flex-1">copyright of flex</a>: <a href="#Copyright">Copyright</a></li>
<li><a href="#index-counting-characters-and-lines-9">counting characters and lines</a>: <a href="#Simple-Examples">Simple Examples</a></li>
<li><a href="#index-customizing-I_002fO-in-C_002b_002b-scanners-485">customizing I/O in C++ scanners</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-default-rule-88">default rule</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-default-rule-7">default rule</a>: <a href="#Simple-Examples">Simple Examples</a></li>
<li><a href="#index-defining-pattern-aliases-21">defining pattern aliases</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-Definitions_002c-in-flex-input-17">Definitions, in flex input</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-deleting-lines-from-input-97">deleting lines from input</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-discarding-C-comments-132">discarding C comments</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-distributing-flex-2">distributing flex</a>: <a href="#Copyright">Copyright</a></li>
<li><a href="#index-ECHO-110">ECHO</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-ECHO_002c-and-yyout-156">ECHO, and yyout</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-embedding-C-code-in-flex-input-25">embedding C code in flex input</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-end-of-file_002c-in-patterns-61">end of file, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-end-of-line_002c-in-negated-character-classes-71">end of line, in negated character classes</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-end-of-line_002c-in-patterns-57">end of line, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-end_002dof_002dfile_002c-and-yyrestart_0028_0029-147">end-of-file, and yyrestart()</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-EOF-and-yyrestart_0028_0029-146">EOF and yyrestart()</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-EOF-in-patterns_002c-syntax-of-62">EOF in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-EOF_002c-example-using-multiple-input-buffers-206">EOF, example using multiple input buffers</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-EOF_002c-explanation-215">EOF, explanation</a>: <a href="#EOF">EOF</a></li>
<li><a href="#index-EOF_002c-pushing-back-129">EOF, pushing back</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-EOL_002c-in-negated-character-classes-72">EOL, in negated character classes</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-EOL_002c-in-patterns-58">EOL, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-error-messages_002c-end-of-buffer-missed-449">error messages, end of buffer missed</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-error-reporting_002c-diagnostic-messages-476">error reporting, diagnostic messages</a>: <a href="#Diagnostics">Diagnostics</a></li>
<li><a href="#index-error-reporting_002c-in-C_002b_002b-406">error reporting, in C++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-error-rules_002c-to-eliminate-backing-up-381">error rules, to eliminate backing up</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-escape-sequences-in-patterns_002c-syntax-of-50">escape sequences in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-exiting-with-yyterminate_0028_0029-139">exiting with yyterminate()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-experimental-form-of-c_002b_002b-scanner-class-390">experimental form of c++ scanner class</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-extended-scope-of-start-conditions-181">extended scope of start conditions</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-file-format-13">file format</a>: <a href="#Format">Format</a></li>
<li><a href="#index-file-format_002c-serialized-tables-475">file format, serialized tables</a>: <a href="#Tables-File-Format">Tables File Format</a></li>
<li><a href="#index-flushing-an-input-buffer-202">flushing an input buffer</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-flushing-the-internal-buffer-135">flushing the internal buffer</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-format-of-flex-input-11">format of flex input</a>: <a href="#Format">Format</a></li>
<li><a href="#index-format-of-input-file-15">format of input file</a>: <a href="#Format">Format</a></li>
<li><a href="#index-freeing-tables-470">freeing tables</a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-getting-current-start-state-with-YY_005fSTART-177">getting current start state with YY_START</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-halting-with-yyterminate_0028_0029-140">halting with yyterminate()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-handling-include-files-with-multiple-input-buffers-207">handling include files with multiple input buffers</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-header-files_002c-with-C_002b_002b-411">header files, with C++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-include-files_002c-with-C_002b_002b-410">include files, with C++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-input-file_002c-Definitions-section-16">input file, Definitions section</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-input-file_002c-Rules-Section-28">input file, Rules Section</a>: <a href="#Rules-Section">Rules Section</a></li>
<li><a href="#index-input-file_002c-user-code-Section-30">input file, user code Section</a>: <a href="#User-Code-Section">User Code Section</a></li>
<li><a href="#index-input_0028_0029-130">input()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-input_0028_0029_002c-and-C_002b_002b-133">input(), and C++</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-input_002c-format-of-12">input, format of</a>: <a href="#Format">Format</a></li>
<li><a href="#index-input_002c-matching-80">input, matching</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-keywords_002c-for-performance-386">keywords, for performance</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-lex-_0028traditional_0029-and-POSIX-448">lex (traditional) and POSIX</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-LexerInput_002c-overriding-482">LexerInput, overriding</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-LexerOutput_002c-overriding-481">LexerOutput, overriding</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-limitations-of-flex-479">limitations of flex</a>: <a href="#Limitations">Limitations</a></li>
<li><a href="#index-literal-text-in-patterns_002c-syntax-of-48">literal text in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-loading-tables-at-runtime-468">loading tables at runtime</a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-m4-499">m4</a>: <a href="#M4-Dependency">M4 Dependency</a></li>
<li><a href="#index-Makefile_002c-example-of-implicit-rules-488">Makefile, example of implicit rules</a>: <a href="#Makefiles-and-Flex">Makefiles and Flex</a></li>
<li><a href="#index-Makefile_002c-explicit-example-489">Makefile, explicit example</a>: <a href="#Makefiles-and-Flex">Makefiles and Flex</a></li>
<li><a href="#index-Makefile_002c-syntax-487">Makefile, syntax</a>: <a href="#Makefiles-and-Flex">Makefiles and Flex</a></li>
<li><a href="#index-matching-C_002dstyle-double_002dquoted-strings-179">matching C-style double-quoted strings</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-matching_002c-and-trailing-context-82">matching, and trailing context</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-matching_002c-length-of-83">matching, length of</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-matching_002c-multiple-matches-84">matching, multiple matches</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-member-functions_002c-C_002b_002b-392">member functions, C++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-memory-management-455">memory management</a>: <a href="#Memory-Management">Memory Management</a></li>
<li><a href="#index-memory_002c-allocating-input-buffers-189">memory, allocating input buffers</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-memory_002c-considerations-for-reentrant-scanners-421">memory, considerations for reentrant scanners</a>: <a href="#Init-and-Destroy-Functions">Init and Destroy Functions</a></li>
<li><a href="#index-memory_002c-deleting-input-buffers-193">memory, deleting input buffers</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-memory_002c-for-start-condition-stacks-187">memory, for start condition stacks</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-memory_002c-serialized-tables-471">memory, serialized tables</a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-memory_002c-serialized-tables-463">memory, serialized tables</a>: <a href="#Serialized-Tables">Serialized Tables</a></li>
<li><a href="#index-methods_002c-c_002b_002b-393">methods, c++</a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-minimal-scanner-89">minimal scanner</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-multiple-input-streams-188">multiple input streams</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-name-definitions_002c-not-POSIX-451">name definitions, not POSIX</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-negating-ranges-in-patterns-45">negating ranges in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-newline_002c-matching-in-patterns-59">newline, matching in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-non_002dPOSIX-features-of-flex-454">non-POSIX features of flex</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-nowrap_002c-_0025option-154">nowrap, %option</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-NULL-character-in-patterns_002c-syntax-of-51">NULL character in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-octal-characters-in-patterns-52">octal characters in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-options_002c-command_002dline-244">options, command-line</a>: <a href="#Scanner-Options">Scanner Options</a></li>
<li><a href="#index-overriding-LexerInput-484">overriding LexerInput</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-overriding-LexerOutput-483">overriding LexerOutput</a>: <a href="#How-do-I-use-my-own-I_002fO-classes-in-a-C_002b_002b-scanner_003f">How do I use my own I/O classes in a C++ scanner?</a></li>
<li><a href="#index-overriding-the-memory-routines-460">overriding the memory routines</a>: <a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a></li>
<li><a href="#index-Pascal_002dlike-language-10">Pascal-like language</a>: <a href="#Simple-Examples">Simple Examples</a></li>
<li><a href="#index-pattern-aliases_002c-defining-20">pattern aliases, defining</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-pattern-aliases_002c-expansion-of-47">pattern aliases, expansion of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-pattern-aliases_002c-how-to-define-19">pattern aliases, how to define</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-pattern-aliases_002c-use-of-22">pattern aliases, use of</a>: <a href="#Definitions-Section">Definitions Section</a></li>
<li><a href="#index-patterns-and-actions-on-different-lines-452">patterns and actions on different lines</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-patterns_002c-character-class-equivalence-69">patterns, character class equivalence</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-end-of-line-78">patterns, end of line</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-grouping-and-precedence-64">patterns, grouping and precedence</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-in-rules-section-36">patterns, in rules section</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-invalid-trailing-context-76">patterns, invalid trailing context</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-matching-79">patterns, matching</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-patterns_002c-precedence-of-operators-63">patterns, precedence of operators</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-repetitions-with-grouping-65">patterns, repetitions with grouping</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-special-characters-treated-as-non_002dspecial-77">patterns, special characters treated as non-special</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-syntax-38">patterns, syntax</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-patterns_002c-tuning-for-performance-377">patterns, tuning for performance</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-patterns_002c-valid-character-classes-67">patterns, valid character classes</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-performance-optimization_002c-matching-longer-tokens-385">performance optimization, matching longer tokens</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-performance-optimization_002c-recognizing-keywords-388">performance optimization, recognizing keywords</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-performance_002c-backing-up-378">performance, backing up</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-performance_002c-considerations-373">performance, considerations</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-performance_002c-using-keywords-387">performance, using keywords</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-popping-an-input-buffer-198">popping an input buffer</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-POSIX-and-lex-447">POSIX and lex</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-POSIX-comp_003bcompliance-453">POSIX comp;compliance</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-POSIX_002c-character-classes-in-patterns_002c-syntax-of-42">POSIX, character classes in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-preprocessor-macros_002c-for-use-in-actions-109">preprocessor macros, for use in actions</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-pushing-an-input-buffer-195">pushing an input buffer</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-pushing-back-characters-with-unput-123">pushing back characters with unput</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-pushing-back-characters-with-unput_0028_0029-125">pushing back characters with unput()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-pushing-back-characters-with-yyless-121">pushing back characters with yyless</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-pushing-back-EOF-128">pushing back EOF</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-ranges-in-patterns-43">ranges in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-ranges-in-patterns_002c-negating-44">ranges in patterns, negating</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-recognizing-C-comments-173">recognizing C comments</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-reentrant-scanners_002c-multiple-interleaved-scanners-414">reentrant scanners, multiple interleaved scanners</a>: <a href="#Reentrant-Uses">Reentrant Uses</a></li>
<li><a href="#index-reentrant-scanners_002c-recursive-invocation-415">reentrant scanners, recursive invocation</a>: <a href="#Reentrant-Uses">Reentrant Uses</a></li>
<li><a href="#index-reentrant_002c-accessing-flex-variables-420">reentrant, accessing flex variables</a>: <a href="#Global-Replacement">Global Replacement</a></li>
<li><a href="#index-reentrant_002c-accessor-functions-425">reentrant, accessor functions</a>: <a href="#Accessor-Methods">Accessor Methods</a></li>
<li><a href="#index-reentrant_002c-API-explanation-416">reentrant, API explanation</a>: <a href="#Reentrant-Overview">Reentrant Overview</a></li>
<li><a href="#index-reentrant_002c-calling-functions-418">reentrant, calling functions</a>: <a href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a></li>
<li><a href="#index-reentrant_002c-example-of-417">reentrant, example of</a>: <a href="#Reentrant-Example">Reentrant Example</a></li>
<li><a href="#index-reentrant_002c-explanation-413">reentrant, explanation</a>: <a href="#Reentrant">Reentrant</a></li>
<li><a href="#index-reentrant_002c-extra-data-427">reentrant, extra data</a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-reentrant_002c-initialization-422">reentrant, initialization</a>: <a href="#Init-and-Destroy-Functions">Init and Destroy Functions</a></li>
<li><a href="#index-regular-expressions_002c-in-patterns-37">regular expressions, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-REJECT-112">REJECT</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-REJECT_002c-calling-multiple-times-113">REJECT, calling multiple times</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-REJECT_002c-performance-costs-374">REJECT, performance costs</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-reporting-bugs-4">reporting bugs</a>: <a href="#Reporting-Bugs">Reporting Bugs</a></li>
<li><a href="#index-restarting-the-scanner-450">restarting the scanner</a>: <a href="#Lex-and-Posix">Lex and Posix</a></li>
<li><a href="#index-RETURN_002c-within-actions-149">RETURN, within actions</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-rules_002c-default-8">rules, default</a>: <a href="#Simple-Examples">Simple Examples</a></li>
<li><a href="#index-rules_002c-in-flex-input-29">rules, in flex input</a>: <a href="#Rules-Section">Rules Section</a></li>
<li><a href="#index-scanner_002c-definition-of-5">scanner, definition of</a>: <a href="#Introduction">Introduction</a></li>
<li><a href="#index-sections-of-flex-input-14">sections of flex input</a>: <a href="#Format">Format</a></li>
<li><a href="#index-serialization-462">serialization</a>: <a href="#Serialized-Tables">Serialized Tables</a></li>
<li><a href="#index-serialization-of-tables-465">serialization of tables</a>: <a href="#Creating-Serialized-Tables">Creating Serialized Tables</a></li>
<li><a href="#index-serialized-tables_002c-multiple-scanners-466">serialized tables, multiple scanners</a>: <a href="#Creating-Serialized-Tables">Creating Serialized Tables</a></li>
<li><a href="#index-stack_002c-input-buffer-pop-199">stack, input buffer pop</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-stack_002c-input-buffer-push-196">stack, input buffer push</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-stacks_002c-routines-for-manipulating-182">stacks, routines for manipulating</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-condition_002c-applying-to-multiple-patterns-180">start condition, applying to multiple patterns</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions-159">start conditions</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-behavior-of-default-rule-166">start conditions, behavior of default rule</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-exclusive-163">start conditions, exclusive</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-for-different-interpretations-of-same-input-171">start conditions, for different interpretations of same input</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-in-patterns-60">start conditions, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-start-conditions_002c-inclusive-162">start conditions, inclusive</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-inclusive-v_002es_002e-exclusive-161">start conditions, inclusive v.s. exclusive</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-integer-values-174">start conditions, integer values</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-multiple-160">start conditions, multiple</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-special-wildcard-condition-164">start conditions, special wildcard condition</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-use-of-a-stack-183">start conditions, use of a stack</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-use-of-wildcard-condition-_0028_003c_002a_003e_0029-165">start conditions, use of wildcard condition (&lt;*&gt;)</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-start-conditions_002c-using-BEGIN-170">start conditions, using BEGIN</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-stdin_002c-default-for-yyin-144">stdin, default for yyin</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-stdout_002c-as-default-for-yyout-158">stdout, as default for yyout</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-strings_002c-scanning-strings-instead-of-files-209">strings, scanning strings instead of files</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-tables_002c-creating-serialized-464">tables, creating serialized</a>: <a href="#Creating-Serialized-Tables">Creating Serialized Tables</a></li>
<li><a href="#index-tables_002c-file-format-474">tables, file format</a>: <a href="#Tables-File-Format">Tables File Format</a></li>
<li><a href="#index-tables_002c-freeing-469">tables, freeing</a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-tables_002c-loading-and-unloading-467">tables, loading and unloading</a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-terminating-with-yyterminate_0028_0029-138">terminating with yyterminate()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-token-85">token</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-trailing-context_002c-in-patterns-54">trailing context, in patterns</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-trailing-context_002c-limits-of-73">trailing context, limits of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-trailing-context_002c-matching-81">trailing context, matching</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-trailing-context_002c-performance-costs-376">trailing context, performance costs</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-trailing-context_002c-variable-length-384">trailing context, variable length</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-unput_0028_0029-122">unput()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-unput_0028_0029_002c-and-_0025pointer-127">unput(), and %pointer</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-unput_0028_0029_002c-pushing-back-characters-124">unput(), pushing back characters</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-user-code_002c-in-flex-input-31">user code, in flex input</a>: <a href="#User-Code-Section">User Code Section</a></li>
<li><a href="#index-username-expansion-6">username expansion</a>: <a href="#Simple-Examples">Simple Examples</a></li>
<li><a href="#index-using-integer-values-of-start-condition-names-175">using integer values of start condition names</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-verbatim-text-in-patterns_002c-syntax-of-49">verbatim text in patterns, syntax of</a>: <a href="#Patterns">Patterns</a></li>
<li><a href="#index-warning_002c-dangerous-trailing-context-480">warning, dangerous trailing context</a>: <a href="#Limitations">Limitations</a></li>
<li><a href="#index-warning_002c-rule-cannot-be-matched-478">warning, rule cannot be matched</a>: <a href="#Diagnostics">Diagnostics</a></li>
<li><a href="#index-warnings_002c-diagnostic-messages-477">warnings, diagnostic messages</a>: <a href="#Diagnostics">Diagnostics</a></li>
<li><a href="#index-whitespace_002c-compressing-98">whitespace, compressing</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yacc-interface-242">yacc interface</a>: <a href="#Yacc">Yacc</a></li>
<li><a href="#index-yacc_002c-interface-240">yacc, interface</a>: <a href="#Yacc">Yacc</a></li>
<li><a href="#index-YY_005fCURRENT_005fBUFFER_002c-and-multiple-buffers-Finally_002c-the-macro-205">YY_CURRENT_BUFFER, and multiple buffers Finally, the macro</a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-YY_005fEXTRA_005fTYPE_002c-defining-your-own-type-432">YY_EXTRA_TYPE, defining your own type</a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-YY_005fFLUSH_005fBUFFER_0028_0029-136">YY_FLUSH_BUFFER()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-YY_005fINPUT-150">YY_INPUT</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-YY_005fINPUT_002c-overriding-151">YY_INPUT, overriding</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-YY_005fSTART_002c-example-176">YY_START, example</a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-YY_005fUSER_005fACTION-to-track-each-time-a-rule-is-matched-219">YY_USER_ACTION to track each time a rule is matched</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-yyalloc_002c-overriding-456">yyalloc, overriding</a>: <a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a></li>
<li><a href="#index-yyfree_002c-overriding-458">yyfree, overriding</a>: <a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a></li>
<li><a href="#index-yyin-145">yyin</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yyinput_0028_0029-134">yyinput()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yyleng-87">yyleng</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-yyleng_002c-modification-of-107">yyleng, modification of</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yyless_0028_0029-119">yyless()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yyless_0028_0029_002c-pushing-back-characters-120">yyless(), pushing back characters</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yylex_0028_0029_002c-in-generated-scanner-141">yylex(), in generated scanner</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yylex_0028_0029_002c-overriding-142">yylex(), overriding</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yylex_002c-overriding-the-prototype-of-143">yylex, overriding the prototype of</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yylineno_002c-in-a-reentrant-scanner-446">yylineno, in a reentrant scanner</a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yylineno_002c-performance-costs-375">yylineno, performance costs</a>: <a href="#Performance">Performance</a></li>
<li><a href="#index-yymore_0028_0029-115">yymore()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yymore_0028_0029-to-append-token-to-previous-token-117">yymore() to append token to previous token</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yymore_0028_0029_002c-mega_002dkludge-116">yymore(), mega-kludge</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yymore_002c-and-yyleng-108">yymore, and yyleng</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yymore_002c-performance-penalty-of-118">yymore, performance penalty of</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yyout-157">yyout</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yyrealloc_002c-overriding-457">yyrealloc, overriding</a>: <a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a></li>
<li><a href="#index-yyrestart_0028_0029-148">yyrestart()</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yyterminate_0028_0029-137">yyterminate()</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yytext-86">yytext</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-yytext_002c-default-array-size-230">yytext, default array size</a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yytext_002c-memory-considerations-461">yytext, memory considerations</a>: <a href="#A-Note-About-yytext-And-Memory">A Note About yytext And Memory</a></li>
<li><a href="#index-yytext_002c-modification-of-106">yytext, modification of</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-yytext_002c-two-types-of-90">yytext, two types of</a>: <a href="#Matching">Matching</a></li>
<li><a href="#index-yywrap_0028_0029-152">yywrap()</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-yywrap_002c-default-for-153">yywrap, default for</a>: <a href="#Generated-Scanner">Generated Scanner</a></li>
<li><a href="#index-g_t_007c_002c-in-actions-105">|, in actions</a>: <a href="#Actions">Actions</a></li>
<li><a href="#index-g_t_007c_002c-use-of-114">|, use of</a>: <a href="#Actions">Actions</a></li>
   </ul><div class="node">
<p><hr>
<a name="Index-of-Functions-and-Macros"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index-of-Variables">Index of Variables</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Concept-Index">Concept Index</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Index of Functions and Macros</h3>

<p>This is an index of functions and preprocessor macros that look like functions. 
For macros that expand to variables or constants, see <a href="#Index-of-Variables">Index of Variables</a>.



<ul class="index-fn" compact>
<li><a href="#index-BEGIN-168"><code>BEGIN</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-debug-_0028C_002b_002b-only_0029-398"><code>debug (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-LexerError-_0028C_002b_002b-only_0029-407"><code>LexerError (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-LexerInput-_0028C_002b_002b-only_0029-404"><code>LexerInput (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-LexerOutput-_0028C_002b_002b-only_0029-405"><code>LexerOutput (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-lineno-_0028C_002b_002b-only_0029-396"><code>lineno (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-set_005fdebug-_0028C_002b_002b-only_0029-397"><code>set_debug (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-switch_005fstreams-_0028C_002b_002b-only_0029-403"><code>switch_streams (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-YY_005fAT_005fBOL-226"><code>YY_AT_BOL</code></a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-yy_005fcreate_005fbuffer-190"><code>yy_create_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fdelete_005fbuffer-194"><code>yy_delete_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fflush_005fbuffer-203"><code>yy_flush_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fnew_005fbuffer-204"><code>yy_new_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-YY_005fNEW_005fFILE--_0028now-obsolete_0029-216"><code>YY_NEW_FILE  (now obsolete)</code></a>: <a href="#EOF">EOF</a></li>
<li><a href="#index-yy_005fpop_005fstate-185"><code>yy_pop_state</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-yy_005fpush_005fstate-184"><code>yy_push_state</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-yy_005fscan_005fbuffer-213"><code>yy_scan_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fscan_005fbytes-211"><code>yy_scan_bytes</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fscan_005fstring-210"><code>yy_scan_string</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005fset_005fbol-224"><code>yy_set_bol</code></a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-yy_005fset_005finteractive-222"><code>yy_set_interactive</code></a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-yy_005fswitch_005fto_005fbuffer-192"><code>yy_switch_to_buffer</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yy_005ftop_005fstate-186"><code>yy_top_state</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-yyFlexLexer-constructor-_0028C_002b_002b-only_0029-401"><code>yyFlexLexer constructor (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-yyget_005fdebug-442"><code>yyget_debug</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005fextra-444"><code>yyget_extra</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005fextra-430"><code>yyget_extra</code></a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-yyget_005fin-436"><code>yyget_in</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005fleng-435"><code>yyget_leng</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005flineno-438"><code>yyget_lineno</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005fout-437"><code>yyget_out</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyget_005ftext-434"><code>yyget_text</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-YYLeng-_0028C_002b_002b-only_0029-395"><code>YYLeng (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-yylex-_0028C_002b_002b-version_0029-402"><code>yylex (C++ version)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-yylex-_0028reentrant-version_0029-495"><code>yylex (reentrant version)</code></a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-yylex_005fdestroy-424"><code>yylex_destroy</code></a>: <a href="#Init-and-Destroy-Functions">Init and Destroy Functions</a></li>
<li><a href="#index-yylex_005finit-423"><code>yylex_init</code></a>: <a href="#Init-and-Destroy-Functions">Init and Destroy Functions</a></li>
<li><a href="#index-yypop_005fbuffer_005fstate-200"><code>yypop_buffer_state</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yypush_005fbuffer_005fstate-197"><code>yypush_buffer_state</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yyrestart-236"><code>yyrestart</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yyset_005fdebug-443"><code>yyset_debug</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyset_005fextra-445"><code>yyset_extra</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyset_005fextra-431"><code>yyset_extra</code></a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-yyset_005fin-439"><code>yyset_in</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyset_005flineno-441"><code>yyset_lineno</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yyset_005fout-440"><code>yyset_out</code></a>: <a href="#Reentrant-Functions">Reentrant Functions</a></li>
<li><a href="#index-yytables_005fdestroy-473"><code>yytables_destroy</code></a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-yytables_005ffload-472"><code>yytables_fload</code></a>: <a href="#Loading-and-Unloading-Serialized-Tables">Loading and Unloading Serialized Tables</a></li>
<li><a href="#index-YYText-_0028C_002b_002b-only_0029-394"><code>YYText (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
   </ul><div class="node">
<p><hr>
<a name="Index-of-Variables"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index-of-Data-Types">Index of Data Types</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Index-of-Functions-and-Macros">Index of Functions and Macros</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Index of Variables</h3>

<p>This is an index of variables, constants, and preprocessor macros
that expand to variables or constants.



<ul class="index-vr" compact>
<li><a href="#index-INITIAL-169"><code>INITIAL</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-YY_005fCURRENT_005fBUFFER-238"><code>YY_CURRENT_BUFFER</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-YY_005fEND_005fOF_005fBUFFER_005fCHAR-212"><code>YY_END_OF_BUFFER_CHAR</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-YY_005fNUM_005fRULES-220"><code>YY_NUM_RULES</code></a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-YY_005fSTART-239"><code>YY_START</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-YY_005fSTART-178"><code>YY_START</code></a>: <a href="#Start-Conditions">Start Conditions</a></li>
<li><a href="#index-yyextra-428"><code>yyextra</code></a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-yyin-235"><code>yyin</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yyleng-234"><code>yyleng</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yylloc-492"><code>yylloc</code></a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-YYLMAX-232"><code>YYLMAX</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yylval-491"><code>yylval</code></a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-yylval_002c-with-yacc-241"><code>yylval, with yacc</code></a>: <a href="#Yacc">Yacc</a></li>
<li><a href="#index-yyout-237"><code>yyout</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yyscanner-_0028reentrant-only_0029-419"><code>yyscanner (reentrant only)</code></a>: <a href="#Extra-Reentrant-Argument">Extra Reentrant Argument</a></li>
<li><a href="#index-yytext-229"><code>yytext</code></a>: <a href="#User-Values">User Values</a></li>
<li><a href="#index-yytext-93"><code>yytext</code></a>: <a href="#Matching">Matching</a></li>
   </ul><div class="node">
<p><hr>
<a name="Index-of-Data-Types"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index-of-Hooks">Index of Hooks</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Index-of-Variables">Index of Variables</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Index of Data Types</h3>



<ul class="index-tp" compact>
<li><a href="#index-FlexLexer-_0028C_002b_002b-only_0029-400"><code>FlexLexer (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-YY_005fBUFFER_005fSTATE-191"><code>YY_BUFFER_STATE</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-YY_005fEXTRA_005fTYPE-_0028reentrant-only_0029-429"><code>YY_EXTRA_TYPE (reentrant only)</code></a>: <a href="#Extra-Data">Extra Data</a></li>
<li><a href="#index-yy_005fsize_005ft-214"><code>yy_size_t</code></a>: <a href="#Multiple-Input-Buffers">Multiple Input Buffers</a></li>
<li><a href="#index-yyFlexLexer-_0028C_002b_002b-only_0029-399"><code>yyFlexLexer (C++ only)</code></a>: <a href="#Cxx">Cxx</a></li>
<li><a href="#index-YYLTYPE-493"><code>YYLTYPE</code></a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
<li><a href="#index-yyscan_005ft-_0028reentrant-only_0029-433"><code>yyscan_t (reentrant only)</code></a>: <a href="#About-yyscan_005ft">About yyscan_t</a></li>
<li><a href="#index-YYSTYPE-494"><code>YYSTYPE</code></a>: <a href="#Bison-Bridge">Bison Bridge</a></li>
   </ul><div class="node">
<p><hr>
<a name="Index-of-Hooks"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index-of-Scanner-Options">Index of Scanner Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Index-of-Data-Types">Index of Data Types</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Index of Hooks</h3>

<p>This is an index of "hooks" that the user may define. These hooks typically  correspond
to specific locations in the generated scanner, and may be used to insert arbitrary code.



<ul class="index-hk" compact>
<li><a href="#index-YY_005fBREAK-228">YY_BREAK</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-YY_005fUSER_005fACTION-218">YY_USER_ACTION</a>: <a href="#Misc-Macros">Misc Macros</a></li>
<li><a href="#index-YY_005fUSER_005fINIT-221">YY_USER_INIT</a>: <a href="#Misc-Macros">Misc Macros</a></li>
   </ul><div class="node">
<p><hr>
<a name="Index-of-Scanner-Options"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Index-of-Hooks">Index of Hooks</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Indices">Indices</a>

</div>

<h3 class="unnumberedsec">Index of Scanner Options</h3>



<ul class="index-op" compact>
<li><a href="#index-g_t_002d_002b-307">-+</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002d7bit-272">&mdash;7bit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002d8bit-275">&mdash;8bit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dalign-325">&mdash;align</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dalways_002dinteractive-279">&mdash;always-interactive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002darray-310">&mdash;array</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dbackup-345">&mdash;backup</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dbatch-266">&mdash;batch</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dbison_002dbridge-297">&mdash;bison-bridge</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dbison_002dlocations-299">&mdash;bison-locations</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dc_002b_002b-308">&mdash;c++</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dcase_002dinsensitive-260">&mdash;case-insensitive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002ddebug-348">&mdash;debug</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002ddefault-277">&mdash;default</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002decs-328">&mdash;ecs</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dfast-342">&mdash;fast</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dfull-339">&mdash;full</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dheader_002dfile-246">&mdash;header-file</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dhelp-369">&mdash;help</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002d_002d_002dinteractive-269">&mdash;interactive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dlex_002dcompat-263">&mdash;lex-compat</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dmain-317">&mdash;main</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dmeta_002decs-333">&mdash;meta-ecs</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dnever_002dinteractive-281">&mdash;never-interactive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dnodefault-354">&mdash;nodefault</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dnoline-302">&mdash;noline</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dnounistd-319">&mdash;nounistd</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dnowarn-360">&mdash;nowarn</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002doption_002dansi_002ddefinitions-293">&mdash;option-ansi-definitions</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002doption_002dansi_002dprototypes-295">&mdash;option-ansi-prototypes</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002doutfile-249">&mdash;outfile</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dperf_002dreport-351">&mdash;perf-report</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dpointer-312">&mdash;pointer</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dposix-283">&mdash;posix</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dprefix-315">&mdash;prefix</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dread-336">&mdash;read</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002d_002d_002dreentrant-305">&mdash;reentrant</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dskel-254">&mdash;skel</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dstack-285">&mdash;stack</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dstdinit-287">&mdash;stdinit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dstdout-252">&mdash;stdout</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dtables_002dfile-255">&mdash;tables-file</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dtables_002dverify-257">&mdash;tables-verify</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002d_002d_002dtrace-357">&mdash;trace</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dverbose-363">&mdash;verbose</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dversion-372">&mdash;version</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002d_002d_002dwarn-365">&mdash;warn</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002d_002d_002dyyclass-321">&mdash;yyclass</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002d_002d_002dyylineno-289">&mdash;yylineno</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d_002d_002dyywrap-291">&mdash;yywrap</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d7-271">-7</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002d8-274">-8</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002db-344">-b</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dB-265">-B</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002dc-367">-c</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002dC-323">-C</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCa-324">-Ca</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCe-327">-Ce</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCF-331">-CF</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCf-330">-Cf</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCm-332">-Cm</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dCr-335">-Cr</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dd-347">-d</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dF-341">-F</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002df-338">-f</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-g_t_002dh-368">-h</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002dI-268">-I</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002di-259">-i</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002dL-301">-L</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002dl-262">-l</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t_002dn-370">-n</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002do-248">-o</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002dp-350">-p</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dP-314">-P</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002dR-304">-R</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-g_t_002ds-353">-s</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dT-356">-T</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dt-251">-t</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-g_t_002dV-371">-V</a>: <a href="#Miscellaneous-Options">Miscellaneous Options</a></li>
<li><a href="#index-g_t_002dv-362">-v</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dw-359">-w</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-g_t_002dX-282">-X</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t7bit-273">7bit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-g_t8bit-276">8bit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-align-326">align</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-always_002dinteractive-280">always-interactive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-ansi_002ddefinitions-294">ansi-definitions</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-ansi_002dprototypes-296">ansi-prototypes</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-array-311">array</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-backup-346">backup</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-batch-267">batch</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-bison_002dbridge-298">bison-bridge</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-bison_002dlocations-300">bison-locations</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-c_002b_002b-309">c++</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-case_002dinsensitive-261">case-insensitive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-debug-349">debug</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-default-278">default</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-ecs-329">ecs</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-fast-343">fast</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-full-340">full</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-header_002dfile-247">header-file</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-interactive-270">interactive</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-lex_002dcompat-264">lex-compat</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-main-318">main</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-meta_002decs-334">meta-ecs</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-nodefault-355">nodefault</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-noline-303">noline</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-nounistd-320">nounistd</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-nowarn-361">nowarn</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-noyyalloc-459">noyyalloc</a>: <a href="#Overriding-The-Default-Memory-Management">Overriding The Default Memory Management</a></li>
<li><a href="#index-outfile-250">outfile</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-perf_002dreport-352">perf-report</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-pointer-313">pointer</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-posix-284">posix</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-prefix-316">prefix</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-read-337">read</a>: <a href="#Options-for-Scanner-Speed-and-Size">Options for Scanner Speed and Size</a></li>
<li><a href="#index-reentrant-306">reentrant</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-stack-286">stack</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-stdinit-288">stdinit</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-stdout-253">stdout</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-tables_002dfile-256">tables-file</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-tables_002dverify-258">tables-verify</a>: <a href="#Options-for-Specifing-Filenames">Options for Specifing Filenames</a></li>
<li><a href="#index-trace-358">trace</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-verbose-364">verbose</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-warn-366">warn</a>: <a href="#Debugging-Options">Debugging Options</a></li>
<li><a href="#index-yyclass-322">yyclass</a>: <a href="#Code_002dLevel-And-API-Options">Code-Level And API Options</a></li>
<li><a href="#index-yylineno-290">yylineno</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
<li><a href="#index-yywrap-292">yywrap</a>: <a href="#Options-Affecting-Scanner-Behavior">Options Affecting Scanner Behavior</a></li>
   </ul><!-- A vim script to name the faq entries. delete this when faqs are no longer -->
<!-- named "unnamed-faq-XXX". -->
<!-- fu! Faq2 () range abort -->
<!-- let @r=input("Rename to: ") -->
<!-- exe "%s/" . @w . "/" . @r . "/g" -->
<!-- normal 'f -->
<!-- endf -->
<!-- nnoremap <F5>  1G/@node\s\+unnamed-faq-\d\+<cr>mfww"wy5ezt:call Faq2()<cr> -->
<div class="footnote">
<hr>
<a name="texinfo-footnotes-in-document"></a><h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> Actually,
<code>yyIN_HEADER</code> is defined before the `<samp><span class="samp">%top</span></samp>' block.</p>

   <p class="footnote"><small>[<a name="fn-2" href="#fnd-2">2</a>]</small> The
quantities given here are approximate, and may vary due to host architecture,
compiler configuration, or due to future enhancements to flex.</p>

   <p class="footnote"><small>[<a name="fn-3" href="#fnd-3">3</a>]</small> It
is not necessary to override all (or any) of the memory management routines. 
You may, for example, override <code>yyrealloc</code>, but not <code>yyfree</code> or
<code>yyalloc</code>.</p>

   <p class="footnote"><small>[<a name="fn-4" href="#fnd-4">4</a>]</small> GNU <samp><span class="command">make</span></samp> and GNU <samp><span class="command">automake</span></samp> are two such
programs that provide implicit rules for flex-generated scanners.</p>

   <p class="footnote"><small>[<a name="fn-5" href="#fnd-5">5</a>]</small> This example also applies to yacc parsers.</p>

   <p class="footnote"><small>[<a name="fn-6" href="#fnd-6">6</a>]</small> The features described here are
purely optional, and are by no means the only way to use flex with bison. 
We merely provide some glue to ease development of your parser-scanner pair.</p>

   <p class="footnote"><small>[<a name="fn-7" href="#fnd-7">7</a>]</small> The use of m4 is subject to change in
future revisions of flex.</p>

   <p><hr></div>

</body></html>

