summaryrefslogtreecommitdiff
path: root/src/brainfuck.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/brainfuck.hs')
-rw-r--r--src/brainfuck.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/brainfuck.hs b/src/brainfuck.hs
new file mode 100644
index 0000000..5f13ae6
--- /dev/null
+++ b/src/brainfuck.hs
@@ -0,0 +1,30 @@
+
+import System.Environment( getArgs )
+import Control.Exception( ErrorCall(..), Handler(..), catches )
+import Brainfuck.Parser
+import Brainfuck.Interpreter
+
+
+
+
+usageString :: String
+usageString = "Usage: brainfuck <program file>"
+
+
+
+program :: IO ()
+program = do
+ args <- getArgs
+ fileContents <- if (length args /= 1)
+ then error usageString
+ else readFile (head args)
+
+ case (parseBrainfuck fileContents) of
+ Left x -> putStrLn (show x)
+ Right x -> brainfuck x >> return ()
+
+
+
+main = catches program
+ [ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ]
+