Execute Brain****: Difference between revisions

Content added Content deleted
(Added Quackery.)
Line 5,485: Line 5,485:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ stack ] is tape ( --> s )
<lang Quackery> [ stack ] is switch.arg ( --> [ )
[ switch.arg put ] is switch ( x --> )


[ stack ] is counter ( --> s )
[ switch.arg release ] is otherwise ( --> )


[ switch.arg share != iff ]else[ done
[ stack ] is input$ ( --> s )
otherwise ]'[ do ]done[ ] is case ( x --> )


[ dip tuck unrot poke swap ] is poketape ( [ n n --> [ n )
[ 1 counter tally counter share
tape share size = if
[ tape take 0 join tape put ] ] is stepright ( --> )


[ 1+ over size over = if [ dip [ 0 join ] ] ] is stepright ( [ n --> [ n )
[ counter share 0 = iff
[ 0 tape take join tape put ]
else [ -1 counter tally ] ] is stepleft ( --> )


[ dup 0 = iff [ 0 rot join swap ] else [ 1 - ] ] is stepleft ( [ n --> [ n )
[ tape take counter share
2dup peek 1 + unrot poke tape put ] is increment ( --> )


[ 2dup peek 1 + poketape ] is increment ( [ n --> [ n )
[ tape take counter share
2dup peek 1 - unrot poke tape put ] is decrement ( --> )


[ tape share counter share peek emit ] is print ( --> )
[ 2dup peek 1 - poketape ] is decrement ( [ n --> [ n )


[ 2dup peek emit ] is print ( [ n --> [ n )


[ input$ take dup $ "" = iff 0 else behead
[ temp take dup $ "" = iff 0 else behead
swap temp put poketape ] is getchar ( [ n --> [ n )
tape take counter share
poke tape put input$ put ] is getchar ( --> )
[ 2dup peek 0 = ] is zero ( [ n --> [ n b )


[ temp put $ "" swap witheach
[ tape share counter share peek 0 = ] is zero ( --> b )
[ switch
[ char > case [ $ "stepright " join ]
char < case [ $ "stepleft " join ]
char + case [ $ "increment " join ]
char - case [ $ "decrement " join ]
char . case [ $ "print " join ]
char , case [ $ "getchar " join ]
char [ case [ $ "[ zero if done " join ]
char ] case [ $ "zero until ] " join ]
otherwise ( ignore ) ] ]
0 nested 0 rot quackery temp release 2drop ] is brainf*** ( $ $ --> )</lang>


{{out}}
[ input$ put
' [ 0 ] tape put 0 counter put
$ "" swap witheach
[ dup char > = iff
[ drop $ "stepright " join ] done
dup char < = iff
[ drop $ "stepleft " join ] done
dup char + = iff
[ drop $ "increment " join ] done
dup char - = iff
[ drop $ "decrement " join ] done
dup char . = iff
[ drop $ "print " join ] done
dup char , = iff
[ drop $ "getchar " join ] done
dup char [ = iff
[ drop $ "[ zero if done " join ]
done
dup char ] = iff
[ drop $ "zero until ] " join ]
done
drop ]
quackery
' [ input$ tape counter ]
witheach release ] is brainf*** ( $ $ --> )</lang>


Testing <code>brainf***</code> in Quackery shell with Brainf*** code from [[Reverse a string#Brainf***]].
Testing <code>brainf***</code> in Quackery shell with Brainf*** code from [[Reverse a string#Brainf***]].