help-bison
[Top][All Lists]
Advanced

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

Re: Help !!!


From: Akim Demaille
Subject: Re: Help !!!
Date: 22 Jul 2002 11:53:06 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

>>>>> "Hans" == Hans Aberg <address@hidden> writes:

Hans> At 19:10 +0200 2002/07/20, Bruno Ripa wrote:
>> My problem's this:
>> 
>> I'm using flex++ and bison to create a parser of instructions, and
>> i need it to be written in C++ because i'll use many object in my
>> proggie.
>> 
>> AND I'M NOT ABLE TO GET C++ CODE USING BISON...
>> 
>> How can i resolve my problem ???

Hans> You might try the -S bison.c++ option on some of the latest
Hans> betas found at ftp://alpha.gnu.org/gnu/bison/ named
Hans> bison-1.49xxx something. -- Akim will perhaps elaborate.

I won't :)  Read the following, and note that it is lalr1.cc, not
bison.c++.

-*-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 ();
        }



reply via email to

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