summaryrefslogtreecommitdiff
path: root/compiler.hs
blob: 2611a5f1bc65420e7c9761185125a31b4fa7cab3 (plain)
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.Environment
import System.IO
import Text.CTPL

comp :: String -> CCConfig -> IO ()
comp str cfg =
  case compileCTPL str cfg of
    Succ a -> putStrLn a
    NoSuchProc nm ->
      hPutStrLn stderr ("Error: No such procedure \""++nm++"\".")
    SyntaxFault ->
      hPutStrLn stderr "Error: Syntax fault."

main = do
  args <- getArgs
  case args of
    ["--old"] -> do
      str <- getContents
      comp str oldConfig
    ["--new"] -> do
      str <- getContents
      comp str newConfig
    ["--old", f] -> do
      str <- readFile f
      comp str oldConfig
    ["--new", f] -> do
      str <- readFile f
      comp str newConfig
    ["--help"] -> do
      putStrLn "ctplc 0.1"
      putStrLn "-------------"
      putStrLn "A compiler for CTPL."
      putStrLn "Synapsis:"
      putStrLn "  ctplc --old [<program-file>]"
      putStrLn "      Compiles the given file (or stdin) for the old (and new) VM."
      putStrLn "  ctplc --new [<program-file>]"
      putStrLn "      Compiles the given file (or stdin) for the new VM only."
    _ -> hPutStrLn stderr "Don't know what to do. See --help for help."