-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operator awareness of parent function? #3
Comments
No, there is no such thing. |
I'll think about how to do it. |
okay cool, thanks 👍 I now wonder how I might go about implementing. |
How to get the function name: ir.addFunction("lettuce", [&ir](const vector<string>& args) ->string {
return !args.empty() ? args[0] : "";
});
ir.addOperator( // a selection
"->", [&ir](string &leftOpd, string &rightOpd) -> string {
auto entities = ir.allEntities();
auto curEntity = ir.currentEntity();
int index = curEntity.beginIndex - 1;
while ((index >= 0) && (entities[index].type != Interpreter::EntityType::FUNCTION))
--index;
string parentFunctionName = "";
if (index >= 0)
parentFunctionName = entities[index].name;
if (isNumber(leftOpd) && isNumber(rightOpd)) {
int a = stoi(leftOpd);
int b = stoi(rightOpd);
for (int cnt = a; cnt <= b; cnt++) {
printf("select %s %d \n\r", parentFunctionName.c_str(), cnt);
}
}
return parentFunctionName;
}, 0);
string scenar = "lettuce(1->24);";
string res = ir.cmd(scenar); // lettuce
|
Hi Tyill! Thanks so much, this works, but breaks the multiple instances #1 when using a vector. This had me stumped, but I think it's because Solved: I should be using a deque instead of a vector, and emplace_back() instead to create the objects in place, instead of using push_back() and moving an object there. facepalm. |
Is there a mechanism or suggestion how that that the operator can know it's parent function?
eg:
lettuce(1->24);
would output...
The text was updated successfully, but these errors were encountered: