Boost logo

Boost Users :

Subject: [Boost-users] [proto][spirit] parsing into proto expressions
From: Igor R (boost.lists_at_[hidden])
Date: 2016-05-10 15:32:07


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.


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