aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: e428ba5ce1aab6b37eef38f8dd489661fe782e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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