Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2006-09-13 18:55:54


Jens Theisen wrote:
> Joel de Guzman <joel_at_[hidden]> writes:
>
>> One-phase construction definitely!
>
> I'd like to ask you a question about your parser framework that is
> related to this. I probably get most of the following wrong, so please
> be patient.

Well, the proper mailing list is:
https://lists.sourceforge.net/lists/listinfo/spirit-general

Anyway...

> With spirit, there appear to be two approaches:
>
> 1) semantic actions, which store away the parsed expression in some way
>
> and
>
> 2) closures, which implicitly "return" their first member (member1).
>
> I don't like 1 for most purposes, because it's too imperative for my
> taste. I need to keep track of what my actions did and, if something
> fails to parse at a point and backtracking occurs, need to manually
> revert the changes. This seems error prone to me.
>
> 2 looks better, but, and this is the connection to the OP, it appears
> that the returned value, as all closure members, must be default
> constructible. In particular, I risk returning such default
> constructed values when I failed to assign to them.
>
> It's very likely that I missed something, as I didn't seriously tried
> using spirit. Can you shed some light on this?

Yeah. You did miss something. The closure members can be initialized.
See "Initializing closure variables" section in http://tinyurl.com/85hbq

"Sometimes, we need to initialize our closure variables upon entering a
non-terminal (rule, subrule or grammar). Closure enabled non-terminals,
by default, default-construct variables upon entering the parse member
function. If this is not desirable, we can pass constructor arguments
to the non-terminal."...

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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