-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeval.hs
37 lines (30 loc) · 942 Bytes
/
feval.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
import System.Environment
import Control.Applicative
import Control.Monad
import FVL.Parser
import FVL.EF
parseTranslateShow :: String -> Either ParseError String
parseTranslateShow s = case parseString s of
Left e -> Left e
Right e -> Right $ showTranslation e
showResult :: Either ParseError Result -> String
showResult (Right (Result (e, t))) = " => " ++ show e ++ "\n : " ++ show t
showResult (Right TypeMismatch) = "Error: Type Mismatch"
showResult (Right InconsistentTypes) = "Error: Inconsistent Types"
showResult (Left e) = "Error: " ++ show e
getLines :: IO ()
getLines = do
l <- getLine
if l == "\EOT" then return () else do
putStrLn . showResult $ parseRun l
getLines
return ()
getFileLines :: FilePath -> IO ()
getFileLines p = do
r <- parseFileRun p
putStrLn $ showResult r
main = do
a <- getArgs
case a of
[] -> getLines
(p:_) -> getFileLines p