| 1 |
/* |
| 2 |
* eof_rules.lex : An example of using multiple buffers |
| 3 |
* EOF rules, and start states |
| 4 |
*/ |
| 5 |
|
| 6 |
%{ |
| 7 |
|
| 8 |
#define MAX_NEST 10 |
| 9 |
|
| 10 |
YY_BUFFER_STATE include_stack[MAX_NEST]; |
| 11 |
int include_count = -1; |
| 12 |
|
| 13 |
%} |
| 14 |
|
| 15 |
|
| 16 |
%x INCLUDE |
| 17 |
|
| 18 |
%% |
| 19 |
|
| 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 |
} |
| 27 |
|
| 28 |
include_stack[++include_count] = YY_CURRENT_BUFFER; |
| 29 |
|
| 30 |
yyin = fopen( yytext, "r" ); |
| 31 |
if ( ! yyin ){ |
| 32 |
fprintf( stderr, "Unable to open \"%s\"\n",yytext); |
| 33 |
exit( 1 ); |
| 34 |
} |
| 35 |
|
| 36 |
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); |
| 37 |
|
| 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; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|