Allow digits in label names
Also, only allow a-zA-Z as the first character of label names.
This commit is contained in:
parent
6ac5bfc9e7
commit
5e9c50d618
3 changed files with 9 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
IAR = technique-a
|
IAR = technique-1
|
||||||
|
|
||||||
; This file demonstrates a few techniques for jumping to an address
|
; This file demonstrates a few techniques for jumping to an address
|
||||||
; stored in the ACC.
|
; stored in the ACC.
|
||||||
|
|
@ -9,15 +9,15 @@ tmp: LIT 0
|
||||||
|
|
||||||
; Jumping by setting the RA and then returning
|
; Jumping by setting the RA and then returning
|
||||||
100:
|
100:
|
||||||
technique-a:
|
technique-1:
|
||||||
LDC technique-b
|
LDC technique-2
|
||||||
STRA
|
STRA
|
||||||
RET
|
RET
|
||||||
|
|
||||||
; Jumping by writing a JMP instruction to a memory location and then
|
; Jumping by writing a JMP instruction to a memory location and then
|
||||||
; jumping to that (aka. almost self-modifying code)
|
; jumping to that (aka. almost self-modifying code)
|
||||||
200:
|
200:
|
||||||
technique-b:
|
technique-2:
|
||||||
LDC end
|
LDC end
|
||||||
OR jump-instruction
|
OR jump-instruction
|
||||||
STV tmp
|
STV tmp
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,8 @@ incrementCurrentPos = do
|
||||||
put s{sCurrentPos = succ $ sCurrentPos s}
|
put s{sCurrentPos = succ $ sCurrentPos s}
|
||||||
|
|
||||||
parseInstructions' :: SParser ()
|
parseInstructions' :: SParser ()
|
||||||
parseInstructions' = sepBy parseInstruction' incrementCurrentPos >> lift (eof <|> fail atMaxAddress)
|
parseInstructions' = sepBy parseInstruction' incrementCurrentPos >> lift eof
|
||||||
where
|
where
|
||||||
atMaxAddress = "already at maximum address (" ++ show (maxBound :: MimaAddress)
|
|
||||||
++ ") - can't go any further"
|
|
||||||
|
|
||||||
parseInstruction' :: SParser ()
|
parseInstruction' :: SParser ()
|
||||||
parseInstruction' = do
|
parseInstruction' = do
|
||||||
s <- get
|
s <- get
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ module Mima.Assembler.Parser.Label
|
||||||
, resolveAddress
|
, resolveAddress
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.Char
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
|
|
@ -33,8 +34,10 @@ mimaLabel = lexeme mimaLabel'
|
||||||
|
|
||||||
mimaLabel' :: Parser MimaLabel
|
mimaLabel' :: Parser MimaLabel
|
||||||
mimaLabel' = label "label" $ do
|
mimaLabel' = label "label" $ do
|
||||||
name <- takeWhile1P Nothing (\c -> isAlphabet c || isConnecting c)
|
firstChar <- satisfy isAlphabet
|
||||||
|
otherChars <- takeWhileP Nothing (\c -> isAlphabet c || isConnecting c || isDigit c)
|
||||||
offset <- getOffset
|
offset <- getOffset
|
||||||
|
let name = T.singleton firstChar <> otherChars
|
||||||
pure MimaLabel{lName = name, lOffset = offset}
|
pure MimaLabel{lName = name, lOffset = offset}
|
||||||
|
|
||||||
failAtLabel :: MimaLabel -> String -> Parser a
|
failAtLabel :: MimaLabel -> String -> Parser a
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue