Writing your own language is quite a task if you actually intend on doing something that is relatively complete. Thousands of lines of code is definitely possible. I have been involved in various forms of this over my 30 years of professional and hobby life - from writing a simple parser for commands in a debugger or similar to a fairly well working "mini-basic" interpreter and a small Lisp interpreter. I've also produced a lot of "pseud-language", where a text-file is used as input for a program, but it's not a full-fledged programming language - there are only a limited set of variables.
Another thing that I've done quite a bit is "table-driven programming", where the actual "code" is built into the program in the form of tables.
In all these, there are various forms of "I have some input/data that I want to translate into an action in relation to some other object".
The basic mechanism, as you describe, is to store the name and some other data (such as the type) in a data-structure of some sort. std::map<std::string, cVariable>
would be one way to relatively easily retrieve the data from a name (string) to the variable of that name.
You can clearly do the same thing for functions. You would of course also have some way to pass arguments into the function. Exactly how you solve that is something every language has had to solve, and usually it ends up being some sort of "stack".
You can certainly have a map<std::string, function>
that translates from a name to a function - the function definition may contain some information about what number and types of arguments the function takes.
For "builtin" functions, you can also have a type of argc, argv[]
type approach, where arguments are passed as cVariable
[where one option is constant
or expression
], to allow for myPrint(myVar[0] + 100)
, which of course isn't a true variable, but the result of the content of a variable added to a constant.
If you haven't written something that acts like a calculator with variables, that would probably be a good starting point.
Many "script" type languages have a variables that are "polymorphic" - that is, the value can be used as a number or as a string without actually asking for the variable to be converted.