summaryrefslogtreecommitdiff
path: root/thue.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-18 01:10:00 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-18 01:10:00 +1100
commit50958fc5f2aad6f72fa8b948f8fa33713beb91a1 (patch)
tree9aefe125d84694f5c5a4614b39a1f3a90d2e3c3d /thue.hs
parentab757822c75aa71bd725126d9511fcb678f6e5e3 (diff)
Added basic command line programs to invoke Fractran and Thue interpreters
Diffstat (limited to 'thue.hs')
-rw-r--r--thue.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/thue.hs b/thue.hs
new file mode 100644
index 0000000..6630e6d
--- /dev/null
+++ b/thue.hs
@@ -0,0 +1,38 @@
+
+import System.Environment( getArgs )
+import Data.Typeable
+import qualified Control.Exception
+import Thue.Parser
+import Thue.Interpreter
+
+
+data ThueException = ThueException { errString :: String }
+ deriving (Show, Typeable)
+
+instance Control.Exception.Exception ThueException
+
+
+
+usageString :: String
+usageString = "Usage: thue <program file>"
+
+
+
+program :: IO ()
+program = do
+ args <- getArgs
+ fileContents <- if (length args /= 1)
+ then Control.Exception.throw (ThueException usageString)
+ else readFile (head args)
+
+ case (parseThue fileContents) of
+ Left x -> putStrLn (show x)
+ Right x -> (thue x) >>= (putStrLn . show)
+
+
+
+main = Control.Exception.catch program handler
+ where
+ handler :: ThueException -> IO ()
+ handler err = putStrLn (errString err)
+