etc/services - sync with NetBSD-8
[minix.git] / external / bsd / flex / dist / examples / manual / eof_rules.lex
blobb575f2c04cbba6bb577c8031c3d2e74f9264becf
1 /*
2  * eof_rules.lex : An example of using multiple buffers
3  *                 EOF rules, and start states
4  */
6 %{
7                               
8 #define MAX_NEST 10                   
10 YY_BUFFER_STATE include_stack[MAX_NEST];
11 int             include_count = -1;
16 %x INCLUDE
20 ^"#include"[ \t]*\"  BEGIN(INCLUDE);
21 <INCLUDE>\"          BEGIN(INITIAL); 
22 <INCLUDE>[^\"]+ {      /* get the include file name */
23           if ( include_count >= MAX_NEST){
24              fprintf( stderr, "Too many include files" );
25              exit( 1 );
26           }
28           include_stack[++include_count] = YY_CURRENT_BUFFER;
30           yyin = fopen( yytext, "r" );
31           if ( ! yyin ){
32              fprintf( stderr, "Unable to open \"%s\"\n",yytext);
33              exit( 1 );
34           }
36           yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
38           BEGIN(INITIAL);
39         }
40 <INCLUDE><<EOF>> 
41         {
42             fprintf( stderr, "EOF in include" );
43             yyterminate();
44         }
45 <<EOF>> {
46           if ( include_count <= 0 ){
47             yyterminate();
48           } else {
49             yy_delete_buffer(include_stack[include_count--] );
50             yy_switch_to_buffer(include_stack[include_count] );
51             BEGIN(INCLUDE);
52           }
53         }
54 [a-z]+               ECHO;
55 .|\n                 ECHO;