summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brainfuck.hs30
-rw-r--r--makefile10
2 files changed, 38 insertions, 2 deletions
diff --git a/brainfuck.hs b/brainfuck.hs
new file mode 100644
index 0000000..5f13ae6
--- /dev/null
+++ b/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 ()) ]
+
diff --git a/makefile b/makefile
index 0eb8b14..66a2928 100644
--- a/makefile
+++ b/makefile
@@ -1,13 +1,17 @@
OUTPUTDIR = bin
-EXECUTABLES = ${OUTPUTDIR}/test ${OUTPUTDIR}/fractran ${OUTPUTDIR}/thue ${OUTPUTDIR}/unlambda
+EXECUTABLES = ${OUTPUTDIR}/test \
+ ${OUTPUTDIR}/fractran \
+ ${OUTPUTDIR}/thue \
+ ${OUTPUTDIR}/unlambda \
+ ${OUTPUTDIR}/brainfuck
SWITCHES = -XDeriveDataTypeable
-all: testprog fractranprog thueprog unlambdaprog
+all: testprog fractranprog thueprog unlambdaprog brainfuckprog
clean:
@@ -31,3 +35,5 @@ thueprog:
unlambdaprog:
ghc ${SWITCHES} --make unlambda.hs -o ${OUTPUTDIR}/unlambda
+brainfuckprog:
+ ghc ${SWITCHES} --make brainfuck.hs -o ${OUTPUTDIR}/brainfuck