1. Is there a way of making ast a data member of my class and not depend on the global variable ?
You can use the %parse-param
to add one (or more) parameters to the yyparse
prototype. In particular, you could pass a pointer to yyparse
and fill it in with the parse result. You probably also want to make yyparse
"pure" (reentrant). See the sections "The Parser Function" and "A Pure Parser" in the bison manual (also possibly available as info bison
)
Alternatively, you can use the ability of bison
to generate C++ code, which will effectively do all of that.
2. Also, is it possible to hide Bison/Flex code from the user ?
You can insert namespace {
blocks into the generated code, but it requires a bit of manual (or scriptable) post-generation manipulation. (Concatenating the bison and flex output into a single translation unit, for example.) Not at all difficult, though.