1 -- automatically generated by BNF Converter
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
17 import Data.Map as Map hiding (showTree)
21 type ParseFun a = [Token] -> Err a
26 cHeader = "#include <stdio.h>\nint read(){\nint n;\nscanf(\"%d\",&n);\nreturn n;\n}\nint main(void){\n"
28 cFooter = "return 0;}"
30 putStrV :: Int -> String -> IO ()
31 putStrV v s = if v > 1 then putStrLn s else return ()
33 runFile :: ([Stm] -> IO()) -> ParseFun Stms -> FilePath -> IO ()
34 runFile e p f = readFile f >>= run e p
36 run :: ([Stm] -> IO()) -> ParseFun Stms -> String -> IO ()
37 run e p s = let ts = myLLexer s in case p ts of
39 putStrLn "\nParse Failed...\n"
51 [] -> hGetContents stdin >>= run interpret pStms
52 "-c":f:[] -> let file = (f++".c") in do
53 putStrLn $ "Compiling "++f++" to the C99-compatible file:"++file
54 runFile (writeFile file . compile) pStms f
55 f:[] -> runFile interpret pStms f
57 putStrLn "Usage: ./CompInt [-c] <file>"
58 putStrLn "-c : compile <file> to C99-compatible file"