summaryrefslogtreecommitdiff
path: root/src/thue.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/thue.hs')
-rw-r--r--src/thue.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/thue.hs b/src/thue.hs
new file mode 100644
index 0000000..89afcc3
--- /dev/null
+++ b/src/thue.hs
@@ -0,0 +1,30 @@
+
+import System.Environment( getArgs )
+import Control.Exception( ErrorCall(..), Handler(..), catches )
+import Thue.Parser
+import Thue.Interpreter
+
+
+
+
+usageString :: String
+usageString = "Usage: thue <program file>"
+
+
+
+program :: IO ()
+program = do
+ args <- getArgs
+ fileContents <- if (length args /= 1)
+ then error usageString
+ else readFile (head args)
+
+ case (parseThue fileContents) of
+ Left x -> putStrLn (show x)
+ Right x -> (thue x) >>= (putStrLn . show)
+
+
+
+main = catches program
+ [ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ]
+