babis87 0 Newbie Poster

Hello,

I'm writing a lexixal analyzer on FLEX, and i want to open an #include file. Calling fopen(yytext,"r"); as shown in flex manual http://flex.sourceforge.net/manual/Multiple-Input-Buffers.html#Multiple-Input-Buffers does not open the file, although that the string in yytext has the value "<filename>". Instead, when i use fopen("<filename>","r") the file opens normaly and the analyzer works. But i want yytext being used for <filename>. What's wrong?

The code of my analyzer (rule section only):

{inclusion} {printf("token INCLUSION: %s\n",yytext);  BEGIN(incl);}

<incl>[ \t]* {}/* */
<incl>[^ \t\n]+  {   printf("Try now to open include file:%s\n",yytext);

        if(stack_pointer>=MAX_INCLUDE_DEPTH){
            printf("Many includes\n");
            exit(0);
        }

        include_stack[stack_pointer++]=YY_CURRENT_BUFFER;

        yyin = fopen( yytext, "r" );

        if(!yyin){
            printf("Error opening file:%s\n",yytext);
            exit(0);
        }
        yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
        BEGIN(INITIAL);
    }

<<EOF>>       {
        if(--stack_pointer<0){
            yyterminate();
        }
        else{

            yy_delete_buffer(YY_CURRENT_BUFFER);
            yy_switch_to_buffer(include_stack[stack_pointer]);

        }
    }

    { printf("Found Unknown Token: %s\n", yytext); }