Execute commands in a string in C ++

1

I have commands in a string something like:

string comm = "int x; cout << \"Digite um número\"; cin << x;";

My idea is to execute the commands that are in this string , having the result as if I had typed:

int x
cout << "Digite um número";
cin << x;

Is there any command to do this?

I thought of doing using in reader that identifies patterns and performs functions, but this would be very complicated, beyond what, I do not know how I would do to create the variables.

    
asked by anonymous 16.07.2017 / 02:47

1 answer

1

Generally speaking you do not have to, you have to create almost a compiler that does it for you. Of course you can use what you have ready as a basis to adapt.

Of course, if you restrict what you can use, it may be easier to do something simpler than a complete compiler, even though a C ++ compiler is very complicated, C ++ is considered the mainstream language more complicated to interpret.

If you find complicated pattern matching , then forget about it, because it is much more complicated than that.

    
16.07.2017 / 02:51