I get a "debug assertion failed... Expression stream != NULL" error when running a flex / bison program. Here is the relevant code, at the top of the lex file:
%x include_state
%{
#define MAX_INCLUDE_DEPTH 10
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
int include_stack_ptr = 0;
%}
... and later in the lex file:
include[ \t]*\" { BEGIN(include_state); }
<include_state>[a-zA-Z0-9 ]+ {
if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
{
fprintf(stderr, "Includes nested too deeply");
exit(1);
}
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
yyin = fopen(yytext, "r" );
if (!yyin)
sprintf(err_str, "Error opening include file: %s", yytext);
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner),
yyscanner);
}
<include_state>\"; { BEGIN(INITIAL); }
... the text it is trying to pass is:
include "hello.txt";
I am trying to add "include" functionality to my program. I am using win flex and win bison. (A side issue: how do I split lines of code in the lex file?)
lex
file content please? – Iharob Al Asimi