-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
48 lines (44 loc) · 1.73 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
39
40
41
42
43
44
45
46
47
48
module Main where
import CoreElaboration
import SourceElaboration
import SrcParser
import SyntaxSource
import SystemFSemantics
import Types
import System.Environment
parseAndEval filename = do
putStrLn $ "Source file: " ++ filename
pgmText <- readFile filename
case srcparse pgmText of
Nothing -> putStrLn "Error: syntax error"
Just pgm -> do
putStrLn "#######################################"
putStrLn "# Source Program #"
putStrLn "#######################################"
putStrLn (showPgm pgm)
let pgm' = translateSrcPgm pgm
putStrLn "#######################################"
putStrLn "# Implicit Calculus #"
putStrLn "#######################################"
putStrLn (show pgm')
putStrLn ""
case translate pgm' of
Nothing -> putStrLn "Error: failed to translate into System F"
Just pgm'' -> do
putStrLn "#######################################"
putStrLn "# System F #"
putStrLn "#######################################"
putStrLn (show pgm'')
putStrLn ""
case evalAll pgm'' of
Nothing -> putStrLn "Error: failed to evaluate the resulting System F program"
Just result -> putStrLn ("Evaluation result: " ++ show result)
main = do
putStrLn "#######################################"
putStrLn "# Implicit Calculus Interpreter #"
putStrLn "#######################################"
putStrLn ""
args <- getArgs
if length args < 1
then putStrLn "Error: source file should be given"
else parseAndEval (args !! 0)