i was working on an interpreter for a language with a friend, and we started with a decision I'm guessing wasn't that wise: we made all the elements for execution first (practically a tree made of different classes); but now looking at boost examples i get a lot confused about how to merge the two. I know what to start from (the grammar), i know what to reach (instantiated classes owning each other), i don't know how to reach it.
We started with expressions without variables, hence we looked at spirit calculator examples; but i don't understand when to instantiate elements.
Example of expression items:
namespace exp
{
class op
{
private:
public:
virtual double exec(function_scope &fs);
};
class operand : public op
{
private:
double value;
public:
operand(double value);
double exec(function_scope &fs);
};
class op_bin : public op
{
private:
public:
op * ll;
op* rr;
op_bin(op* ll, op* rr);
~op_bin();
};
namespace bin
{
class sum : public op_bin
{
public:
sum(op* ll, op* rr);
double exec(function_scope &fs);
};
}
}
Ignore the exec function, it's used at runtime.
For example the code 5 + (2 + 1) should result in a final equivalent of:
new exp::bin::sum(new exp::operand(5), new exp::bin::sum(new exp::operand(2), new exp::operand(1))
Once i understand how to do that I've practically done.