diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-14 01:58:00 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-14 01:58:00 +1100 |
commit | 370847f0326e1cdf848d674b7cfd89565f3e8757 (patch) | |
tree | 5997cbd03c11909134676789c2fd479b830753bf | |
parent | f309a14ee66ca569d8f763f02c750f088165fe95 (diff) |
Added wrapper command line program for unlambda interpreter
-rw-r--r-- | makefile | 7 | ||||
-rw-r--r-- | unlambda.hs | 30 |
2 files changed, 35 insertions, 2 deletions
@@ -1,11 +1,11 @@ OUTPUTDIR = bin -EXECUTABLES = ${OUTPUTDIR}/test ${OUTPUTDIR}/fractran ${OUTPUTDIR}/thue +EXECUTABLES = ${OUTPUTDIR}/test ${OUTPUTDIR}/fractran ${OUTPUTDIR}/thue ${OUTPUTDIR}/unlambda -all: testprog fractranprog thueprog +all: testprog fractranprog thueprog unlambdaprog clean: @@ -26,3 +26,6 @@ fractranprog: thueprog: ghc --make thue.hs -o ${OUTPUTDIR}/thue +unlambdaprog: + ghc -XDeriveDataTypeable --make unlambda.hs -o ${OUTPUTDIR}/unlambda + diff --git a/unlambda.hs b/unlambda.hs new file mode 100644 index 0000000..b06b42f --- /dev/null +++ b/unlambda.hs @@ -0,0 +1,30 @@ + +import System.Environment( getArgs ) +import Control.Exception( ErrorCall(..), Handler(..), catches ) +import Unlambda.Parser +import Unlambda.Interpreter + + + + +usageString :: String +usageString = "Usage: unlambda <program file>" + + + +program :: IO () +program = do + args <- getArgs + fileContents <- if (length args /= 1) + then error usageString + else readFile (head args) + + case (parseUnlambda fileContents) of + Left x -> putStrLn (show x) + Right x -> unlambda x >>= putStrLn . show + + + +main = catches program + [ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ] + |