comparison src/parse.s @ 140:86f6f3a71e60 default tip

Fix some bugs in tokenization/parsing routine
author William Astle <lost@l-w.ca>
date Tue, 16 Jul 2024 22:30:07 -0600
parents 5d4801c0566d
children
comparison
equal deleted inserted replaced
139:5d4801c0566d 140:86f6f3a71e60
20 ; The stuff below that has hard coded colon checks will eventually be replaced by more complete parsing. 20 ; The stuff below that has hard coded colon checks will eventually be replaced by more complete parsing.
21 parse ldu freestart ; default to the start of free memory for encoding 21 parse ldu freestart ; default to the start of free memory for encoding
22 leay -stackheadroom,s ; set the top of free memory 22 leay -stackheadroom,s ; set the top of free memory
23 parseto lda #1 ; flag to enable memory limit detection 23 parseto lda #1 ; flag to enable memory limit detection
24 pshs a,u,y ; save start and end addresses and OM error detection flag 24 pshs a,u,y ; save start and end addresses and OM error detection flag
25 leay ,x ; put the input pointer somewhere less useful 25 leay -1,x ; put the input pointer somewhere less useful and back up one spot
26 parsea jsr parse_curchar ; fetch an input character 26 parsea jsr parse_nextchar ; fetch an input character
27 bne parseb ; brif not end of input 27 bne parseb ; brif not end of input
28 parsez tfr u,d ; get current output pointer 28 parsez tfr u,d ; get current output pointer
29 subd 3,s ; now D is the length 29 subd 3,s ; now D is the length
30 leas 5,s ; clean up the stack 30 leas 5,s ; clean up the stack
31 rts ; return - C will be clear from subd above 31 rts ; return - C will be clear from subd above
63 bne parsek ; brif so 63 bne parsek ; brif so
64 leay -1,y ; unconsume it 64 leay -1,y ; unconsume it
65 bra parsea ; we're done with DATA 65 bra parsea ; we're done with DATA
66 parsek bsr parseout ; put the data value into the output 66 parsek bsr parseout ; put the data value into the output
67 bra parsei ; go handle another character 67 bra parsei ; go handle another character
68 parsec cmpb #'" ; did we encounter a quoted string? 68 parsec ldb ,y ; get back the current input in the right register
69 cmpb #'" ; did we encounter a quoted string?
69 bne parsel ; brif not 70 bne parsel ; brif not
70 bsr parseout ; output delimiter 71 bsr parseout ; output delimiter
71 parsem ldb ,y+ ; get string character 72 parsem leay 1,y ; move to next input character
73 ldb ,y ; get string character
72 beq parsez ; brif end of input 74 beq parsez ; brif end of input
73 bsr parseout ; output it 75 bsr parseout ; output it
74 cmpb #'" ; end delimiter? 76 cmpb #'" ; end delimiter?
75 bne parsem ; brif not - keep looking 77 bne parsem ; brif not - keep looking
76 bra parsea ; go handle more stuff 78 bra parsea ; go handle more stuff
85 cmpb #'a ; is it a lower case letter? 87 cmpb #'a ; is it a lower case letter?
86 blo parsen ; brif not 88 blo parsen ; brif not
87 cmpb #'z ; is it still a lower case letter? 89 cmpb #'z ; is it still a lower case letter?
88 bhi parsen ; brif not 90 bhi parsen ; brif not
89 parseo bsr parseout ; stash the character 91 parseo bsr parseout ; stash the character
90 ldb ,y+ ; fetch next input 92 leay 1,y ; move to next character
91 beq parsez ; brif end of input 93 ldb ,y ; fetch next input
92 bra parsep ; go see if we're still in an identifier 94 bne parsep ; brif not end of input
95 jmp parsez ; go handle end of input
93 parsen bsr parseout ; output unknown character (number, unknown token) 96 parsen bsr parseout ; output unknown character (number, unknown token)
94 jmp parsea ; go handle more 97 jmp parsea ; go handle more
95 parseoutw exg a,b ; do MSB 98 parseoutw exg a,b ; do MSB
96 bsr parseout 99 bsr parseout
97 exg a,b ; and then LSB (fall through) 100 exg a,b ; and then LSB (fall through)
102 coma ; set C for error 105 coma ; set C for error
103 leas 7,s ; clean up stack 106 leas 7,s ; clean up stack
104 rts ; return to original caller 107 rts ; return to original caller
105 parseout0 stb ,u+ ; stash in buffer 108 parseout0 stb ,u+ ; stash in buffer
106 rts 109 rts
107 parse_nextchar lda ,y ; at end of input already? 110 parse_nextchar leay 1,y ; move to next input character
108 beq parse_curchar ; brif so
109 leay 1,y ; move to next input character
110 parse_curchar lda ,y ; fetch input character 111 parse_curchar lda ,y ; fetch input character
111 rts 112 rts
112 parse_nextcharu bsr parse_nextchar ; fetch next input character 113 parse_nextcharu bsr parse_nextchar ; fetch next input character
113 beq parse_toupper0 ; brif end of input 114 beq parse_toupper0 ; brif end of input
114 parse_toupper cmpa #'a ; is it lower case alpha? 115 parse_toupper cmpa #'a ; is it lower case alpha?