Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forth language EBNF rule for an infinite loop or if statement

Tags:

forth

ebnf

Is there an EBNF rule that describes a Forth infinite loop or if statement?

like image 883
shobhnit Avatar asked Dec 12 '25 17:12

shobhnit


2 Answers

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 ;
like image 77
Jerry Coffin Avatar answered Dec 14 '25 06:12

Jerry Coffin


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 ;
like image 45
Peter Knaggs Avatar answered Dec 14 '25 06:12

Peter Knaggs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!