help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parser base class (lalr1)


From: Hans Aberg
Subject: Re: Parser base class (lalr1)
Date: Wed, 28 Sep 2005 22:47:06 +0200


On 28 Sep 2005, at 21:02, Jan Nabbefeld wrote:

Hello,
On 28.09.2005, Hans Aberg wrote:

On 28 Sep 2005, at 14:37, Jan Nabbefeld wrote:
I use a C++ polymorphic hierarchy, with a reference count at the
base, in order to avoid unnecessary copying.
This approach has also the advantage of making use of C++ cleanup
The code above then becomes:

cd_list: /* empty */ {$$=0;}
    | cd_list cd { $$ = new NRec(token, _CD_LIST, $1, $2, _CD); }
;
[snip]


That's a nice solution but unfortunately no option for me. As I
mentioned, there is no way for me to change the semantic actions. My
mission is to rebuild an existing C implemented scanner/parser in C++.
The semantic actions have to be untouched (as far as possible).

It seems me that you want to put the functions in a separate namespace, but having to write out the namespace name in the actions. Have you tried using the C++ "namespace" and "using" features.

Also, if you put the tree* in the parser class, then the parser isn't pure. Do you want that? If you put it in the parser function argument, instead, then you get a pure function (or at least, when the C++ parser has been rewritten as to move all else stuff as well there).

In addition, moving to the C++ class hierarchy approach is not so difficult. I use a template class ref<T> that replaces your "tree" class with ref<tree>. You might want to try it, once you have gotten your current approach working.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]