Well, so far i'm using GNU Bison with Lex & Yacc files to build a parser in C++, which is called by my program through the yyparse()
function. Therefore the g++ compilation of my program produce an .a file that allow the user to insert some code to be parsed.
However I would like to use the generated-file to compile a whole project directory hierarchy (i.e a bunch of files). So, is Bison able to generate the result-compiler in a independent archive to allow me that? Maybe there is a simple way to parse multiple files? Or Should I manage this behavior through C++ algorithms by myself?
Thanks for the knowledge sharing!
Bisons/yacc generated parsers do not directly read input. The parsers use the tokens extracted from the input stream by yylex()
, leaving it entirely up to yylex()
to read the data or otherwise access the input.
By default, the yylex()
generated by (f)lex reads input from the input stream pointed at by the global variable yyin
. yylex()
does not fopen
a file or otherwise give yyin
a value (except for initialising it to stdin
).
To pass multiple files through your parser:
Set yyin
appropriately:
yyin = fopen(filepath, "r");
Call yyparse()
.
Close yyin
.
Repeat as necessary.