summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fractran.hs38
-rw-r--r--makefile19
-rw-r--r--thue.hs38
3 files changed, 90 insertions, 5 deletions
diff --git a/fractran.hs b/fractran.hs
new file mode 100644
index 0000000..7f3946f
--- /dev/null
+++ b/fractran.hs
@@ -0,0 +1,38 @@
+
+import System.Environment( getArgs )
+import Data.Typeable
+import qualified Control.Exception
+import Fractran.Parser
+import Fractran.Interpreter
+
+
+data FractranException = FractranException { errString :: String }
+ deriving (Show, Typeable)
+
+instance Control.Exception.Exception FractranException
+
+
+
+usageString :: String
+usageString = "Usage: fractran <program file>"
+
+
+
+program :: IO ()
+program = do
+ args <- getArgs
+ fileContents <- if (length args /= 1)
+ then Control.Exception.throw (FractranException usageString)
+ else readFile (head args)
+
+ case (parseFractran fileContents) of
+ Left x -> putStrLn (show x)
+ Right x -> putStrLn (show (fractran x))
+
+
+
+main = Control.Exception.catch program handler
+ where
+ handler :: FractranException -> IO ()
+ handler err = putStrLn (errString err)
+
diff --git a/makefile b/makefile
index d5a3939..961af1a 100644
--- a/makefile
+++ b/makefile
@@ -1,10 +1,12 @@
-OUTPUTDIR = ./bin
+OUTPUTDIR = bin
-EXECUTABLES = ${OUTPUTDIR}/test
+EXECUTABLES = ${OUTPUTDIR}/test ${OUTPUTDIR}/fractran ${OUTPUTDIR}/thue
-all: test
+
+all: testprog fractranprog thueprog
+
clean:
find . -name '*.hi' -delete
@@ -14,6 +16,13 @@ distclean:
rm ${EXECUTABLES}
-test:
- ghc --make ./test.hs -o ${OUTPUTDIR}/test
+
+testprog:
+ ghc --make test.hs -o ${OUTPUTDIR}/test
+
+fractranprog:
+ ghc -XDeriveDataTypeable --make fractran.hs -o ${OUTPUTDIR}/fractran
+
+thueprog:
+ ghc -XDeriveDataTypeable --make thue.hs -o ${OUTPUTDIR}/thue
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)
+