I am trying to get this to work but it isn't going right:
bool get_truth() {
return curdata.truth;
}
then_expr =3D ( (eps_p(get_truth) >> syntax ) | no_actions_d[syntax]);
The docs say that I can use eps_p in this way, but something is obviously w=
rong:
http://spirit.sourceforge.net/distrib/spirit_1_8_2/libs/spirit/doc/epsilon.=
html
------------
Semantic Predicate
Semantic predicates allow you to attach a function anywhere in the
grammar. In this role, the epsilon takes a 0-ary (nullary)
function/functor. The run-time function/functor is typically a test
that is called upon to resolve ambiguity in the grammar. A parse
failure will be reported when the function/functor result evaluates to
false. Otherwise an empty match will be reported. The general form is:
eps_p(f) >> rest;
The nullary function f is called to do a semantic test (say, checking
if a symbol is in the symbol table). If test returns true, rest will
be evaluated. Otherwise, the production will return early with a
no-match without ever touching rest.
---------------
What can I do?

>> I think that I need "new_" in the style of "construct_". BLL seems
>> to have something like this, but Pheonix doesn't. Any thoughts
>> anyone?
>
>It has. It was just undocumented as of Phoenix 1.0.
Thanks Joel. That's another piece of the jigsaw done.
So now I have a base class, and some derived classes, and rules have a
single closure variable which is a base class pointer. Then individual
rules use new_<>:
constant = int_p [constant.val=new_<Constant>(arg1)] ;
variable = identifier [variable.val=new_<Variable>(arg1)] ;
But sometimes I have multiple arguments:
addition = expression >> '+' >> expression ;
I'm still wondering if there is a way to do this:
addition = expression >> '+' >> expression
[addition.val=new_<Addition>(arg1,arg3)] ;
i.e. getting the result of each of the two expression sub-rules at the
end of the rule. But no-one has suggested a concise way of doing that,
so I'll ignore the idea for now.
So instead I need to do something like this:
addition = expression [addition.val=new_<Addition>(),
addition.val->left=arg1]
>> '+'
>> expression [addition.val->right=arg1]
These assignments are similar to the ones I was doing before, except
using "->" rather than ".". The documentation gives the impression that
I should be able to use bind with exactly the same syntax, e.g.
[bind(&Addition::right)(addition.val)=arg1]
but that doesn't seem to work. Should it?
Of course I'm also faced with the possibility that the rule will
backtrack after the new_, causing a memory leak. A smart pointer
(shared_ptr?) would fix this; can anyone suggest how to adapt this code
to use one?
As an aside, I have some rules with lots of alternatives like this:
r = r1 | r2 | r3 | r4 | r5 ;
All of these rules have the same type, and I'd like r to return whatever
the matched subrule returns. I'd like to be able to write it like this:
r = ( r1 | r2 | r3 | r4 | r5 ) [r.val=arg1] ;
but that doesn't seem to work, presumably because operator| is returning
an iterator pair decribing the matched input, rather than whatever its
matched subrule matched. So I have to write:
r = r1 [r.val=arg1] | r2 [r.val=arg1] | r3 [r.val=arg1] .....
which is a bit tedious. Any ideas?
Thanks for all the help. I'm about two thirds of the way through the
problem now (and about 99% of the way through my RAM while compiling...)
Cheers,
--Phil.

> -----Original Message-----
> From: spirit-general-admin@...=20
> [mailto:spirit-general-admin@...] On Behalf=20
> Of Jeff Flinn
> Sent: Wednesday 10 August 2005 14:03
> To: spirit-general@...
> Subject: [Spirit-general] Re: Building tree of custom structs=20
> (structs as closure vars?)
>=20
>=20
> I've become fond of functor parsers when faced with these tasks:
>=20
> struct name_parser_function
> {
> // snip...
> };
> Then
>=20
> name_rule_name =3D name_p[assign(self.mName)];
>=20
I like the look of this. How does name_p relate to name_parser_function?
Is there some kind of convenience typedef required?
Thanks
Barney
The information transmitted is intended only for the person(s) or entity to=
which it is addressed and may contain confidential and/or privileged mater=
ial. Any review, retransmission, dissemination or other use of, or taking o=
f any action in reliance upon, this information by persons or entities othe=
r than the intended recipient is prohibited. If you received this in error,=
please contact the sender and delete the material from any computer. =20
This communication is for informational purposes only. It is not intended a=
s an offer or solicitation for the purchase or sale of any financial instru=
ment or as an official confirmation of any transaction. All market prices, =
data and other information are not warranted as to completeness or accuracy=
and are subject to change without notice. Any comments or statements made =
herein do not necessarily reflect those of Brevan Howard Asset Management L=
LP, its members and affiliates.
=20
Brevan Howard Asset Management LLP is authorised and regulated by the Finan=
cial Services Authority. Registered Office: 42 Portman Road, Reading, Berks=
hire RG3O 1EA. Phone number 020 7022 6100.=20

