flex++ と bison を使用してパーサーを作成しようとしています。ファイルから読み取り、出力に新しいファイルを書き込むことができるパーサーが必要です。
次のようにインスタンス化された yyFlexLexer があります。
yyFlexLexer lexer;
そして私はそれを使用します:
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;
}
私が実行した場合:
./executable foo bar
パーサーはファイル foo を正しく読み取りました (bison ルールで何らかの印刷を行っていることがわかります) が、最後には何も入っていない「bar」という空のファイルしか見つかりませんでした。
私もこれをやろうとしました:
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;
}
しかし、それは同じことをします。