From 159d3835bed9a299c8248c18ca319222f8505f58 Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Wed, 2 Apr 2014 14:40:01 +0100 Subject: [PATCH] Parse hex values. --- README.markdown | 9 +++++---- src/SixtyPical/Parser.hs | 33 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index 05816cb..aecfb07 100644 --- a/README.markdown +++ b/README.markdown @@ -262,11 +262,12 @@ In these, `absolute` must be a `reserve`d or `locate`d address. TODO ---- -* Parse HEX values like $40A3 +* comments * Initial values for reserved, incl. tables +* give length for tables, must be there for reserved * Character tables ("strings" to everybody else) * Work out the analyses again and document them -* `repeat jmp` +* lda wordaddress --> is not legal. use lda wordaddr * Addressing modes; rename instructions to match Tests @@ -441,7 +442,7 @@ We cannot absolute-indexed a word. | routine main { | lda #4 | ldx #0 - | ldy #255 + | ldy #$FF | lda screen | lda screen, x | lda screen, y @@ -530,7 +531,7 @@ We cannot absolute-indexed a word. = score: .word 0 = .alias screen 1024 - | assign word screen 1024 + | assign word screen $0400 | routine main { | lda screen | cmp screen diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 1da3124..0909c7e 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -2,9 +2,12 @@ module SixtyPical.Parser (parseProgram) where -import SixtyPical.Model +import Numeric (readHex) + import Text.ParserCombinators.Parsec +import SixtyPical.Model + {- Toplevel := {Decl} {Routine}. @@ -420,14 +423,34 @@ locationName = do spaces return (c:cs) -address :: Parser Address -address = do +address = hex_address <|> decimal_address + +hex_address :: Parser Address +hex_address = do + char '$' + digits <- many hexDigit + spaces + let ((d, _):_) = readHex digits + return (d :: Address) + +decimal_address :: Parser Address +decimal_address = do digits <- many digit spaces return (read digits :: Address) -data_value :: Parser DataValue -data_value = do +data_value = hex_data_value <|> decimal_data_value + +hex_data_value :: Parser DataValue +hex_data_value = do + char '$' + digits <- many hexDigit + spaces + let ((d, _):_) = readHex digits + return (d :: DataValue) + +decimal_data_value :: Parser DataValue +decimal_data_value = do digits <- many digit spaces return (read digits :: DataValue)