Dear All,
Thanks for the replies. For a while I was using something like Bill
Barry's suggestion, i.e. replicating all of the fields of my struct as
closure vars, assigning to them, and then constructing a struct at the
end of the rule. By making this struct the first closure var it becomes
the "closure return value" and can be accessed using arg1 in the parent
rule. But it's really ugly to replicate everything.
So I eventually worked out how to use structs as closure vars. The
problem is that you can't do
struct foo { int a, b, c, d ... };
struct foo_closure: boost::spirit::closure<foo_closure, foo> {
member1 val;
};
rule<scanner_t, foo_closure::context_t> r
= .... [ r.val.a=(...) ]
because r.val.a isn't a Pheonix lazy variable, or whatever you want to
call it. But you can explicitly bind it to convert it into one:
[ bind(&foo::a)(r.val) = (...) ]
This is a bit cryptic but it does work.
My next task is to work out if I can use (smart?) pointers instead of
complete structs for these values. I need this so that I can have a
rule whose return type is a base class and sub-rules whose return types
are subclasses, e.g.
struct Expr {};
struct Constant: Expr {
int c;
};
struct Variable: Expr {
string name;
};
rule_t constant = int_p [ constant.val=new_<Constant(arg1)> ]
rule_t variable = identifier [ variable.val=new_<Variable(arg1)> ]
rule_t expr
= constant
| variable
| ....
[ expr.val = arg1.val ] ;
I think that I need "new_" in the style of "construct_". BLL seems to
have something like this, but Pheonix doesn't. Any thoughts anyone?
--Phil.

Hi Bj=F6rn,
> Maybe I'm just dim, but what can I do with the new class that I =
couldn't
> do
> with old one?
The Point class "essentially" does the same. And that's why the user =
doesn't
see any difference, and is not needed to do anything except =
recompilation as
you change your design. So, the user comes up with no bonus feature.
You, as the programmer of the Point class, get a bonus guarantee, =
however.
The guarantee saves your member functions from mistakenly doing anything
which is not defined within its view! That's all! And, in case you do =
not
guess what this can mean, I'd tell you that that's saving bewildering =
nights
of debugging nights, several nightmares...
Hope that explanation suffices,
Wishes,
--Hossein

A few minutes ago I wrote:
> I'm still rather lost as to how to build a nested structure containing
> my parsed data.
I've just found mention of the "closure return value", which may be the
missing part of the jigsaw that will make it all make sense. If I'm on
the right lines, hopefully I'll be able to post a solution to my own
problem tomorrow.
--Phil.

On 8/8/05, Yusaku Sugai <sugai@...> wrote:
> Hi,
Hi Yusaku,
>=20
> Maybe you can turn off some part of /O2 option by #pragma optimize
> to make it work?
>=20
When I have more time I'll take a closer look at this. It is almost
surely an optimization bug, since it works exactly as expected without
/O2(or with /O1) and only gives error to me when compiled with the
entire project. I'll probably use some #pragma's or #error to nobody
else here have to debug it all again. Optimization problems are surely
very annoying. I thought someone else could have this problem already,
and the bug be somehow documented. The /O2 optimization did a good job
with the others parts of the project, hopefully the optimizations that
will be needed to be turned off dont make much difference.
>=20
> Regards,
Thanks for the attention,
Felipe.
>=20
> Yusaku Sugai
>=20
--=20
Felipe Magno de Almeida
Developer from synergy and Computer Science student from State
University of Campinas(UNICAMP).
Unicamp: http://www.ic.unicamp.br
Synergy: http://www.synergy.com.br
"There is no dark side of the moon really. Matter of fact it's all dark."

Dear All,
Thanks for the replies to my earlier questions. I'm making progress but
I'm still rather lost as to how to build a nested structure containing
my parsed data. I'll try to give an example of what I'm hoping to achieve.
Say I have a text file containing a list of names:
Alice Andrews
Brian Bloggs
Charles Cobb
David Dodds
and I have a struct to store a name:
struct name {
string firstname;
string surname;
name(string f, stirng s): firstname(f), surname(s) {}
};
I'd like to end up with a list<name>, or perhaps a list<name*>, or
something like that.
Having done this sort of thing with Yacc in the past my intuition is
that I need something vaguely like this:
firstname = *alpha_p ;
surname = *alpha_p ;
name = firstname >> ' ' >> surname [return new name(_1,_3)] ;
name_list = list_p ( name[l.push_back], '\n' ) ;
This obviously isn't literally correct. I can see various ways of doing
it, some of which are rather hacky. I'd like to find the cleanest
solution. For example, I have just been looking at using
access_node_d[] and node_val_data_factory<T>. That seems to be similar
to Yacc's semantic value mechanism. Presumably I could do something
like this:
- Declare a base class for node values, node_base_t.
- Use node_val_data_factory<node_base_t>.
- Make rules that have a semantic value assign pointers to subclasses of
node_base_t to their node value, e.g. make struct name a subclass of
node_base_t and
name = access_node_d [ firstname >> ' ' >> surname ]
[ assign_to_node(new name(_1,_3)) ]
..or something like that. How do I access the values returned by
'firstname' and 'surname', where I have written _1 and _2?
Please help!
--Phil.

Peter Simons wrote:
> Brad Retzlaff writes:
>
> > I just realized the example I referenced from Peter Simons
> > works correctly now in Spirit 1.6.2 and not as he has
> > documented.
>
> Hi everybody, long time no see. ;-)
Hi Peter! Long time no see.
> Reading Brad's e-mail surprised me a bit: I didn't even know the
> rfcdate example was still being distributed. I checked the CVS
> repository a while ago, and it seems that it has been removed
> from there, but apparently the web site still has it. Since the
> tutorial clearly doesn't match the current Spirit version
> anymore, I was wondering what to do with that old piece of code
> of mine. Is it worth updating the code (and finishing the
> tutorial)?
Yes.
Any interest in that?
Definitely!
Or shall we just drop it
> entirely to avoid users being mislead by obsolete information?
The application repository is very much alive and kicking.
I'd be sad if we drop one of the applications there because
of obsolete information. I'd say, please update it and keep
it moving.
Regards,
--
Joel de Guzman
http://www.boost-consulting.comhttp://spirit.sf.net