3 ms·
Not the OP and I honestly have no idea what they mean, but the translation of a tree-walking interpreter for expressions to a stack-machine compiler is almost t
by sirwhinesalot 2mo ago
Not the OP and I honestly have no idea what they mean, but the translation of a tree-walking interpreter for expressions to a stack-machine compiler is almost trivial. For example, if you have (in pseudo-code):
class Add : Node {
Node left;
Node right;
int interpret() {
int l = left.interpret();
int r = right.interpret();
return l + r;
}
}
You can turn it into:
class Add : Node {
Node left;
Node right;
void compile(bc: ByteCode) {
left.compile(bc);
right.compile(bc);
bc.push(OP_ADD);
}
}
The inputs to OP_ADD are implicit, I guess that is what "remove" means?