From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-02-26 12:51:34
On Tuesday 26 February 2002 12:28 pm, you wrote:
> Doees anyone know of a C++-friendly version of yacc, or, better yet, a
> version of yacc that produces a generic algorithm (e.g., take as input a
> pair of InputIterators)? Yacc / bison as it stands is quite unfriendly to
> C++, as you cannot put C++ objects on the evaluation stack, which means
> that you can't always get objects properly destroyed. You can
> partially get around this by putting only pointers on the evaluation
> stack, and having the code that accompanies a production rule be
> responsible for managing the objects on which it operates, but this scheme
> breaks down when it comes to error processing -- values get popped off of
> the evaluation stack without giving you any opportunity to process them.
I looked around somewhat recently for the same thing, and was unfortunately
unable to find any generic parser other than Spirit (which I couldn't use
only because of the fear of adding yet another library). I ended up using
Bison with lots of pointers, grumbling all the way...
> The Spirit parser is not what I am looking for, as it is limited to
> recursive-descent parsing, and is hence unsuitable for many applications
> (say, parsing a C++ program).
As Dave Abrahams already mentioned, several of the better C++ parsers uses
recursive descent parsing. This is generally because recursive descent
parsers handle context sensitivity and arbitrary lookahead _much_ better than
any Yacc-based solution. Check out gcc/cp/parse.y in the GCC source code to
see all of the ugliness a Yacc-based parser adds; especially look at the
comments. Also note that there is an experimental recursive descent parsing
for GCC that will replace the Yacc-based parser in the future.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk