andrewt@watsnew.waterloo.edu (Andrew Thomas) (10/19/89)
I have recently tried to write a parser using bison and flex. It worked fine on a single input file, but I wanted to read mulitple files and parse them in the same way. The program always aborted from the parser on the second file saying that EOF had been reached. I tried setting yyin to a new file pointer before calling yyparse but it did not help. Eventually I changed the skeleton file to remove the 'static' definitions from the function 'yyrestart'. Now from the routine which calls yyparse, I set yyin to stdin (so yyrestart won't try to close some other file), then call yyrestart with a pointer to the file I want to read. This has the desired effect, but now the line number counting I have put in the .l file is off by the number of lines in the previous file. Is there a correct way to read multiple input files with one parser run? -- Andrew Thomas andrewt@watsnew.waterloo.edu Systems Design Eng. University of Waterloo "If a million people do a stupid thing, it's still a stupid thing." - Opus
vern@utgard.cs.cornell.edu (Vern Paxson) (10/20/89)
In article <ANDREWT.89Oct18222337@watsnew.waterloo.edu> andrewt@watsnew.waterloo.edu (Andrew Thomas) writes: > I have recently tried to write a parser using bison and flex. It > worked fine on a single input file, but I wanted to read mulitple > files and parse them in the same way.... > Eventually I changed the skeleton file to remove the > 'static' definitions from the function 'yyrestart'.... > This has the desired effect, but now the > line number counting I have put in the .l file is off by the number of > lines in the previous file. Is there a correct way to read multiple > input files with one parser run? Yes. What you want to do is add a rule like: <<EOF>> { if there's another input file { fclose( yyin ); yyin = fopen( file, "r" ); reset line number counter YY_NEW_FILE; } else return; } This is a new feature so it may be somewhat buggy. If you have problems with it, send me mail. Vern Vern Paxson vern@cs.cornell.edu Computer Science Dept. decvax!cornell!vern Cornell University vern@LBL (bitnet)