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