1*3c3a7b76Schristos /*
2*3c3a7b76Schristos  * eof_rules.lex : An example of using multiple buffers
3*3c3a7b76Schristos  *                 EOF rules, and start states
4*3c3a7b76Schristos  */
5*3c3a7b76Schristos 
6*3c3a7b76Schristos %{
7*3c3a7b76Schristos 
8*3c3a7b76Schristos #define MAX_NEST 10
9*3c3a7b76Schristos 
10*3c3a7b76Schristos YY_BUFFER_STATE include_stack[MAX_NEST];
11*3c3a7b76Schristos int             include_count = -1;
12*3c3a7b76Schristos 
13*3c3a7b76Schristos %}
14*3c3a7b76Schristos 
15*3c3a7b76Schristos 
16*3c3a7b76Schristos %x INCLUDE
17*3c3a7b76Schristos 
18*3c3a7b76Schristos %%
19*3c3a7b76Schristos 
20*3c3a7b76Schristos ^"#include"[ \t]*\"  BEGIN(INCLUDE);
21*3c3a7b76Schristos <INCLUDE>\"          BEGIN(INITIAL);
22*3c3a7b76Schristos <INCLUDE>[^\"]+ {      /* get the include file name */
23*3c3a7b76Schristos           if ( include_count >= MAX_NEST){
24*3c3a7b76Schristos              fprintf( stderr, "Too many include files" );
25*3c3a7b76Schristos              exit( 1 );
26*3c3a7b76Schristos           }
27*3c3a7b76Schristos 
28*3c3a7b76Schristos           include_stack[++include_count] = YY_CURRENT_BUFFER;
29*3c3a7b76Schristos 
30*3c3a7b76Schristos           yyin = fopen( yytext, "r" );
31*3c3a7b76Schristos           if ( ! yyin ){
32*3c3a7b76Schristos              fprintf( stderr, "Unable to open \"%s\"\n",yytext);
33*3c3a7b76Schristos              exit( 1 );
34*3c3a7b76Schristos           }
35*3c3a7b76Schristos 
36*3c3a7b76Schristos           yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
37*3c3a7b76Schristos 
38*3c3a7b76Schristos           BEGIN(INITIAL);
39*3c3a7b76Schristos         }
40*3c3a7b76Schristos <INCLUDE><<EOF>>
41*3c3a7b76Schristos         {
42*3c3a7b76Schristos             fprintf( stderr, "EOF in include" );
43*3c3a7b76Schristos             yyterminate();
44*3c3a7b76Schristos         }
45*3c3a7b76Schristos <<EOF>> {
46*3c3a7b76Schristos           if ( include_count <= 0 ){
47*3c3a7b76Schristos             yyterminate();
48*3c3a7b76Schristos           } else {
49*3c3a7b76Schristos             yy_delete_buffer(include_stack[include_count--] );
50*3c3a7b76Schristos             yy_switch_to_buffer(include_stack[include_count] );
51*3c3a7b76Schristos             BEGIN(INCLUDE);
52*3c3a7b76Schristos           }
53*3c3a7b76Schristos         }
54*3c3a7b76Schristos [a-z]+               ECHO;
55*3c3a7b76Schristos .|\n                 ECHO;
56*3c3a7b76Schristos 
57*3c3a7b76Schristos 
58*3c3a7b76Schristos 
59*3c3a7b76Schristos 
60*3c3a7b76Schristos 
61*3c3a7b76Schristos 
62*3c3a7b76Schristos 
63*3c3a7b76Schristos 
64*3c3a7b76Schristos 
65*3c3a7b76Schristos 
66