1 -- automatically generated by BNF Converter
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
19 type ParseFun a = [Token] -> Err a
25 splitFunStm :: [FuncStm] -> ([Func],[Stm])
26 splitFunStm [] = ([],[])
27 splitFunStm ((F f):fss) = let (fs,ss) = splitFunStm fss in (f:fs,ss)
28 splitFunStm ((S s):fss) = let (fs,ss) = splitFunStm fss in (fs,s:ss)
30 putStrV :: Verbosity -> String -> IO ()
31 putStrV v s = if v > 1 then putStrLn s else return ()
33 runFile :: Verbosity -> ParseFun Program -> FilePath -> IO ()
34 runFile v p f = putStrLn f >> readFile f >>= run v p
36 run :: Verbosity -> ParseFun Program -> String -> IO ()
37 run v p s = let ts = myLLexer s in case p ts of
39 putStrLn "\nParse Failed...\n"
43 Ok (Program s) -> let (fun,st) = splitFunStm (s) in do
44 putStrLn "\nParse Successful!"
45 showTree v (Program s)
47 print "The program is type-correct!!"
48 print "Running program:"
50 print "Done running program!"
52 showTree :: (Show a, Print a) => Int -> a -> IO ()
55 putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
56 putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
59 main = do args <- getArgs
61 [] -> hGetContents stdin >>= run 2 pProgram
62 "-s":fs -> mapM_ (runFile 0 pProgram) fs
63 fs -> mapM_ (runFile 2 pProgram) fs