Forth language EBNF rule for an infinite loop or if statement

青春壹個敷衍的年華 提交于 2019-12-02 00:07:14

问题


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


回答1:


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 ;



回答2:


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 ;


来源:https://stackoverflow.com/questions/6053030/forth-language-ebnf-rule-for-an-infinite-loop-or-if-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!