1 -- automatically generated by BNF Converter
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
15 import Control.Monad.State
16 import Data.Map as Map hiding (showTree)
23 type ParseFun a = [Token] -> Err a
29 putStrV :: Verbosity -> String -> IO ()
30 putStrV v s = if v > 1 then putStrLn s else return ()
32 runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
33 runFile v p f = putStrLn f >> readFile f >>= run v p
35 run :: Verbosity -> ParseFun Stms -> String -> IO ()
36 run v p s = let ts = myLLexer s in case p ts of
38 putStrLn "\nParse Failed...\n"
43 putStrLn "\nParse Successful!"
44 showTree v (Program s)
45 runStateT (mapM typeCheckStm s) empty
48 showTree :: (Show a, Print a) => Int -> a -> IO ()
51 putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
52 putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
55 main = do args <- getArgs
57 [] -> hGetContents stdin >>= run 2 pStms
58 "-s":fs -> mapM_ (runFile 0 pStms) fs
59 fs -> mapM_ (runFile 2 pStms) fs