summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-26 16:36:54 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-26 16:36:54 +1100
commit16eb169df1f5a2dedfc6f71673982960d3ea73e6 (patch)
treeb39dff2b6117f0d33de6debdc28673877ddd2cc0
parent4885bc81e3716841723b585572ff157b4e324198 (diff)
Brainfuck interpreter frontend
-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