diff options
Diffstat (limited to 'fractran.hs')
| -rw-r--r-- | fractran.hs | 38 | 
1 files changed, 38 insertions, 0 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) + | 
