(Not sure if this post will show up correctly in the thread, as I am using mobile Google groups.)
I was going towards the direction of "program counter" while implementing condition and loop for my Forth clone 5GL.
1) Given 5GL commands:
Example #1:
array foreach: cmd1: cmd2: cmd3: ....
Example #2:
array foreach: begin: cmd1: cmd2: end: cmd3: ....
2) A 5GL command (equivalent to Forth word) has a colon ( : ) suffix, as it is easy to use JavaScript split() function to obtain an array of the commands.
3) The index of the array of commands is therefore equivalent to "program counter" in microprocessor.
4) Each 5GL command will be mapped to a JavaScript function with prefix fgl_ e.g. fgl_foreach(), fgl_cmd1(), ... etc.
5) As such, to implement loop ( foreach: equivalent to PHP foreach () ), in fgl_foreach(), it reads the next command, or the next block of commands, marked by begin: .... end:
At the end of loop, it returns the offset of the last command index (program counter) from the index of the loop command (foreach:) to the master control loop (MCL).
So, MCL will resume execution at cmd2: in Example #1 and at cmd3: in Example #2.
5) The current example concerns obtaining the 'id' from the array returned by document.body.getElementsByTagName('*')
I am not sure if Forthers would appreciate the irony of using a Forth clone for such high level applications. Forth and JavaScript DOM would represent the earliest and the latest in the evolution of computer programming.
6) I will enable
5gl.pagekite.me for readers to test and verified later.
Thank you very much.