aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-12 22:53:06 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-12 22:53:06 +0100
commit279f04cb63e45ceb9a9df82540d5362565b8b37b (patch)
treebf71e8d7829e6ccf29320dacaf7c4742423683c5 /src/Main.hs
downloadmicro-lang-hs-279f04cb63e45ceb9a9df82540d5362565b8b37b.tar.gz
micro-lang-hs-279f04cb63e45ceb9a9df82540d5362565b8b37b.zip
Initial import
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs20
1 files changed, 20 insertions, 0 deletions
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