-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
26 lines (21 loc) · 827 Bytes
/
Main.hs
File metadata and controls
26 lines (21 loc) · 827 Bytes
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
module Main where
import Lexer
import Parser
import Interpreter
import System.Environment
import System.Directory
main = do args <- getArgs
interpret args
interpret :: [String] -> IO ()
interpret [] = error "Missing argument: Source file\n Usage: myinterpreter <filename>.cql"
interpret [p] = do b <- doesFileExist p
interpret' p b
interpret _ = error "Too many arguments, Expected: 1\n Usage: myinterpreter <filename>.cql"
interpret' :: String -> Bool -> IO ()
interpret' p b | b = do text <- readFile p
errorHandle (parseCalc (alexScanTokens text))
| otherwise = error ("Source file does not exist: " ++ p)
errorHandle :: E Prog -> IO ()
errorHandle (Ok t) = do result <- eval t
putStrLn result
errorHandle (Failed s) = error s