]> ruin.nu Git - proglang.git/blob - Typechecker.hs
interpreter seems to work
[proglang.git] / Typechecker.hs
1 -- automatically generated by BNF Converter
2 module Main where
3
4
5 import IO ( stdin, hGetContents )
6 import System ( getArgs, getProgName )
7
8 import Lexsyntax
9 import Parsyntax
10 import Skelsyntax
11 import Printsyntax
12 import Abssyntax
13
14 import Typecheck
15 import Control.Monad.State
16 import Data.Map as Map hiding (showTree)
17
18 import ErrM
19
20 type ParseFun a = [Token] -> Err a
21
22 myLLexer = myLexer
23
24 type Verbosity = Int
25
26 putStrV :: Verbosity -> String -> IO ()
27 putStrV v s = if v > 1 then putStrLn s else return ()
28
29 runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
30 runFile v p f = putStrLn f >> readFile f >>= run v p
31
32 run :: Verbosity -> ParseFun Stms -> String -> IO ()
33 run v p s = let ts = myLLexer s in case p ts of
34         Bad s    -> do
35                 putStrLn "\nParse              Failed...\n"
36                 putStrV v "Tokens:"
37                 putStrV v $ show ts
38                 putStrLn s
39         Ok (Program s) -> do
40                 putStrLn "\nParse Successful!"
41                 showTree v (Program s)
42                 runStateT (mapM typeCheckStm s) [empty]
43                 print "The program is type-correct!!"
44                 return ()
45
46 showTree :: (Show a, Print a) => Int -> a -> IO ()
47 showTree v tree
48  = do
49       putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
50       putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
51
52 main :: IO ()
53 main = do args <- getArgs
54           case args of
55             [] -> hGetContents stdin >>= run 2 pStms
56             "-s":fs -> mapM_ (runFile 0 pStms) fs
57             fs -> mapM_ (runFile 2 pStms) fs
58
59
60
61
62