]> ruin.nu Git - proglang.git/commitdiff
CompInt, integrated compiler and interpreter for the new century
authorMichael Andreen <harv@ruin.nu>
Tue, 14 Mar 2006 17:29:20 +0000 (17:29 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 14 Mar 2006 17:29:20 +0000 (17:29 +0000)
CompInt.hs [new file with mode: 0644]

diff --git a/CompInt.hs b/CompInt.hs
new file mode 100644 (file)
index 0000000..1188466
--- /dev/null
@@ -0,0 +1,54 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import Lexsyntax
+import Parsyntax
+import Skelsyntax
+import Printsyntax
+import Abssyntax
+
+import Typecheck
+import Interpret
+import Compile
+import Data.Map as Map hiding (showTree)
+
+import ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = myLexer
+
+
+cHeader = "#include <stdio.h>\nint read(){\nint n;\nscanf(\"%d\",&n);\nreturn n;\n}\nint main(void){\n"
+
+cFooter = "return 0;}"
+
+putStrV :: Int -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: ([Stm] -> IO()) -> ParseFun Stms -> FilePath -> IO ()
+runFile e p f = readFile f >>= run e p
+
+run :: ([Stm] -> IO()) -> ParseFun Stms -> String -> IO ()
+run e p s = let ts = myLLexer s in case p ts of
+       Bad s    -> do
+               putStrLn "\nParse              Failed...\n"
+               putStrLn "Tokens:"
+               putStrLn $ show ts
+               putStrLn s
+       Ok (Program s) -> do
+               typeCheck s
+               e s
+
+main :: IO ()
+main = do 
+       args <- getArgs
+       case args of
+               [] -> hGetContents stdin >>= run interpret pStms
+               "-c":f:[] -> runFile (writeFile (f++".c") . compile)  pStms f
+               f:[] -> runFile interpret pStms f
+               _ -> print "Too many arguments"