Created
May 31, 2010 01:59
-
-
Save micahrj/419469 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module BF (run, Memory, Command) where | |
import Data.Char | |
data Memory = Memory [Integer] Integer [Integer] | |
empty = Memory [0,0..] 0 [0,0..] | |
type Command = Char | |
run :: [Commmand] -> (Memory, String) | |
run cs = exec cs empty "" | |
exec :: [Command] -> Memory -> String -> (Memory, String) | |
exec [] m s = (m, s) | |
exec ('+':cs) (Memory xs n ys) s = run cs (Memory xs (n+1) ys) s | |
exec ('-':cs) (Memory xs n ys) s = run cs (Memory xs (n-1) ys) s | |
exec ('<':cs) (Memory (x:xs) y ys) s = run cs (Memory xs x (y:ys)) s | |
exec ('>':cs) (Memory xs x (y:ys)) s = run cs (Memory (x:xs) y ys) s | |
exec ('.':cs) m@(Memory xs y zs) s = run cs m (s ++ [(chr y)]) | |
exec ('[':cs) m s = |
I'm going to implement 'while' in this (or at least attempt to)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome. No 'while' though, and no 'getc'. :(