You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then add the operator to the operator's precedence map and to the operations map:
structStartup_Op {
Startup_Op() {
OppMap_t& opp = calculator::Default().opPrecedence;
// Note the operator name here uses characters,// but does not need to be the same name you want to use on the code:
opp.add("my op", 2);
// Add the operation function to the default opMap:
opMap_t& opMap = calculator::Default().opMap;
// Here you should use the same name used on the OppMap:
opMap.add({NUM, "my op", NUM}, &my_sum);
}
} Startup_Op;
Note: Operator names starting with capital letters "L" and "R" are reserved
for internal usage of the engine. So avoid using these as
starting letters for the names of your operators and prefere lowercased names.
Registering the Reserved Word
After that you must define a parser for your reserved word operator, and add it to the parser map:
// This parser is very simple and only requires one line:voidmy_op_parser(constchar* expr, constchar** rest, rpnBuilder* data) {
// Use here the same name as before
data->handle_op("my op");
}
structStartup_Parser {
Startup_Parser() {
parserMap_t& parser = calculator::Default().parserMap;
// Here you must use the actual word you expect to use// on the code instead an Ad Hoc name as before:
parser.add("and", &my_op_parser);
}
} Startup_Parser;
And that should do the trick. Now when the code is being parsed it will read the word "and" and then add the operator "my op" to the expression, then when executing the Operation Matching Loop it will access the definitions we wrote on Startup_Op.
Note: To keep it simpler you might want to join both startup functions into a single one.
There is no need for 2 of them.