Compare commits

...

2 commits

View file

@ -21,6 +21,7 @@ repl interpreter = do
putStrLn " :h = this text"
putStrLn " :q = quit"
putStrLn " :d = print the state of the array around the index"
putStrLn " :s = print a table of all symbols and their functionality"
repl interpreter
":q" -> return ()
":d" ->
@ -36,6 +37,28 @@ repl interpreter = do
| other == size - 0 -> printf "... %u %u |%u| ]\n" (arr ! (size - 2)) (arr ! (size - 1)) (arr ! size)
| otherwise -> printf "... %u %u |%u| %u %u ...\n" (arr ! (other - 2)) (arr ! (other - 1)) (arr ! other) (arr ! (other + 1)) (arr ! (other + 2))
>> repl interpreter
":s" ->
return ()
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| symbol | description |"
>> putStrLn "|========+=======================================================================================================|"
>> putStrLn "| > | Increment the data pointer by one (to point to the next cell to the right). |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| < | Decrement the data pointer by one (to point to the next cell to the left). Undefined if at 0. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| + | Increment the byte at the data pointer by one modulo 256. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| - | Decrement the byte at the data pointer by one modulo 256. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| . | Output the byte at the data pointer. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| , | Accept one byte of input, storing its value in the byte at the data pointer. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| [ | If the byte at the data pointer is zero, jump forward to the command after the matching ] command. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> putStrLn "| ] | If the byte at the data pointer is nonzero, jump back to the command after the matching [ command. |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> repl interpreter
brainfuck -> interpreter `execStr` brainfuck >>= repl
main :: IO ()