I’m writing a super small interpreter in vb.net because i need to execute a simple (invented) language so the app understand it and do what ever it needs to do.
Everything went well until i reached the control structures and the loops.
So my question its, in a code that its executed line by line using a simple for each how can i match the “WHILE ;” AND “ENDWHILE;” and execute the code within it?
The first thing that came to my mind its kind of flag the line of the reader and read the content from that line until find “ENDWHILE;” and the store that to execute late, so keep isolating the code in parts until I’ve all parts and then execute it.
But i’m not so sure how to code it or if my reasoning its correct.
PD: I’m using regexs.
I’m not sure I 100% understand what you are doing, so if this is way off, I apologize upfront :).
if you do something like this:
Then the code in m.Groups(2) should be just the inner WHILE code. In terms of explanation, the regex looks for WHILE, followed by any characters that are not ENDWHILE zero or more times, followed by ENDWHILE.
Again, sorry if this way off, and I haven’t tested the regex so it may need some tweaking.
Good luck!