From 279f04cb63e45ceb9a9df82540d5362565b8b37b Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 12 Aug 2022 22:53:06 +0100 Subject: Initial import --- src/Main.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/Main.hs (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..e428ba5 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,20 @@ +module Main where + +import Compiler +import Control.Monad.State (evalState) +import qualified Data.Map as Map +import Lexer (scan) +import Parser (parse, parseFromFile) +import System.Exit (exitFailure) +import System.IO (hPutStrLn, stderr, stdout) + +main :: IO () +main = do + res <- parseFromFile (scan parse) "input" + case res of + Left err -> hPutStrLn stderr ("error: " ++ show err) >> exitFailure + Right ast -> do + res <- return $ evalState (compile ast) startState + case res of + Right _ -> print ast + Left errs -> hPutStrLn stderr $ showErrorList errs -- cgit v1.2.3