From 2909ad4b7b96a93d04c01135683d4dee6356def2 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 16 Dec 2014 12:32:02 +1100 Subject: Grasp interpreter main program added, still untested --- makefile | 9 +++++++-- src/grasp.hs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/grasp.hs diff --git a/makefile b/makefile index 43c7a44..e9f7a72 100644 --- a/makefile +++ b/makefile @@ -6,13 +6,14 @@ EXECUTABLES = ${OUTPUTDIR}/test \ ${OUTPUTDIR}/fractran \ ${OUTPUTDIR}/thue \ ${OUTPUTDIR}/unlambda \ - ${OUTPUTDIR}/brainfuck + ${OUTPUTDIR}/brainfuck \ + ${OUTPUTDIR}/grasp SWITCHES = -XDeriveDataTypeable -all: testprog fractranprog thueprog unlambdaprog brainfuckprog +all: testprog fractranprog thueprog unlambdaprog brainfuckprog graspprog clean: @@ -43,3 +44,7 @@ unlambdaprog: brainfuckprog: cd ${SOURCEDIR}; \ ghc ${SWITCHES} --make brainfuck.hs -o ../${OUTPUTDIR}/brainfuck + +graspprog: + cd ${SOURCEDIR}; \ + ghc ${SWITCHES} --make grasp.hs -o ../${OUTPUTDIR}/grasp diff --git a/src/grasp.hs b/src/grasp.hs new file mode 100644 index 0000000..4b12abd --- /dev/null +++ b/src/grasp.hs @@ -0,0 +1,30 @@ + +import System.Environment( getArgs ) +import Control.Exception( ErrorCall(..), Handler(..), catches ) +import Grasp.Parser +import Grasp.Interpreter + + + + +usageString :: String +usageString = "Usage: grasp " + + + +program :: IO () +program = do + args <- getArgs + fileContents <- if (length args /= 1) + then error usageString + else readFile (head args) + + case (parseGrasp fileContents) of + Left x -> putStrLn (show x) + Right x -> grasp x >> return () + + + +main = catches program + [ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ] + -- cgit