summaryrefslogtreecommitdiff
path: root/compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.hs')
-rw-r--r--compiler.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/compiler.hs b/compiler.hs
new file mode 100644
index 0000000..2611a5f
--- /dev/null
+++ b/compiler.hs
@@ -0,0 +1,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."