Is there an EBNF rule that describes a Forth infinite loop or if statement?
EBNF is used to describe syntax. A loop being infinite or otherwise wouldn't normally fall within what it would describe. As such, you'd be looking at the EBNF for an indefinite loop, which looks something like:
indefinite_loop ::= 'BEGIN' statements cond 'UNTIL'
Normally the cond will be something that pushes a 0 or 1 on the stack to determine whether to continue the loop (0 means continue the loop, 1 means exit). As such, if you just insert a 0 directly, the loop will execute forever:
: infinite_loop BEGIN do_whatever 0 UNTIL ;
You can also use:
infinite_loop ::= 'BEGIN' statements 'AGAIN'
The AGAIN word is used to do an unconditional branch back to the BEGIN. For example:
: main-loop BEGIN listen-for-event process-event AGAIN ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With