blob: 964a0955bad660ef5137d7f4c2526b8989221f5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import System.Environment( getArgs )
import Data.Typeable
import Control.Exception( ErrorCall(..), Handler(..), catches )
import Fractran.Parser
import Fractran.Interpreter
usageString :: String
usageString = "Usage: fractran <program file>"
program :: IO ()
program = do
args <- getArgs
fileContents <- if (length args /= 1)
then error usageString
else readFile (head args)
case (parseFractran fileContents) of
Left x -> putStrLn (show x)
Right x -> putStrLn (show (fractran x))
main = catches program
[ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ]
|