Created
December 9, 2011 16:49
-
-
Save takeshik/1452333 to your computer and use it in GitHub Desktop.
Brainf*ck on Yacq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def bf (\ [c:String] ($ [ | |
d Int32.array.(new 30000) ; data array | |
di 0 ; data index | |
ci 0 ; code index | |
s Stack.[Int32].(new) ; jump stack | |
jc 0 ; jump counter | |
] | |
EnumerableEx.(Repeat c) | |
.(TakeWhile {!= ci $0.Length}) | |
.(ForEach {$ | |
(== jc 0).(if | |
$0.[ci].(switch | |
'>' | |
(++= di) | |
'<' | |
(--= di) | |
'+' | |
(++= d.[di]) | |
'-' | |
(--= d.[di]) | |
'.' | |
d.[di].(to Char).(printn) | |
',' | |
(= d.[di] (type 'System.Console').(ReadKey).KeyChar.(to Int32)) | |
'[' ($ | |
s.(Push ci) | |
(== d.[di] 0).(then (++= jc)) | |
) | |
']' | |
(!= d.[di] 0).(then (= ci (-- s.(Pop)))) | |
; otherwise - do nothing | |
) | |
(== $0.[ci] ']').(then s.(Pop) (--= jc)) | |
) | |
(++= ci) | |
}) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment