html2 Flex - a scanner generator: End-of-file rules Whole document tree
    

Whole document tree

html2 Flex - a scanner generator: End-of-file rules
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13. End-of-file rules

The special rule "<<EOF>>" indicates actions which are to be taken when an end-of-file is encountered and yywrap() returns non-zero (i.e., indicates no further files to process). The action must finish by doing one of four things:

  • assigning yyin to a new input file (in previous versions of flex, after doing the assignment you had to call the special action YY_NEW_FILE; this is no longer necessary);

  • executing a return statement;

  • executing the special `yyterminate()' action;

  • or, switching to a new buffer using `yy_switch_to_buffer()' as shown in the example above.

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

 
<INITIAL><<EOF>>

These rules are useful for catching things like unclosed comments. An example:

 
%x quote
%%

...other rules for dealing with quotes...

<quote><<EOF>>   {
         error( "unterminated quote" );
         yyterminate();
         }
<<EOF>>  {
         if ( *++filelist )
             yyin = fopen( *filelist, "r" );
         else
            yyterminate();
         }


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root on March, 17 2002 using texi2html