]> ruin.nu Git - proglang.git/blob - Interpreter.hs
minor stuff
[proglang.git] / Interpreter.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 Interpret
16 import Control.Monad.State
17 import Data.Map as Map hiding (showTree)
18
19 import ErrM
20
21 type ParseFun a = [Token] -> Err a
22
23 myLLexer = myLexer
24
25 type Verbosity = Int
26
27 putStrV :: Verbosity -> String -> IO ()
28 putStrV v s = if v > 1 then putStrLn s else return ()
29
30 runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
31 runFile v p f = putStrLn f >> readFile f >>= run v p
32
33 run :: Verbosity -> ParseFun Stms -> String -> IO ()
34 run v p s = let ts = myLLexer s in case p ts of
35         Bad s    -> do
36                 putStrLn "\nParse              Failed...\n"
37                 putStrV v "Tokens:"
38                 putStrV v $ show ts
39                 putStrLn s
40         Ok (Program s) -> do
41                 --putStrLn "\nParse Successful!"
42                 --showTree v (Program s)
43                 typeCheck s
44                 --print "The program is type-correct!!"
45                 --print "Running program:"
46                 interpret s
47                 --print "Done running program!"
48
49 showTree :: (Show a, Print a) => Int -> a -> IO ()
50 showTree v tree
51  = do
52       putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
53       putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
54
55 main :: IO ()
56 main = do args <- getArgs
57           case args of
58             [] -> hGetContents stdin >>= run 2 pStms
59             "-s":fs -> mapM_ (runFile 0 pStms) fs
60             fs -> mapM_ (runFile 2 pStms) fs
61
62
63
64
65