Making a Variable while Running?

I was thinking of making a mini programming language within a program. Knowing this, I would have to be able to make variables while running the program. Anyway to make variables while compiled?
It has to be simulated. Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <map>
#include <string>

namespace
{
    std::map< std::string, int > ints ;
    std::map< std::string, std::string > strings ;

    void create_variable( std::string name, int value )
    { ints[name] = value ; }

    void create_variable( std::string name, std::string value )
    { strings[name] = value ; }
}

int main()
{
    create_variable( "count", 5 ) ;
    create_variable( "total", 0 ) ;
    create_variable( "name", "anonymous" ) ;
    create_variable( "file", "my_data.txt" ) ;
    create_variable( "message", "hello" ) ;

    int& cnt = ints["count"] ;
    cnt += 8 ;

    std::string& msg = strings["message"] ;
    msg += " world" ;

    for( auto& p : ints ) std::cout << p.first << " == " << p.second << '\n' ;
    for( auto& p : strings ) std::cout << p.first << " == " << p.second << '\n' ;
}
count == 13
total == 0
file == my_data.txt
message == hello world
name == anonymous

http://coliru.stacked-crooked.com/a/10dc0d8fd3e7962a
Topic archived. No new replies allowed.