Anonymous user
Execute Brain****/Forth: Difference between revisions
m
moved RCBF/Forth to Execute Brain****/Forth
(switch to collection template) |
m (moved RCBF/Forth to Execute Brain****/Forth) |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}
A Brainf*** compiler written by [[User:IanOsgood|Ian Osgood]] in [[Forth]].
==Usage==
Load the code your preferred Forth environment. The code will define the
===Compiling Brainf*** code===
Let's say you have this sequence that prints a capital A:
++++++[>+++++++++++<-]>-.
You can compile it by using the ''':bf''' word:
:bf
Your Brainf*** code is now compiled in your Forth environment as the word '''printA'''. If you want to use a different
Larger BF programs may be loaded from a file instead of parsed from the interpreter:
:bf-file bottles bottles.bf
===Running the compiled Brainf*** code===
Assuming you used the word '''printA''' from the above example, you can execute your code by running the word:
Line 34 ⟶ 39:
[char] > of postpone right endof
[char] < of postpone left endof
[char] , of postpone
postpone key endof
[char] . of postpone dup
postpone emit endof
Line 40 ⟶ 46:
endcase ;
:
:▼
[char] " parse \ "▼
postpone init
bounds do i c@ compile-bf-char loop
Line 48 ⟶ 52:
postpone c!
postpone ;
;
: :bf ( name " bfcode" -- )
▲ :
compile-bf-string ;
: :bf-file ( name file -- )
:
bl parse slurp-file
compile-bf-string ;</pre>
|