Interpreter in C ++: the problem of storing the function table

In my interpreter, I have built-in functions available in a language such as print exit inputetc. Obviously, these functions can be obtained from within the language. Then the interpreter searches for the corresponding function with the correct name in the vector and calls it through the pointer stored with its name.

So I gather all these functions in these files is io.cpp, string.cpp, arithmetic.cpp. But I have to add each function to the list of functions in the interpreter so that it can be found.

So, in these function files there are such things as:

void print( arg )
{
     cout << arg.ToString;
}

I would add this print function to the list of interpreter functions with:

interpreter.AddFunc( "print", print );
  • But where should I call interpreter.AddFunc?

, ++.

  • ?
+3
3

(io, string ..) , , :

void IOModule::Register(Interpreter &interpreter) {
    interpreter.AddFunc( "print", print );
    //...
}

, .

.

: , , , , .

+2

map . , , main().

, (.dll .so ), / .

+1

? , (, ), init.

, "include" . , include.

+1

Source: https://habr.com/ru/post/1739781/


All Articles