aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 47fd8839d196265b7c0551c0371e79cb400908b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Main where

import Compiler
import Control.Monad.State (evalState)
import qualified Data.Map as Map
import Error (showErrorList, showParserError)
import Lexer (scan)
import Parser (parse, parseFromFile)
import System.Exit (exitFailure)
import System.IO (hPutStr, hPutStrLn, stderr, stdout)

main :: IO ()
main = do
  res <- parseFromFile (scan parse) "input"
  case res of
    Left err -> hPutStrLn stderr (showParserError err) >> exitFailure
    Right ast -> do
      res <- return $ evalState (compileAll ast) startState
      case res of
        Right _ -> print ast
        Left errs -> hPutStr stderr $ showErrorList errs