Im working on my script compiler. All works fine, but at the saving part i got some problems.
I need some ideas from other people.
What i have is a list of ID's (identifications) of commands used in script.
The list is built as the commands are parsed from script (i mean, the commands ID's are put in same order into list, as they are found in script). This is important.
Almost each command has it's own struct which must be saved to compiled script in same order as they are found in source of script.
ID's are just int's, for ex: "cls" = 5 "begin" = 20, "end" = 25, "print" = 30 etc.
So for example i have script like:
begin cls print "hello" print "good bye" end
As you see from example, print is used twice: so command id's list for this script will be like this:
20 5 30 30 25
5 commands. Each of these commands structs must be saved to file, in same order.
The filling of structs is done earlier in parsing stage.
What i have now is just a for_loop, that goes thru ID's, for ex: 0 to 4, in this loop i check what ID i have currently, with "switch" statement.
In each "case" in "switch" i also loop through nr_of_current_command_id's", for example above, i need to loop 2 times, because i have 2 "print" commands.
It kinda works but because of first loop, it writes data too many times.
If i have 1 "print" command, it writes actually 2 of them. If i have 2 "print" commands, it writes 4 of them, etc.
Not good.
Any ideas how i could get rid of the main loop?
Im heavily using std::vector and std::map and iterators, because they are so good and neat.
I thought about something with std::map and go through it and if i find specific ID, i will save it.
But what about order of saving?
Im completely lost here.
I hope somebody understands my problem.
TIA for any help.






