-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interpret.hs
47 lines (35 loc) · 1.17 KB
/
Interpret.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
40
41
42
43
44
45
46
47
-- Jakub Kuszneruk jk320790
module Main where
import Control.Monad (liftM)
import System.Environment
import Lexshl
import Parshl
import Absshl
import Interpreter
import TypeChecker
import ErrM
import Control.Monad.Trans
import Misc
runFile :: FilePath -> IO ()
runFile f = putStrLn f >> readFile f >>= \s -> show_info s >> debug s >> run s
-- runFile f = putStrLn f >> readFile f >>= \s -> run s
main :: IO ()
main = do args <- getArgs
case args of
[] -> error "usage `interpreter <input file>`"
fs -> mapM_ runFile fs
run :: String -> IO ()
run s = let ts = myLexer s in case pProg ts of
Bad msg -> do putStrLn msg;
Ok p -> do
case (interpret p) of
Ok (St (_, _, _, _, Bst bst, _, _, _, _, _)) -> putStrLn $ show $ reverse bst
Bad c -> return()
return ();
-- print final state of a program
debug s = let ts = myLexer s in case pProg ts of
Bad msg -> do putStrLn msg;
Ok p -> do putStrLn $show (interpret p);
return ();
-- shows parsed file
show_info s = putStrLn $show (pProg $ myLexer s)