Skip to content

Commit

Permalink
Implement mki, the main interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunje Jun committed Mar 5, 2017
1 parent 0c17d16 commit 99b4db4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions monkey-hs.cabal
Expand Up @@ -39,6 +39,7 @@ executable mki
main-is: Main.hs
build-depends: base >=4.9 && <4.10
, protolude
, monkey-hs
hs-source-dirs: src
default-language: Haskell2010
default-extensions: OverloadedStrings
Expand Down
27 changes: 25 additions & 2 deletions src/Main.hs
@@ -1,6 +1,29 @@
module Main where

import Protolude
import Protolude hiding (evaluate)

import Common.ParserT (ParserError)
import Evaluator (eval)
import Lexer (lex)
import Parser (parse)
import System.Environment (getArgs)

main :: IO ()
main = putStrLn ("Hello, Haskell!" :: Text)
main = getArgs >>= traverse_ evalFile

evalFile :: FilePath -> IO ()
evalFile file = readFile file >>= evaluate

printError :: Exception e => e -> IO ()
printError e = putStrLn (show e :: Text)

evaluate :: Text -> IO ()
evaluate input = do
let parsed = lex input >>= parse
case parsed of
Left err -> printError err
Right ast -> do
evaluated <- eval ast
case evaluated of
Left err -> printError err
_ -> return ()

0 comments on commit 99b4db4

Please sign in to comment.