X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=CompInt.hs;fp=CompInt.hs;h=d5aa2ca052ada77068d47afd86bb901eeb053a98;hp=0000000000000000000000000000000000000000;hb=04f0a9566794cf761b7bcf83190051a400ec3653;hpb=8687a7c6790e959242228d64c8c513771565f8c1 diff --git a/CompInt.hs b/CompInt.hs new file mode 100644 index 0000000..d5aa2ca --- /dev/null +++ b/CompInt.hs @@ -0,0 +1,53 @@ +-- 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 ErrM + +type ParseFun a = [Token] -> Err a + +myLLexer = myLexer + +splitFunStm :: [FuncStm] -> ([Func],[Stm]) +splitFunStm [] = ([],[]) +splitFunStm ((F f):fss) = let (fs,ss) = splitFunStm fss in (f:fs,ss) +splitFunStm ((S s):fss) = let (fs,ss) = splitFunStm fss in (fs,s:ss) + +putStrV :: Int -> String -> IO () +putStrV v s = if v > 1 then putStrLn s else return () + +runFile :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> FilePath -> IO () +runFile e p f = readFile f >>= run e p + +run :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> 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) -> let (fun,st) = splitFunStm (s) in do + typeCheck fun st + e fun st + +main :: IO () +main = do + args <- getArgs + case args of + [] -> hGetContents stdin >>= run interpret pProgram + "-c":f:[] -> runFile (\fun st -> writeFile (f++".c") $ compile fun st) pProgram f + f:[] -> runFile interpret pProgram f + _ -> print "Too many arguments"