0

This code works well:

int One = 1;
int Two = 2;

if ( One == 1 && Two == 2)
{
   int i = 1;
}

What I now wonder is this. I want to put everything that is written inside the () in a textBox so it will look like this:

int One = 1;
int Two = 2;

if 
( 
One == 1 && Two == 2   // This line is written in a textBox
)
{
   int i = 1;
}

So what I am trying to achive is in anyway parse out every word and character from this textBox to be executable code.
I know that I have to use maps in any way but dont know how to start this and how this in the end will be executable code. I am reading about maps now to understand this better.

1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Jennifer84
0

For the example it is not necessary to parse out the words. I beleive it could be thought of separate strings to simplify it like this but dont know what next step is from here.

"One" //variable
"==" //operator
"1" //number
"&&" //operator
"Two" //variable
"==" //operator
"2" //number

I have seen an example of a <string, int> map like this. Though as the above shows it is different things all the time as int, variable, operator wich confuses me a bit.

map<string, int> data;
 
data["Ten"] = 10;
data["Fifteen"] = 15;
data["Thirtyfour"] = 34;
data["Twentytwo"] = 22;

I have also understand that there is maps that uses key values and mapped values wich I beleive is the more right approach for this:

map<Key,T>::iterator it;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.