Three passing tests!
Cat's Eye Technologies
8 years ago
|
0 |
SixtyPical
|
|
1 |
==========
|
|
2 |
|
|
3 |
-> Tests for functionality "Parse SixtyPical program"
|
|
4 |
|
|
5 |
-> Functionality "Parse SixtyPical program" is implemented by
|
|
6 |
-> shell command "bin/sixtypical parse %(test-file)"
|
|
7 |
|
|
8 |
| routine main {
|
|
9 |
| nop
|
|
10 |
| }
|
|
11 |
= Program [] [Routine "main" [NOP]]
|
|
12 |
|
|
13 |
| reserve word score
|
|
14 |
| assign word scram 4000
|
|
15 |
| routine main {
|
|
16 |
| lda scram
|
|
17 |
| cmp score
|
|
18 |
| }
|
|
19 |
= Program [Reserve "score" Word,Assign "scram" Word 4000] [Routine "main" [LOAD A "scram",CMP A "score"]]
|
|
20 |
|
|
21 |
All declarations (`reserve`s and `assign`s) must come before any `routines`.
|
|
22 |
|
|
23 |
| routine main {
|
|
24 |
| lda scram
|
|
25 |
| }
|
|
26 |
| reserve word score
|
|
27 |
? expecting "routine"
|
0 | 0 |
-- encoding: UTF-8
|
1 | 1 |
|
2 | 2 |
module Main where
|
3 | |
--module Sixtype where
|
4 | 3 |
|
5 | 4 |
import qualified Data.Map as Map
|
6 | 5 |
|
|
188 | 187 |
return cs
|
189 | 188 |
|
190 | 189 |
command :: Parser Instruction
|
191 | |
command = cmp <|> lda <|> beq
|
|
190 |
command = cmp <|> lda <|> beq <|> nop
|
|
191 |
|
|
192 |
nop :: Parser Instruction
|
|
193 |
nop = do
|
|
194 |
string "nop"
|
|
195 |
spaces
|
|
196 |
return NOP
|
192 | 197 |
|
193 | 198 |
cmp :: Parser Instruction
|
194 | 199 |
cmp = do
|
|
236 | 241 |
|
237 | 242 |
-- -- -- -- driver -- -- -- --
|
238 | 243 |
|
|
244 |
usage = do
|
|
245 |
putStrLn "Usage: sixtypical (parse|check) filename.60pical"
|
|
246 |
exitWith $ ExitFailure 1
|
|
247 |
|
239 | 248 |
main = do
|
240 | 249 |
args <- getArgs
|
241 | 250 |
case args of
|
242 | |
[filename] -> do
|
|
251 |
[verb, filename] -> do
|
243 | 252 |
programText <- readFile filename
|
244 | |
case parse toplevel "" programText of
|
245 | |
Right program -> do
|
|
253 |
case (verb, parse toplevel "" programText) of
|
|
254 |
("parse", Right program) -> do
|
246 | 255 |
putStrLn $ show $ program
|
|
256 |
("check", Right program) -> do
|
247 | 257 |
putStrLn $ show $ checkProgram program
|
248 | |
Left problem -> do
|
|
258 |
(_, Left problem) -> do
|
249 | 259 |
hPutStrLn stderr (show problem)
|
250 | 260 |
exitWith $ ExitFailure 1
|
251 | |
_ -> do
|
252 | |
putStrLn "Usage: sixtypical filename.60pical"
|
253 | |
exitWith $ ExitFailure 1
|
254 | |
|
255 | |
{-
|
256 | |
test = checkProgram [(Routine "wait" [LOAD Y "score", COPY Y A]),
|
257 | |
(Routine "main" [LOAD X "score", JSR "wait"])]
|
258 | |
Map.empty
|
259 | |
-}
|
|
261 |
(_, _) -> usage
|
|
262 |
_ -> usage
|
|
0 |
#!/bin/sh
|
|
1 |
|
|
2 |
./build.sh && falderal --substring-error README.markdown
|