git @ Cat's Eye Technologies PL-GOTO.NET / 67e4164
Always read text from files as UTF-8. Cat's Eye Technologies 8 years ago
2 changed file(s) with 19 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2626
2727 > module PLexceptGOTOdotNET where
2828
29 > import System.IO
2930 > import Text.ParserCombinators.Parsec
3031 > import qualified Data.Map as Map
3132
149150
150151 Drivers for the parser.
151152
153 > workOnFile fn fileName = do
154 > handle <- openFile fileName ReadMode
155 > hSetEncoding handle utf8
156 > contents <- hGetContents handle
157 > outputText <- return $ fn contents
158 > putStrLn outputText
159
152160 > pa s = case parse program "" s of
153161 > Left perr -> show perr
154162 > Right prog -> show prog
155163
156 > parseFile fileName = do
157 > programText <- readFile fileName
158 > outputText <- return $ pa programText
159 > putStrLn outputText
164 > parseFile = workOnFile pa
160165
161166 Environments
162167 ------------
212217 > Left perr -> show perr
213218 > Right prog -> show $ toList $ eval empty prog
214219
215 > runFile fileName = do
216 > programText <- readFile fileName
217 > outputText <- return $ run programText
218 > putStrLn outputText
220 > runFile = workOnFile run
219221
220222 Static Analyzer
221223 ---------------
245247 > in
246248 > ((x':xs'), id'')
247249
248 Helper function for the test suite.
249
250 > testLoopLabeling s = case parse program "" s of
250 Helper functions for the test suite.
251
252 > loopLabel s = case parse program "" s of
251253 > Left perr -> show perr
252254 > Right prog -> show (labelLoops prog 0)
255
256 > loopLabelFile = workOnFile loopLabel
253257
254258 Gather all variables used in the program. This includes internal variables
255259 to be used as loop counters. This assumes loops have already been labeled.
385389 > Left perr -> show perr
386390 > Right prog -> translate prog
387391
388 > compileFile fileName = do
389 > programText <- readFile fileName
390 > outputText <- return $ compile programText
391 > putStrLn outputText
392 > compileFile = workOnFile compile
1111
1212 -> Functionality "Parse PL-{GOTO} Program" is implemented by
1313 -> shell command
14 -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.pa c" PLexceptGOTOdotNET.lhs"
14 -> "ghc PLexceptGOTOdotNET.lhs -e "workOnFile pa \"%(test-file)\"""
1515
1616 | n ← 0;
1717 = Block [AssignZero "n"]
4646
4747 -> Functionality "Evaluate PL-{GOTO} Program" is implemented by
4848 -> shell command
49 -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.run c" PLexceptGOTOdotNET.lhs"
49 -> "ghc PLexceptGOTOdotNET.lhs -e "runFile \"%(test-file)\"""
5050
5151 | n ← 0;
5252 = [("n",0)]
8888
8989 -> Functionality "Label PL-{GOTO} Loops" is implemented by
9090 -> shell command
91 -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.testLoopLabeling c" PLexceptGOTOdotNET.lhs"
91 -> "ghc PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
9292
9393 | n ← 0; m ← 0; LOOP n;
9494 | LOOP m;