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 /unlambda.hs | |
parent | f309a14ee66ca569d8f763f02c750f088165fe95 (diff) |
Added wrapper command line program for unlambda interpreter
Diffstat (limited to 'unlambda.hs')
-rw-r--r-- | unlambda.hs | 30 |
1 files changed, 30 insertions, 0 deletions
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 ()) ] + |