I am trying to parse two files with win flex and bison, but I am encountering a problem where lex is not in the state I am expecting. In the lex file:
include[ \t]+\" { BEGIN(include_state); }
<include_state>([^\\\"\n]|\\.)+ {
yyin = fopen(yytext, "r");
if (!yyin) {
printf("Error opening include file: %s\n", yytext);
return 1;
}
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner),
yyscanner);
BEGIN(INITIAL);
}
<include_state>\"[ \t]*";" { BEGIN(INITIAL); }
<<EOF>> {
yypop_buffer_state(yyscanner);
if (!YY_CURRENT_BUFFER)
yyterminate();
}
The first file being parsed includes the second file as follows:
include "hello.txt";
What happens when parsing is that the second file ("hello.txt") is parsed OK with no problems, but there is a problem when returning to the first file. The quote and semi colon at the end of the line are read, but lex is in the INITIAL state. So lex is not matching on the rule that I'm expecting it to match on. I know this for sure because if I add the following rule (it matches):
<INITIAL>\"[ \t]*";" { printf("Right matching, wrong state.\n"); return 1; }
Why does it not return to the include_state and how can I fix this?
"before doing the include. - rici