1 -- automatically generated by BNF Converter
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
16 import Control.Monad.State
17 import Data.Map as Map hiding (showTree)
21 type ParseFun a = [Token] -> Err a
27 putStrV :: Verbosity -> String -> IO ()
28 putStrV v s = if v > 1 then putStrLn s else return ()
30 runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
31 runFile v p f = putStrLn f >> readFile f >>= run v p
33 run :: Verbosity -> ParseFun Stms -> String -> IO ()
34 run v p s = let ts = myLLexer s in case p ts of
36 putStrLn "\nParse Failed...\n"
41 putStrLn "\nParse Successful!"
42 showTree v (Program s)
43 runStateT (mapM typeCheckStm s) [empty]
44 print "The program is type-correct!!"
45 print "Running program:"
46 runStateT (mapM execute s) [empty]
47 print "Done running program!"
50 showTree :: (Show a, Print a) => Int -> a -> IO ()
53 putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
54 putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
57 main = do args <- getArgs
59 [] -> hGetContents stdin >>= run 2 pStms
60 "-s":fs -> mapM_ (runFile 0 pStms) fs
61 fs -> mapM_ (runFile 2 pStms) fs