Flex++ Bisonc++ parser

bison, c++, flex-lexer, parsing

Solution

There are flex/bison, flex++/bison++ and flexc++/bisonc++. I think it's best to pick one of these three pairs, instead of mixing/matching flex++ and bisonc++. Here are the user guides for Flexc++ and Bisonc++.

From the Flexc++ website:

Flexc++, contrary to flex and flex++, generates code that is explicitly intended for use by C++ programs. The well-known flex(1) program generates C source-code and flex++(1) merely offers a C++-like shell around the yylex function generated by flex(1) and hardly supports present-day ideas about C++ software development. Contrary to this, flexc++ creates a C++ class offering a predefined member function lex matching input against regular expressions and possibly executing C++ code once regular expressions were matched. The code generated by flexc++ is pure C++, allowing its users to apply all of the features offered by that language.

From the Bisonc++ website:

Bisonc++ is a general-purpose parser generator that converts a grammar description for an LALR(1) context-free grammar into a C++ class to parse that grammar. Once you are proficient with bisonc++, you may use it to develop a wide range of language parsers, from those used in simple desk calculators to complex programming languages. Bisonc++ is highly comparable to the program bison++, written by Alain Coetmeur: all properly-written bison++ grammars ought to be convertible to bisonc++ grammars after very little or no change. Anyone familiar with bison++ or its precursor, bison, should be able to use bisonc++ with little trouble. You need to be fluent in using the C++ programming in order to use bisonc++ or to understand this manual.

So flexc++/bisonc++ are more than just wrappers around the old flex/bison utilities. They generate complete C++ classes to be used for re-entrant scanning / parsing.

Problem

I'm trying to use `flex` and `bison` in my project to generate a parser code for a file structure. Main programming language is C++ and project is on an OO design mainly running in parallel. I heard that `flex` and `bison` generated parsers are C codes and they're not reenterant. Googling, I found `flex++` and `bisonc++`. Unfortunately there is no simple tutorial to get started. Most examples are based on `bison/flex`. Some people somehow integrated `bison/flex` parsers in their C++ code. They supposed to be "tricky"... Documentation of `flex++` and `bisonc++` doesn't help me and. Tutorials and examples, they all get input from stdin and print some messages on stdout. I need these features in my parser: - Parser should be a C++ class, defined in normal manner (a header and a cpp file) - Parser receives data from either an `std::string` or `std::stringstream` or a null-terminated `char*`. I feel so confused. Should I use `flex++/bisonc++` or `flex/bison`? And how to do that, satisfying above conditions?

Original source