From fbed3a4b44823256f17c6a4473e0ec3f63792be6 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 20 Jan 2017 16:21:22 +0100 Subject: Initial -- dump of stuff --- main.hs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main.hs (limited to 'main.hs') diff --git a/main.hs b/main.hs new file mode 100644 index 0000000..e1b975a --- /dev/null +++ b/main.hs @@ -0,0 +1,38 @@ +module Main where + +import Control.Monad +import Data.Either +import System.Environment +import System.Exit + +import Codegen +import Parser +import PShow + + +fromLeft :: Either a b -> a +fromLeft (Left a) = a +fromLeft (Right _) = error "Either is not a Left" + +fromRight :: Either a b -> b +fromRight (Right b) = b +fromRight (Left _) = error "Either is not a Right" + +dieShow :: (Show a) => a -> IO () +dieShow = die . show + + +main :: IO () +main = do + args <- getArgs + when (length args /= 1) $ die "Pass NL file name as a command-line parameter" + + let fname = args !! 0 + parseResult <- (\file -> parseProgram file fname) <$> readFile fname + + when (isLeft parseResult) $ dieShow $ fromLeft parseResult + + let ast = fromRight parseResult + pprint ast + + either die print $ codegen ast "Module" fname -- cgit v1.2.3-54-g00ecf