]> ruin.nu Git - proglang.git/commitdiff
fully functional and C99 (not C90) compliant output
authorMichael Andreen <harv@ruin.nu>
Wed, 1 Mar 2006 19:21:40 +0000 (19:21 +0000)
committerMichael Andreen <harv@ruin.nu>
Wed, 1 Mar 2006 19:21:40 +0000 (19:21 +0000)
Compiler.hs

index 2f1f31bbd0e16e2e8f00237907e464f875ed2528..d971b2f19954bccca195f9d33419e9c9f6d48e0d 100644 (file)
@@ -24,6 +24,10 @@ myLLexer = myLexer
 
 type Verbosity = Int
 
+cHeader = "#include <stdio.h>\nint read(){\nint n;\nscanf(\"%d\",&n);\nreturn n;\n}\nint main(void){\n"
+
+cFooter = "return 0;}"
+
 putStrV :: Verbosity -> String -> IO ()
 putStrV v s = if v > 1 then putStrLn s else return ()
 
@@ -39,7 +43,7 @@ run v p s = let ts = myLLexer s in case p ts of
                putStrLn s
        Ok (Program s) -> do
                runStateT (mapM typeCheckStm s) [empty]
-               putStr $ concat (map compileStm s) 
+               putStr $ cHeader++concat (map compileStm s)++cFooter
                return ()
 
 showTree :: (Show a, Print a) => Int -> a -> IO ()