1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-31 16:04:48 +00:00

Assembly helper function for lex scanner ID/keyword match

This commit is contained in:
David Schmenk 2018-03-12 15:21:36 -07:00
parent 76fd2328d9
commit e77aceb4ea
2 changed files with 124 additions and 31 deletions

View File

@ -26,28 +26,24 @@
// fin
// return FALSE
//end
def keymatch
byte i, keypos
word chrptr
keypos = 0
while keywrds[keypos] < tknlen
keypos = keypos + keywrds[keypos] + 2
loop
chrptr = tknptr - 1
while keywrds[keypos] == tknlen
for i = 1 to tknlen
if ^(chrptr + i) <> keywrds[keypos + i]
break
fin
next
if i > tknlen
return keywrds[keypos + keywrds[keypos] + 1]
fin
keypos = keypos + keywrds[keypos] + 2
loop
return ID_TKN
end
//def keymatch
// byte i, keypos
// word chrptr
//
// keypos = 0
// while keywrds[keypos] < tknlen
// keypos = keypos + keywrds[keypos] + 2
// loop
// chrptr = tknptr - 1
// while keywrds[keypos] == tknlen
// i = 1; while i <= tknlen and ^(chrptr + i) == keywrds[keypos + i]; i++; loop
// if i > tknlen
// return keywrds[keypos + keywrds[keypos] + 1]
// fin
// keypos = keypos + keywrds[keypos] + 2
// loop
// return ID_TKN
//end
def scannum
word num
num = 0
@ -84,23 +80,20 @@ def scan
scanptr++
loop
tknptr = scanptr
scanchr = toupper(^scanptr)
scanchr, scanptr, token = scanid(scanptr, @keywrds) //scanchr = toupper(^scanptr)
//
// Scan for token based on first character
//
//if isalpha(scanchr)
if (scanchr >= 'A' and scanchr <= 'Z') or (scanchr == '_')
if token //if isalpha(scanchr)
//
// ID, either variable name or reserved word
//
repeat
^scanptr = scanchr
scanptr++
scanchr = toupper(^scanptr)
//repeat
// ^scanptr = scanchr
// scanptr++
// scanchr = toupper(^scanptr)
//until not isalphanum(scanchr)
until not ((scanchr >= 'A' and scanchr <= 'Z') or (scanchr >= '0' and scanchr <= '9' ) or (scanchr == '_'))
tknlen = scanptr - tknptr
token = keymatch
elsif scanchr >= '0' and scanchr <= '9' // isnum()
//
// Decimal constant

View File

@ -342,6 +342,106 @@ const ERR_SYNTAX = $8000
//
//=====================================
//
// Lexical scanner helper for keyword/IDs
//
asm scanid(scanptr, keywrds)#3
!SOURCE "vmsrc/plvmzp.inc"
LDA ESTKL,X
STA DSTL
LDA ESTKH,X
STA DSTH
LDA ESTKL+1,X
STA ESTKL,X ; COPY OUTPUT SCANPTR
STA SRCL
LDA ESTKH+1,X
STA ESTKH,X
STA SRCH
DEX
LDA #$00
STA ESTKL,X ; CLEAR OUTPUT TOKEN
STA ESTKH,X
STA ESTKH+2,X ; CLEAR MSB OF SCANCHR
TAY
LDA (SRC),Y
AND #$7F
CMP #'a'
BCC +
CMP #'z'+1
BCS +
SBC #$1F
STA (SRC),Y
+ STA ESTKL+2,X ; SET SCANCHR
CMP #'_'
BEQ +
CMP #'A'
BCC SCANEX
CMP #'Z'+1
BCS SCANEX
+ LDA #$D6 ; ID_TKN
STA ESTKL,X ; SET OUTPUT TOKEN = ID_TKN
SCANID INY
LDA (SRC),Y
AND #$7F
BEQ ++
CMP #'a'
BCC +
CMP #'z'+1
BCS ++
SBC #$1F
STA (SRC),Y ; COPY UPPERCASE CHAR BACK TO ^SCANPTR
BNE SCANID
+ CMP #'_'
BEQ SCANID
CMP #'0'
BCC ++
CMP #'9'+1
BCC SCANID
CMP #'A'
BCC ++
CMP #'Z'+1
BCC SCANID
++ STY TMPL
TYA
LDY #$00
CLC
ADC SRCL
STA ESTKL+1,X ; UPDATE SCANPTR
BCC MATCHLEN
INC ESTKH+1,X
MATCHLEN LDA (DST),Y
CMP TMPL
BCS +
ADC #$02
ADC DSTL
STA DSTL
BCC MATCHLEN
INC DSTH
BNE MATCHLEN
+ BNE SCANEX ; NO KEY MATCH
TAY
DEY
INC DSTL
BNE MATCHKEY
INC DSTH
MATCHKEY LDA (SRC),Y
CMP (DST),Y
BNE NEXTKEY
DEY
BPL MATCHKEY
LDY TMPL
LDA (DST),Y
STA ESTKL,X ; SET OUTPUT TOKEN
SCANEX RTS
NEXTKEY LDY #$00
LDA TMPL
SEC
ADC DSTL
STA DSTL
BCC MATCHLEN
INC DSTH
BNE MATCHLEN
end
//
// Handy functions
//