1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-22 17:32:01 +00:00

Allow comments.

This commit is contained in:
Cat's Eye Technologies 2014-04-02 17:10:21 +01:00
parent 159d3835be
commit 1cf166f0db
2 changed files with 35 additions and 3 deletions

View File

@ -262,7 +262,6 @@ In these, `absolute` must be a `reserve`d or `locate`d address.
TODO
----
* comments
* Initial values for reserved, incl. tables
* give length for tables, must be there for reserved
* Character tables ("strings" to everybody else)
@ -295,6 +294,25 @@ Tests
| }
? missing 'main' routine
A comment may appear at the start of a block.
| routine main {
| ; this program does nothing
| nop
| }
= True
A comment may appear after each command.
| routine main {
| lda #1 ; we assemble the fnord using
| ldx #1 ; multiple lorem ipsums which
| ldy #1
| lda #1 ; we
| ldx #1 ; found under the bridge by the old mill yesterday
| }
= True
A program may `reserve` and `assign`.
| reserve byte lives

View File

@ -16,7 +16,7 @@ Decl := "reserve" StorageType LocationName
| "external" RoutineName Address.
StorageType := "byte" | "word" | "vector".
Routine := "routine" RoutineName Block.
Block := "{" {Command} "}".
Block := "{" [Comment] {Command [Comment]} "}".
Command := "if" Branch Block "else" Block
| "lda" (LocationName | Immediate)
| "ldx" (LocationName | Immediate)
@ -90,11 +90,19 @@ block :: Parser [Instruction]
block = do
string "{"
spaces
cs <- many command
optional comment
cs <- many commented_command
string "}"
spaces
return cs
comment :: Parser ()
comment = do
string ";"
manyTill anyChar (try (string "\n"))
spaces
return ()
-- -- -- -- -- -- commands -- -- -- -- --
immediate :: (DataValue -> Instruction) -> Parser Instruction
@ -124,6 +132,12 @@ absolute_indexed f = do
indexes <- many index
return $ f l indexes
commented_command :: Parser Instruction
commented_command = do
c <- command
optional comment
return c
command :: Parser Instruction
command = (try lda) <|>
(try ldx) <|> (try ldy) <|>