This is not a duplicate of this question because the solution was not to use a parser!
I have a Bison parser I can run by doing ./parser < file_to_parse
. I want to call the Bison parser from within my C++ program. What I don't want is to do system(./parser < file_to_parse)
because that would assume the parser is pre-compiled and then my whole program would not be platform independant.
If I have a function:
void foo(file_name) {
// call parser on file_name
}
then how can this be done? Any ideas? I think it's the case of calling yyparse or something but I'm not getting anywhere with it!
Thank you :).
Are you using a version that is adapted to C++?
I use the one by Alain Coetmeur.
At the moment, I only have code handy for employing flex++, but it should show you how this goes.
When you run flex++ it will output a header file and an implementation file for a new class to do the parsing. Add these to your project, then write:
// Construct new instance of parser
::lex * plex = new lex();
// tell parser what file to parse
plex->yyin = _wfopen(L"C:/Documents and Settings/All Users/Application Data/QuietWake/eCrew/new_rules_to_be_parsed.txt",L"r");
// run the parser
int lex_return = plex->yylex();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With