I'm trying to write a parser using flex++ and bison. I need the parser to be able to read from a file and write a new file in output.
I have an yyFlexLexer instantiated as follows:
yyFlexLexer lexer;
and I use it:
int main(int argc, char* argv[])
{
std::istream* in_file = new std::ifstream(argv[1])
std::ostream* out_file = new std::ofstream(argv[2])
lexer.switch_streams(in_file, out_file);
yyparse();
return 0;
}
If I run:
./executable foo bar
the parser correctly read the file foo (I can see it making some printing in bison rules) but at the end I found only an empty file called "bar" without anything in it.
I have also tried to do this:
int main(int argc, char* argv[])
{
std::istream* in_file = new std::ifstream(argv[1])
std::ostream* out_file = new std::ofstream(argv[2])
lexer.switch_streams(in_file, out_file);
while(lexer.yylex())
;
return 0;
}
but it does the same thing.