-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.hs
39 lines (31 loc) · 995 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- automatically generated by BNF Converter
module Main where
import System.Environment (getArgs)
import System.IO()
import MIML.Abs
import MIML.ErrM
import MIML.Lex
import MIML.Par
import MIML.Print()
import MIML.Skel()
import Interpreter
import Control.Monad.Reader
import qualified Data.Map as Map
type ParseFun a = [Token] -> Err a
runFile :: FilePath -> IO ()
runFile f = putStrLn f >> readFile f >>= run
run :: String -> IO ()
run s = let ts = myLexer s in case pExp ts of
Bad err -> error err
Ok tree -> print $ runReader (eval tree) iEnv
where iEnv = Map.fromList [(Ident "true", Bool True),
(Ident "false", Bool False)]
main :: IO ()
main = do
args <- getArgs
if null args then do
contents <- getContents
run contents
else do
input <- readFile (head args)
run input