-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathparse.src
278 lines (278 loc) · 4.89 KB
/
parse.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
.page
.subttl "Parser Utils"
;******************************************************************************
; PARSER UTILS
;******************************************************************************
;
zpage parse_pntr,2
;
; delimit_label_oper
; chops up LINE.
; sets LABEL to point to the label feild string or to a NULL.
; sets OPER to point to operaetor feild
; sets ARGS to point to remander of string ( comment delimited ).
;
;
null_string
.byte 0
;
delimit_label_oper
;
ldi null_string label,oper,args <= null_string
std label
std oper
std args
;
ldi line parse_pntr <= base of line
std parse_pntr
;
jsr 100$ a <= first char
bcs 80$ exit iff comment or EOS
;
jsr isspace if not a space
bcc 20$
;
ldd parse_pntr mark start of label
std label
;
jsr parse_skip_nonwhite advance to first delimiting space
bcs 80$
;
lda #0 terminate label string here
sta (parse_pntr),y
;
jsr parse_advance point to next field
;
20$ jsr parse_skip_white skip_white
jsr 100$ exit iff comment
bcs 80$
;
ldd parse_pntr mark start of oper
std oper
;
jsr parse_skip_nonwhite advance past chars
bcs 80$ exit if end of string
;
lda #0
sta (parse_pntr),y mark end of oper string
;
jsr parse_advance point to next field
;
jsr parse_skip_white skip spaces
jsr 100$ exit iff comment or null
bcs 80$
ldd parse_pntr
std args mark arguement base
;
80$ clc return
rts
;
100$ ldy #0
lda (parse_pntr),y
beq 109$
cmp #';
bne 80$
109$ sec
rts
;
; oper_toupper
; force contents of oper to upper case
;
oper_toupper
ldy #$ff y <= -1
10$ iny do y++
lda (oper),y (oper),y <= toupper( (oper),y )
jsr toupper
sta (oper),y
cmp #0 until null encountered
bne 10$
clc return
rts
;
;
parse_skip_white
10$ lda (parse_pntr),y
beq 90$
jsr isspace
bcc 20$
clc
rts
;
20$ jsr parse_advance
bne 10$
;
90$ sec
rts
;
parse_advance
incd parse_pntr
rts
;
parse_skip_nonwhite
10$ lda (parse_pntr),y
beq 90$
jsr isspace
bcs 20$
clc
rts
20$ jsr parse_advance
bne 10$
;
90$ sec
rts
;
;
;
;
; comma_delimit_args
;
; chops up args string based on quotes and
; commas. leaves args string as seris of
; null terminated strings in args field.
; sets NARGS to number of args found.
;
comma_delimit_args
;
ldy #0 y <= 0
sty nargs nargs <= 0
;
10$ lda (args),y while not at EOS
beq 80$
cmp #';
beq 80$
jsr isspace
bcc 80$
;
20$ inc nargs do inc nargs
;
dey y--
;
30$ iny do get next char
33$ lda (args),y
beq 80$ exit iff EOS
jsr isspace if space
bcc 80$ exit ( no more args )
cmp #'; if semicolon
bne 40$
;
jsr 80$ terminate arg
jmp outerr_q output Q error, exit
;
40$ cmp #'' if dreaded single quote
bne 70$
;
ldd args find range
jsr range_of_single_quote ignore errors
dey back up a char
jmp 30$ loop
;
70$ eor #', until a comma
bne 30$
sta (args),y mark comma with null
iny point to next byte
jmp 10$ forever
;
80$ lda #0 mark exit char w/ null ( semi colon ? )
sta (args),y
rts
;
;
;
; delimit_single_arg
; delimits ARG for a single numeric value
; recognizes the following chars as universal delimiters:
; space,tab
; passes any commas or other punctation.
; implementes the single quote weirdness.
;
delimit_single_arg
ldy #0
sty nargs
;
lda (args),y if first char is null or space or ;
beq 90$
cmp #';
beq 90$
jsr isspace
bcs 10$
90$ sec return un happy ( args is 0 )
rts
;
10$ inc nargs nargs <= 1
;
20$ lda (args),y do if yth char is null
beq 80$ go exit hapopy
cmp #'; if yth char is ;
bne 30$
jsr 80$ terminate at ;
jsr outerr_q issue 'q error
clc return happy
rts
;
30$ jsr isspace if char is white
bcc 80$ go terminate and return happy
;
cmp #'' if its a quote (ARG!!)
bne 40$
ldd args find how many chars are invovled
jsr range_of_single_quote
jmp 20$ else
40$ iny point to next char
jmp 20$
;
80$ lda #0
sta (args),y
clc
rts
;
;
;
; range of single_quote
; this weird routine is called when a single quote is
; encountered in the args list stream.
;
; entry: (x,a),y points to single quote
; exit: parse_pntr destroyed
; x,a destroyed
; (oldx,a),y pointer to end of quoted thingie.
; c=1 y=0 routine misscalled
; c=1 y<>0 syntactical problem,
; y points to next bit
; c=0 y points to next bit
;
;
range_of_single_quote
std parse_pntr
lda (parse_pntr),y if yth char is not a
cmp #''
bne 90$ go return 0 chars un happy
;
iny if char 1 is null
lda (parse_pntr),y
beq 90$ go return 1 char, un happy
cmp #'' if char 1 is single quote
beq 70$ go return 2, happy
;
iny
lda (parse_pntr),y if char 3 is null
beq 80$ go return 2,happy
;
cmp #'' if char 3 is single quote
beq 70$ go return 3,happy
;
iny
lda (parse_pntr),y if char 4 is single quote
cmp #''
beq 70$ go return 4,happy
;
dey prepare to return 2 chars
lda (parse_pntr),y
jmp isspace return happy iff char 2 is white
;
70$ iny
80$ clc
rts
;
90$ sec
rts
;