Given 2 commands like: For(variable,start_val,end_val,step_val)
Next(variable)
How would one implement this, while maintaining the ability to nest them?
my first thought was to store the following:
-step size
-variable
-address of "For" command
-address of command following the "next" command ("next++_addr"
-flag bit to say if you were in "for-mode" or not
So then, in psuedo-code:
"for_address:"
If (for_mode=1) then goto continue_for
else
for_ptr=for_ptr+1
pop for_address
"continue_for:"
If for_var > final_for_val then
for_mode <= 0
Program_Counter <=(next++_addr)
for_ptr <= for_ptr - 1
else
(execute code here)
With the code for the "next" command like:
var = var + 1
goto for_addr
This would still be incomplete, however, as I would still need to store a stack of the (next++_addr) addresses as well.
Sorry this turned into kind of a rant, I just need some insight into how a For-loop usually works in an interpreter, and my brain is apparently not working =) Hippy? Demonicpicaxeguy? Anyone else?
Next(variable)
How would one implement this, while maintaining the ability to nest them?
my first thought was to store the following:
-step size
-variable
-address of "For" command
-address of command following the "next" command ("next++_addr"
-flag bit to say if you were in "for-mode" or not
So then, in psuedo-code:
"for_address:"
If (for_mode=1) then goto continue_for
else
for_ptr=for_ptr+1
pop for_address
"continue_for:"
If for_var > final_for_val then
for_mode <= 0
Program_Counter <=(next++_addr)
for_ptr <= for_ptr - 1
else
(execute code here)
With the code for the "next" command like:
var = var + 1
goto for_addr
This would still be incomplete, however, as I would still need to store a stack of the (next++_addr) addresses as well.
Sorry this turned into kind of a rant, I just need some insight into how a For-loop usually works in an interpreter, and my brain is apparently not working =) Hippy? Demonicpicaxeguy? Anyone else?