[Flex-help] Why it does not work ?
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Frank Y. <pro...@gm...> - 2007-05-17 07:20:41
|
Hi , all ! Let us study the question. I have three char buffers A , B and C ; buffer A: "data1" buffer B: "data2" buffer C: "data3" rule: data1data2data3data4 printf( "\n Experiment is successful!" ); In order to find the string "data1data2data3" , I have written the following code, however, it does not find the string "data1data2data3". I found yy_state is always one when yy_switch_to_buffer is run. What should I do ? Please tell me. Source Code: %{ #define FILE_NUM 4 YY_BUFFER_STATE Channel[4] ; static unsigned int BufferIndex ; int yywrap(void); %} %% data1data2data3data4 printf( "\nExperiment is successful!" ); <<EOF>> { BufferIndex++; if ( BufferIndex<FILE_NUM ) { yy_switch_to_buffer( Channel[BufferIndex] ); } else { yyterminate(); } } %% int main( int argc, char* argv[] ) { unsigned int nCounter; FILE* pFile[4]; // checking parameter if( argc <FILE_NUM+1 ) { printf( "usage: Buffer filename1 filename2....." ); exit(0); } // open the file for( nCounter=0; nCounter<FILE_NUM; ++nCounter ) { pFile[nCounter] = fopen( argv[nCounter+1], "r" ); if ( !pFile[nCounter] ) { printf( "\ncan not open the data%d", nCounter+1 ); exit(1); } // Create Buffer Channel[nCounter] = yy_create_buffer(pFile[nCounter], YY_BUF_SIZE); } yy_switch_to_buffer( Channel[BufferIndex] ); yylex( ); system( "pause" ) ; for ( nCounter=0; nCounter<FILE_NUM; ++nCounter ) { fclose( pFile[nCounter] ); } return 0; } int yywrap(void) { return 1; } |