-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
38 lines (32 loc) · 1.16 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import System.Console.GetOpt
import System.Environment(getArgs, getProgName)
import PTEstruturado.Interpreter
import PTEstruturado.Parse
data Flag
= Source String
| JustParse
| ShowMemory
deriving Show
options :: [OptDescr Flag]
options =
[ Option ['P'] ["just-parse" ] (NoArg JustParse ) "no exec, Just parse and print result"
, Option ['M'] ["show-memory"] (NoArg ShowMemory ) "print variables in the end of execution"
]
compilerOpts :: String -> [String] -> IO ([Flag], [String])
compilerOpts name argv =
case getOpt Permute options argv of
(o,n,[] )
| not (null n) -> return (o,n)
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
where header = "Usage: "++name++" [OPTION] file"
main = do
args <- getArgs
name <- getProgName
opts <- compilerOpts name args
case opts of
([] , file:_) -> runfile file >> return ()
([JustParse] , file:_) -> parseFile file >>= print
([ShowMemory] , file:_) -> do
(_, state) <- runfile file
putStrLn "----------------------------------------------------"
mapM_ print $ state