Boost logo

Boost Users :

Subject: Re: [Boost-users] [proto][spirit] parsing into proto expressions
From: llonesmiz (jorge.navalon_at_[hidden])
Date: 2016-05-11 01:08:07

Igor R. wrote
> Hi,
> Long story short: I would like to create proto expressions at run-time
> using spirit parsers. Would it be possible?
> More in details: I'd like to parse disassembler output, creating proto
> expression template for instruction and its operands.
> Lets assume we define proto expressions that would allow to express
> the following asm:
> "lea eax, [ebx + 2 * ecx]"
> like this:
> BOOST_PROTO_AUTO(lea_instr, eax = &*(ebx + 2 * ecx)); // registers and
> immediates are proto terminals
> Of course, we can't write such an expression in C++ code, because the
> actual operands get known after the asm string is parsed.
> So we can express any "lea" in the code (at compile-time) in a more
> general form, using placeholders: _1 = &_2;
> Then, when the parser matches "lea", we need to parse and create at
> run-time the actual operands, i.e. to substitute _1 with eax and _2
> with *(ebx + 2 * ecx).
> I'd appreciate any pointer!
> Thanks.

I'm not an expert in either Spirit or Proto but my understanding is that
Spirit requires specific (fixed) types as the result of its parsers and a
proto expression generated as you intend wouldn't fit in that model(unless
you use some kind of type erasure, but I don't know if that would be even

I think what you need to use is Boost.Metaparse (in Boost 1.61). Abel
Sinkovics has a great tutorial (sadly not completely up-to-date with the
most recent version, but there are very little differences) at (the real interesting part is
in "lab 6", the rest is a great introduction to metaprogramming and mpl
conventions). I think this
could also be useful. It's not as well explained but it's up-to-date and
tries to compare Metaparse with a Spirit approach.

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at