Input handling is done by flex, so you need to read the flex manual for details.
The section on multiple input buffers (linked above) has example code for handling "include"-like constructs. In fact, there are two sample implementations; one using the built-in buffer stack (recommended) and the other with an explicit buffer stack.
Really, it is not very complicated. To start reading a new file, all you need to do is this:
yyin = fopen(filename, "r");
if ( !yyin ) /* Handle the error */
yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
You pop the buffer state in your EOF rule:
<<EOF>> { yypop_buffer_state();
/* Make sure we stop if the EOF is the original input. */
if (!YY_CURRENT_BUFFER) { yyterminate(); }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…