summaryrefslogtreecommitdiff
path: root/src/unlambda.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
committerJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
commit281425310c5db21f87981eeb9601a71d1974d98d (patch)
treebef4643d906c93622c311fef2cf758fe94f1f651 /src/unlambda.hs
parente8695600977769008f285f9958eb043cca1b9b29 (diff)
Rearranging files
Diffstat (limited to 'src/unlambda.hs')
-rw-r--r--src/unlambda.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/unlambda.hs b/src/unlambda.hs
new file mode 100644
index 0000000..b06b42f
--- /dev/null
+++ b/src/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 ()) ]
+