diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-26 16:36:54 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-26 16:36:54 +1100 |
commit | 16eb169df1f5a2dedfc6f71673982960d3ea73e6 (patch) | |
tree | b39dff2b6117f0d33de6debdc28673877ddd2cc0 | |
parent | 4885bc81e3716841723b585572ff157b4e324198 (diff) |
Brainfuck interpreter frontend
-rw-r--r-- | brainfuck.hs | 30 | ||||
-rw-r--r-- | makefile | 10 |
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 ()) ] + @@ -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 |