rendered paste body# ksh93 brainfuck compilertypeset -T countcache_t=( typeset op="" integer count=0 typeset tabe="" # tab engine function flush { nameref t=${_.tabe} if [[ "${_.op}" != "" ]] ; then t.w ; printf "${_.op}\n" _.count fi # reset (( _.count=0 )) _.op="" return 0 } function write_op { typeset wop="$1" [[ "${wop}" != "${_.op}" ]] && _.flush (( _.count++ )) _.op="${wop}" return 0 })# manage tab intentstypeset -T tab_t=( typeset indent="" function inc { _.indent+=$'\t' return 0 } function dec { _.indent="${_.indent:0:${#_.indent}-1}" return 0 } function w # write { printf "%s" "${_.indent}" return 0 })function write_bf_head{cat <<EOF#!/usr/bin/ksh93# I/O functionsfunction pc # putchar{ nameref x=\$1 typeset c c=\${ printf "%x\n" "\$x" ; } printf "\u[\${c}]" return 0}function gc # getchar{ nameref x="\$1" typeset c # we only write into "x" if we could read a character if read -N1 c ; then (( x='\${c} )) fi return 0}# mainset -o noglobIFS=''integer -a tinteger p(( p=2**18 )) # tape start position# bf program startEOF return 0}function write_bf_tail{cat <<EOF# bf program endexit 0EOF return 0}function brainfuck2shell{ typeset c while read -N1 c ; do case "$c" in '>') cc.write_op '(( p+=%d ))' ;; '<') cc.write_op '(( p-=%d ))' ;; '+') cc.write_op '(( t[p]+=%d ))' ;; '-') cc.write_op '(( t[p]-=%d ))' ;; '.') cc.flush ; tb.w ; print 'pc t[p]' ;; ',') cc.flush ; tb.w ; print 'gc t[p]' ;; '[') cc.flush ; tb.w ; print 'while (( t[p] != 0 )) ; do' ; tb.inc ;; ']') cc.flush ; tb.dec ; tb.w ; print 'done' ;; esac done return 0}# mainset -o noglobset -o nounsetIFS=''tab_t tbcountcache_t cc=( tabe=tb )write_bf_headbrainfuck2shellwrite_bf_tailexit 0