Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 641583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:04:43+00:00 2026-05-13T21:04:43+00:00

I am using Boost Spirit parser, and as the parser is parsing, semantic actions

  • 0

I am using Boost Spirit parser, and as the parser is parsing, semantic actions are reflected to an instance of the class ParserActions.

Here is the code for the parser (the relevant part)

struct urdf_grammar : public grammar<urdf_grammar> {

template <typename ScannerT>
        struct definition {

    definition(urdf_grammar const& self) {


        prog = (alpha_p >> *alnum_p)[&(self.actions.do_prog)];

    }

    rule<ScannerT> prog;

    rule<ScannerT> const&
            start() const {
        return prog;
    }
};

const ParserActions & actions;

explicit urdf_grammar(const ParserActions & actions = ParserActions()) : actions(actions) {
}  
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:04:43+00:00Added an answer on May 13, 2026 at 9:04 pm

    In order to call a member function of an object you need to provide two things:

    1. the address of the member function, as said before you can get that by writing &my_class::my_member
    2. the pointer (or a reference) to the instance of the object you want the member function be invoked for

    Spirit semantic actions expect you to provide a function or function object exposing a certain interface. In your case the expected interface is:

    void func(Iterator first, Iterator Last);
    

    where Iterator is the iterator type used to call the parse function (accessible through typename ScannerT::iterator_t). What you need to do is to create a function object exposing the mentioned interface while still calling your member function. While this can be done manually, doing so is tedious at best. The simplest way to create a function object is by using Boost.Bind:

    prog = (alpha_p >> *alnum_p)
           [
               boost::bind(&ParserActions::do_prog, self.action)
           ];
    

    which will create the required function object for you, binding and wrapping your member function.

    All this assumes your member function does not take any arguments. If you need to pass the pair of iterators the semantic action will be invoked with to your function the construct needs to be written as:

    prog = (alpha_p >> *alnum_p)
           [
               boost::bind(&ParserActions::do_prog, self.action, _1, _2)
           ];
    

    instructing the function object to forward its first and second parameter to the bound function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I have just started using Boost 1.36. These libraries would be very useful in
I'm using boost for several C++ projects. I recently made a upgrade (1.33.1 to
I'm using boost's shared pointers, and enable_shared_from_this to enable returning a shared pointer to
What might be the best way to start programming using boost lambda libraries.
So I am doing a lot of high performance network programming using Boost::Asio (or
When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of
How much do using smart pointers, particularly boost::shared_ptr cost more compared to bare pointers
Since I have started using this site, I keep hearing about the Boost library.
I'm trying setup a subset of boost and get it properly compiled using bjam,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.