I'm writing a converter for fairly basic scripting language, however it seems to lack the ability to use for loops. This makes code very messy and redundant, for instance, instead of:
for(int i = 0; i < 5; i++) {
ECHO Hello World!
SLEEP 500
}
The scripts written in this language end up looking like this:
ECHO Hello World!
SLEEP 500
ECHO Hello World!
SLEEP 500
ECHO Hello World!
SLEEP 500
ECHO Hello World!
SLEEP 500
ECHO Hello World!
SLEEP 500
and so on. So basically, I'm converting this script to c++, would it be possible to reduce all of these repeating calls? I had thought about looping through and looking for duplicate code, however the problem arises that I can't process code such as this:
ECHO 1
SLEEP 500
ECHO 2
SLEEP 500
ECHO 3
SLEEP 500
ECHO 4
Is there a simpler way to recognize these patterns or do I need to delve into something more complicated such as neural networks?