Choosing a variable based on user text input.
I have an assignment to write a simple interpreter for a made-up programming language, the code for which will be passed in a text file; for example,
INC(A)
would perform:
A++;
(the variable A is predefined). I know how to do most of it, but one part has stumped me: how do I tell C++ that it has to incriment the variable A? I could do it using an if or a case statement like:
Code:
void increment(char varName) {
if(varName == 'A') {
A++;
}
if(varName == 'B') {
B++;
}
}
but that gets ugly fast, considering there are five "functions" and ten variables. Any alternative ideas? I'm not looking for someone to do the work for me, but a hint on how to get C++ to pass the correct variable based on text input would be awesome. Thanks in advance.