Add common code for CS325 madness

This commit is contained in:
2019-12-27 23:20:18 -08:00
parent c7ce8a3107
commit f74209c970
3 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
module Common where
import PythonAst
import PythonGen
import Text.Parsec
compile :: (String -> String -> Either ParseError p) -> (p -> [PyStmt]) -> String -> IO ()
compile p t f = do
let inputName = f ++ ".lang"
let outputName = f ++ ".py"
file <- readFile inputName
let either = p inputName file
case either of
Right prog -> writeFile outputName (translate $ t prog)
Left e -> print e