Re: trying out the c++ parser skeleton / b4_post_prologue
Anthony Heading <ajrh <at> ajrh.net>
2006-07-12 13:22:41 GMT
Akim Demaille wrote:
> Could you please detail why you'd like to do that? For several
> reasons, including recursion support, I think the proper way to extend
> the parser is to couple it with a parsing driver.
Yes, I did read the example in the docs, and thought it an odd design.
Perhaps you also could expand on those reasons - here are my thoughts as
an end-user.
First, it is very natural in C++ for a programmer to link in some
types of application-specific code by providing an implementation of
an abstract interface. See e.g. Stroustrup C++PL ch. 24, MFC, Qt, etc.
I was surprised to find, for example, that in this bison-c++, the
interface to the lexer is not created as an abstract virtual function
for the end-programmer to implement, but instead remains a C macro.
Obviously this isn't wrong per se, but there has been a decade of
aggregate common thinking (agree with it or not) about how ideally
C++ code should differ from C, and the bison-c++ design differs
enough in many areas from this convergence of practice that I found
it unintuitive and hard to use. Therefore I chose to ignore the
documentation example, and instead read the skeleton source code.
Your parsing-driver suggestion leads the semantic action code to be
filled with references to a driver handle.
| TOKEN_IDENTIFIER { $$ = driver.variables[*$1]; }
This is the main reason for my attempt to subclass. To me, this is
unacceptable - the programmer should totally own the scope in
which the semantic actions are being executed. Yacc has always
allowed this. But in C++, there is the huge benefit that this
(Continue reading)