[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bison 1.35: end of file?
From: |
Akim Demaille |
Subject: |
Re: bison 1.35: end of file? |
Date: |
01 Jul 2002 14:01:06 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter) |
>>>>> "Bernd" == Bernd Prager <address@hidden> writes:
Bernd> Any changes on that status? Was anybody else successful in
Bernd> using "bison -S bison.c++ " with gcc 3.1? I'd really
Bernd> appreciate some help. -- Bernd
I use it with success. But recently bison.c++ (now lalr1.cc) has
changed, so I need to adjust my samples. Here is a first draft of the
maybe future documentation:
-*-outline-*-
* C++
** Extending parser classes
One can define a base class from which the generated parser class will
inherit. This is done using the `root' muscle:
%define root "Base"
The provided base class has to fulfil two requirements. It must define
a type called `Param', and use this type as the only parameter of its
constructor. Here is a basic example:
class Base
{
public:
struct Param
{
Param (const std::string& fn) :
filename (fn)
{
}
std::string filename;
};
Base (const Param& p) :
ast_ (0),
filename_ (p.filename)
{
}
inline Ast* ast_get () { return ast_; }
inline const Ast* ast_get () const { return ast_; }
protected:
Ast* ast_;
std::string filename_;
};
The added members and methods are then available in semantic actions:
program : exp { ast_ = $1; }
;
There are no particular constraints on the `Param' type. It can be
a simple type as well:
class Base
{
public:
typedef std::string Param;
Base (const Param& p) :
ast_ (0),
filename_ (p)
{
}
// ...
};
However, this type has to be defined, since it is used to provide a
sound signature to the constructor of the generated parser class:
// ...
{
yy::Parser parser = yy::Parser (0, // Debugging
"foo"); // User-defined parameter
parser.parse ();
return parser.ast_get ();
}