In my interpreter I have built-in functions available in the language like print
exit
input
, etc.
These functions can obviously be accessed from inside the language. The interpreter then looks for the corresponding function with the right name in a vector and calls it via a pointer stored with its name.
So I gather all these functions in files like io.cpp
, string.cpp
, arithmetic.cpp
. But I have to add every function to the function list in the interpreter in order for it to be found.
So in these function files I have things like:
void print( arg )
{
cout << arg.ToString;
}
I'd add this print function to the interpreter function list with:
interpreter.AddFunc( "print", print );
- But where should I call the
interpreter.AddFunc
?
I can't just put it there below the print function as it has to be in a function according to the C++ syntax.
- Where and how should all the functions be added to the list?