git @ Cat's Eye Technologies SixtyPical / 962f2ad
Baby steps. Cat's Eye Technologies 7 years ago
2 changed file(s) with 6 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
2121 | nop
2222 | }
2323 ? missing 'main' routine
24
25 A comment may appear at the start of a block.
26
27 | routine main {
28 | ; this program does nothing
29 | nop
30 | }
31 = True
3224
3325 A comment may appear after each command.
3426
3434
3535 -}
3636
37 nspaces = many (oneOf " \t")
37 nspaces :: Parser [Char]
38 nspaces = do
39 many (char ' ' <|> char '\t')
3840
3941 toplevel :: Parser Program
4042 toplevel = do
4547 decl :: Parser Decl
4648 decl = do
4749 d <- (try assign <|> try reserve <|> try external)
48 optional comment
50 optional_comment_before_eol
4951 return d
5052
5153 reserve :: Parser Decl
9799 block = do
98100 string "{"
99101 spaces
100 optional comment
101102 cs <- many commented_command
102103 string "}"
103104 spaces
104105 return cs
105106
106 optional_comment = do
107 optional_comment_before_eol = do
107108 optional comment
108 nspaces
109109
110110 comment :: Parser ()
111111 comment = do
112112 string ";"
113113 manyTill anyChar (try (string "\n"))
114114 spaces
115 return ()
116115
117116 -- -- -- -- -- -- commands -- -- -- -- --
118117
185184 commented_command :: Parser Instruction
186185 commented_command = do
187186 c <- command
188 optional comment
187 optional_comment_before_eol
189188 return c
190189
191190 command :: Parser Instruction