git @ Cat's Eye Technologies ZOWIE / e7ef859
Add beginnings of parser. Chris Pressey 1 year, 22 days ago
3 changed file(s) with 33 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5252 Nothing ->
5353 return state
5454
55 loadAndRun s =
56 let
57 prog = [Mov (Direct 0) (Immediate 0)] -- TODO parse s
58 state = initState prog
59 in
60 run state
55 loadAndRun prog = run (initState prog)
0 module Language.ZOWIE.Parser where
1
2 import Language.ZOWIE.State
3
4
5 splitLines :: String -> String -> [String]
6 splitLines [] line = [reverse line]
7 splitLines ('\n':rest) line = [reverse line] ++ (splitLines rest [])
8 splitLines (char:rest) line = splitLines rest (char:line)
9
10 parseLines [] = []
11 parseLines (line:lines) =
12 case parseLine line of
13 Just instr ->
14 (instr:parseLines lines)
15 Nothing ->
16 parseLines lines
17
18 parseLine [] = Nothing
19 parseLine (' ':rest) = parseLine rest
20 parseLine ('M':'O':'V':rest) = Just $ Mov (Direct 0) (Immediate 0)
21
22
23 parseZOWIE text =
24 let
25 lines = splitLines text []
26 prog = parseLines lines
27 in
28 prog
33 import System.Exit
44 import System.IO
55
6 import qualified Language.ZOWIE.Parser as Parser
67 import qualified Language.ZOWIE.Machine as Machine
78
89
1112 case args of
1213 ["run", fileName] -> do
1314 text <- readFile fileName
14 result <- Machine.loadAndRun text
15 let prog = Parser.parseZOWIE text
16 result <- Machine.loadAndRun prog
1517 putStrLn $ show $ result
1618 return ()
1719 _ -> do