1 -- automatically generated by BNF Converter
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
20 type ParseFun a = [Token] -> Err a
24 splitFunStm :: [FuncStm] -> ([Func],[Stm])
25 splitFunStm [] = ([],[])
26 splitFunStm ((F f):fss) = let (fs,ss) = splitFunStm fss in (f:fs,ss)
27 splitFunStm ((S s):fss) = let (fs,ss) = splitFunStm fss in (fs,s:ss)
29 putStrV :: Int -> String -> IO ()
30 putStrV v s = if v > 1 then putStrLn s else return ()
32 runFile :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> FilePath -> IO ()
33 runFile e p f = readFile f >>= run e p
35 run :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> String -> IO ()
36 run e p s = let ts = myLLexer s in case p ts of
38 putStrLn "\nParse Failed...\n"
42 Ok (Program s) -> let (fun,st) = splitFunStm (s) in do
50 [] -> hGetContents stdin >>= run interpret pProgram
51 "-c":f:[] -> runFile (\fun st -> writeFile (f++".c") $ compile fun st) pProgram f
52 f:[] -> runFile interpret pProgram f
53 _ -> print "Too many arguments"