;;; variables
:input
:flag
:zero
;;; macros
;; read byte with all EOF conventions
;; + it also stops on linefeed
;; compatible BF interpreters translate CRLF => LF
;; so this would be portable
;; char value is one more than actual value
{read_byte
$flag +
$input ,
+[-[10-[11+$flag-]]]
>[@flag-$zero]
}
;; assumes current cell is empty
;; prints out a linefeed
{linefeed
10+.
}
;; Assumes data starts to the left of current cell
;; prints until zero
{print_bytes_left
<[.<]
}
;;; main program
while more $input +
( -
>@input ;; shift variables to the right
&read_byte ;; read in byte
)
&print_bytes_left
&linefeed
Since someone beat me to a BF answer I rewrote it in EBF and made it portable and compatible. This doesn't wrap cells, it stops when encontering any one of the 3 EOF indicators or a linefeed. In compatible interpreters CRLF is translated to just a LF so this should work on any interpreter.
Usage:
% bf ebf.bf < rev.ebf > rev.bf
% echo 2345 | bf -w rev.bf
5432
The resulting BrainFuck code (output of jitbf rev.bf --bf
) is:
-[+>>+<,+[-[----------[+++++++++>-]]]>[->]<<]<[.<]++++++++++.
Same as with the previous answer and the other BF entry this just stores the input and print it in reverse order.
I don't consider this an array since I made no way of random access (yes, I use arrays in (E)BF) so this is more a stack structure.
Strings do not exist in BF but we do store them in similar manner as in this code.
1230
is the input? Are we allowed to output321
? (Otherwise, Strings are necessary). \$\endgroup\$