Last active
August 29, 2015 14:03
-
-
Save zeptometer/ecccb203589da1660376 to your computer and use it in GitHub Desktop.
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
bf_([], _, [], _, _, _, _). | |
bf_([plus | Ops], In, Out, Stack, Cur, Left, Right) :- Val is Cur+1, bf_(Ops, In, Out, Stack, Val, Left, Right). | |
bf_([minus | Ops], In, Out, Stack, Cur, Left, Right) :- Val is Cur-1, bf_(Ops, In, Out, Stack, Val, Left, Right). | |
bf_([next | Ops], In, Out, Stack, Cur, Left, []) :- bf_(Ops, In, Out, Stack, 0, [Cur|Left], []). | |
bf_([next | Ops], In, Out, Stack, Cur, Left, [Next|Right]) :- bf_(Ops, In, Out, Stack, Next, [Cur|Left], Right). | |
bf_([prev | Ops], In, Out, Stack, Cur, [], Right) :- bf_(Ops, In, Out, Stack, 0, [], [Cur|Right]). | |
bf_([prev | Ops], In, Out, Stack, Cur, [Next|Left], Right) :- bf_(Ops, In, Out, Stack, Next, Left, [Cur|Right]). | |
bf_([get | Ops], [], Out, Stack, _, Left, Right) :- bf_(Ops, [], Out, Stack, 0, Left, Right). | |
bf_([get | Ops], [C|In], Out, Stack, _, Left, Right) :- bf_(Ops, In, Out, Stack, C, Left, Right). | |
bf_([put | Ops], In, [Cur|Out], Stack, Cur, Left, Right) :- bf_(Ops, In, Out, Stack, Cur, Left, Right). | |
bf(Ops, In, Out) :- bf_(Ops, In, Out, [], 0, [], []). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
brainfuck virtual machine implemented by Prolog.