added symbol table for repl mode

This commit is contained in:
Dario48 2026-03-02 22:16:12 +01:00
commit 68326a19a1

View file

@ -36,6 +36,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.[b] |"
>> 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.[c] |"
>> putStrLn "|--------+-------------------------------------------------------------------------------------------------------|"
>> repl interpreter
brainfuck -> interpreter `execStr` brainfuck >>= repl
main :: IO ()