summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile7
-rw-r--r--unlambda.hs30
2 files changed, 35 insertions, 2 deletions
diff --git a/makefile b/makefile
index b702844..4388627 100644
--- a/makefile
+++ b/makefile
@@ -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 ()) ]
+