git @ Cat's Eye Technologies SixtyPical / b4eb0b0
Three passing tests! Cat's Eye Technologies 8 years ago
3 changed file(s) with 49 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
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"
00 -- encoding: UTF-8
11
22 module Main where
3 --module Sixtype where
43
54 import qualified Data.Map as Map
65
188187 return cs
189188
190189 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
192197
193198 cmp :: Parser Instruction
194199 cmp = do
236241
237242 -- -- -- -- driver -- -- -- --
238243
244 usage = do
245 putStrLn "Usage: sixtypical (parse|check) filename.60pical"
246 exitWith $ ExitFailure 1
247
239248 main = do
240249 args <- getArgs
241250 case args of
242 [filename] -> do
251 [verb, filename] -> do
243252 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
246255 putStrLn $ show $ program
256 ("check", Right program) -> do
247257 putStrLn $ show $ checkProgram program
248 Left problem -> do
258 (_, Left problem) -> do
249259 hPutStrLn stderr (show problem)
250260 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