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:[] -> let file = (f++".c") in do
52 putStrLn $ "Compiling "++f++" to the C99-compatible file:"++file
53 runFile (\fun st -> writeFile file $ compile fun st) pProgram f
54 f:[] -> runFile interpret pProgram f
56 putStrLn "Usage: ./CompInt [-c] <file>"
57 putStrLn "-c : compile <file> to C99-compatible file"