Boost logo

Boost Users :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2004-11-17 05:34:21


I'm just trying to make a simple parser like uint_p. From the source
I've dug through it doesn't look like those use grammar classes though
it's very possible I'm wrong.

If the object passed through definition() is const, how would state be updated?

On Tue, 16 Nov 2004 21:59:24 -0500, Jeffrey Holle
<jeff.holle_at_[hidden]> wrote:
> Not sure where you are stuck at, given your description, but I'll give
> it a try.
>
> In order to hook semantic actions into your grammar:
> 1. You should create a grammar object that houses your grammar.
> 2. You should use functor action operators.
>
> The first provides a way to expose application objects to the grammar in
> a maintainable way.
>
> For instance:
>
> struct My_grammar : public grammar<My_grammar>
> {
> My_grammar(State& state) : state_(state) {}
> template <typename ScannerT>
> struct definition
> {
> definition(My_grammar const& self)
> {
> // define grammar here
> rule<ScannerT> outerRule;
> rule<ScannerT> const&
> start() const { return outerRule; }
> };
> State& state_;
> }
>
> In the object example, the action objects can get mutable access to the
> State object to record what needs recording.
>
> The second "should" involves the actual action operators. These can be
> either functions or functors. I sugguest using only the later in that
> they can be used like:
>
> struct captureSA
> {
> captureSA(State *pState) : m_pState(pState) {}
> void operator()(iterator_t first, const iterator_t& last) const;
> State *m_pState;
> };
>
> This functor can be attached to a rule like (note: within the body of
> definition above):
>
> outerRule[captureSA(self.state)]
>
> There is one caviot to this. The signature of the operator() method
> changes to:
> void operator()(const char& ch)
> when the rule matches single characters.
> Sometimes its necessary to define both methods in an action functor.
>
> Hope that helps.
>
> Cory Nelson wrote:
> > Okay, I'm trying to learn Spirit and I've got the grammar down. I've
> > tried looking at the documentation but still can not find out how to
> > make a custom parser (that will let me use the [action] operator).
> > Could someone give an example of a pascal string parser (one byte for
> > length, string follows) to get me started?
> >
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Cory Nelson
http://www.int64.org

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net