-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascaltoLoop.hs
More file actions
26 lines (23 loc) · 830 Bytes
/
PascaltoLoop.hs
File metadata and controls
26 lines (23 loc) · 830 Bytes
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
import System.IO
import System.Environment
import RPtoLoop
import qualified ReducedPascal as P
-- Main logic from pascal input file to loop file
main :: IO ()
main = do
args <- getArgs
-- parse arguments
case args of
[] -> usage
("-o":[]) -> usage
("-o":outf:[]) -> usage
("-o":outf:inf:rest) -> run inf outf
(inf:rest) -> run inf (takeWhile (/='.') inf ++ ".loop")
where
usage = putStrLn ("Usage :\n\t plt [-o outputfile] inputfile")
-- read input file -> compile it -> if successfull write it to output file
run inf outf = do
inp <- P.parseProgram (readFile inf)
case inp of
Left p -> writeFile outf $ show $ fst (runCalculation (programCalc p) 0)
Right r -> putStrLn $ show r