Writng a compiler

I need to write a program that wil read a txt file containg instructions like these
ADD R1, R2, R3
STORE R4, R1
SUB R5, R2, R3
whre R1, 2,3,4,5 are regsters or lets say variables.

My program should read the txt file, identify which operation to perform, and then perfrm the requird saving the results in R1, R4, R5 respectivly. .
Plz if anyone can tell me how to. ?
Firstly, it's an interpreter that you're trying to write.
Now. You need to read the file line by line. Split each line into several strings, so that "ADD R1, R2, R3" becomes "ADD", "R1", "R2", "R3". You'll want to use http://cplusplus.com/reference/string/string/substr/ and http://cplusplus.com/reference/string/string/find/ for that. Finally, convert register names to integers by simply doing int r = reg_name[1]-'0';

Then you have done that, check the first string and perform the appropriate operation in a long string of if-else statements. Your registers will be array elements.
Dear sir, i got the idea. But better f u post actual code for the operation. .?
You should do that yourself or you won't learn anything.
Topic archived. No new replies allowed.