Boost logo

Boost Users :

Subject: [Boost-users] [boost-users][[proto] : Seeking advice on a DSL
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-03-17 21:12:36


Hello,

I want to create a DSL where users are allowed to create "free"
variables and then use them are parameters and local variables in
their mini-program. For example, I want to have something like

int_ a,b,c;
Program(&a,b) [c = b*2, a = c]

The parameter with the '&' prefix represents output, the ones without
represent input. So, Program(&a, b)[...] should behave as a function
object with prototype void foo(int&, const int), and I should be able
to do the following :

int ra;
BOOST_AUTO(pr, Program(&a,b) [c = b*2, a = c]);
pr(ra, 4);

I am seeking some advice on implementing the "evaluator" for this
language. In particular, where do I store the values corresponding to
these free variables? To draw parallels with Boost.Phoenix, in
phoenix, arg1, arg2.. etc are uniquely typed, and the evaluator just
creates a fusion::vector<...> with the values passed in, and argN
evaluation just returns fusion::at_c<N>(env.args()). In my case, I
could create a unique ID for each free variable, and create a std::map
from ID to value, and use that as the environment. Evaluator of the
free variables can then look up that map to find values. But I
consider this too heavy weight. In contrast, the fusion::vector<...>
would incur very little overhead during run time. I will be grateful
for any suggestions on other ways to implement the evaluator.

Thanks in advance,
Manjunath


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