lex:
ldx
txa
txy
sty.d ln
sty.q idx0
sty.q idx1
sty.q idx2
sty.d t_id
sty.q t_val
sty.q t_str
sty.q t_sym
sty regb
sty islinenum
@loop:
ldy.w idx0
lda (ptr), y
jsr isdelm
cmp
beq @end
@spaces:
ldy.w idx0
lda (ptr), y
pha
jsr isdelm
and
pla
beq @switch
inc.w idx0
cmp
beq @incs
cmp
beq @inct
bra @spaces
@incs:
inc t_space
bra @spaces
@inct:
inc t_tab
bra @spaces
@switch:
ldy.w idx0
lda (ptr), y
jsr get_ptok
pha
jsr is_altok
pla
bne @is_altok
@parse:
jsr parse_ptok
lda lex_type
cmp
beq @inc_idx
ldy.w idx0
lda (ptr), y
jsr isdelm2
beq @inc_idx
bra @loop
@is_altok:
sta lex_type
iny
cmp
bne @ptok_p
lda (ptr), y
jsr tolower
cmp
bne @ptok_p
bra @inc_offset
@ptok_p:
cmp
bne @is_altok2
lda (ptr), y
jsr tolower
cmp
bne @is_altok2
@inc_offset:
iny
@is_altok2:
lda (ptr), y
jsr get_ptok
cmp
bcc @ptok_num
beq @ptok_num
cmp
bcs @ptok_al
lda lex_type
ldy.w idx0
bra @parse
@ptok_al:
lda
ldy.w idx0
bra @parse
@inc_idx:
inc.w idx0
bra @loop
@end:
jsr update_ptr
tay
and
rts
parse_ptok:
pha
ldb
lda.w
jsr set_ptr
and
pla
phy.w
lsl
tay
lda.w (ptr3), y
jsr set_ptr
and
tab
ply.w
jmp (ptr3)
ptok_dot:
ldb
jsr init_lex
ldb
lda
pha
jsr delmcpy
pla
@isop:
lda regb
beq @dir
@rs:
lda
sta lex_type
sta t_id
ldy.w idx1
dey
lda (ptr3), y
jsr get_rs
bra @end
@dir:
ldb
stb.q idx1
jsr set_lexptr
@dir_loop:
ldb idx1
cpb
beq @end
lda.w
clc
adc.w idx2
pha.q
jsr strcaseg
pla.q
beq @found
inc idx1
@getlen:
mov d, a
jsr strlen
inc
add.w idx2, a
bra @dir_loop
@found:
lda
sta lex_type
sta t_id
lda idx1
sta t_type
@end:
jsr make_tok
jsr set_cmdbuf
rts
ptok_at:
inc.w idx0
rts
ptok_col:
inc.w idx0
rts
ptok_equ:
inc.w idx0
rts
ptok_plus:
lda
bra ptok_expr
ptok_min:
lda
bra ptok_expr
ptok_gt:
lda
bra ptok_expr
ptok_lt:
lda
bra ptok_expr
ptok_pipe:
lda
ptok_expr:
sta t_type
lda
sta t_id
sta lex_type
inc.w idx0
jsr make_tok
jsr set_cmdbuf
rts
ptok_lbrk:
inc.w idx0
rts
ptok_rbrk:
inc.w idx0
rts
ptok_com:
inc.w idx0
rts
ptok_br:
inc.w idx0
rts
ptok_xr:
inc.w idx0
rts
ptok_yr:
inc.w idx0
rts
ptok_sp:
inc.w idx0
rts
ptok_pc:
inc.w idx0
rts
ptok_dqu:
ldb
jsr init_lex
ldb
lda
pha
and
jsr delmcpy
pla
lda
sta lex_type
sta t_id
bra copy_str
ptok_squ:
ldb
jsr init_lex
ldb
lda
pha
and
jsr delmcpy
pla
lda
sta lex_type
sta t_id
bra copy_str
ptok_scol:
ldb
jsr init_lex
ldb
lda
pha
jsr delmcpy
pla
lda
sta lex_type
sta t_id
copy_str:
lea d, (idx1)
inc d
mov f, d
jsr malloc
lea s, (ptr3)
mov d, a
jsr memcpy
sta.q t_str
and
tab
ldy.q idx0
@end:
jsr make_tok
rts
ptok_hash:
inc.w idx0
rts
ptok_dolr:
lda
sta lex_type
sta t_id
lda
ldb
bra ptok_num2
ptok_prcn:
lda
sta lex_type
sta t_id
lda
ldb
bra ptok_num2
ptok_num:
lda
sta lex_type
sta t_id
lda
ldb
ptok_num2:
pha
jsr init_lex
ldb
lda
pha
jsr delmcpy
pla
pla
jsr strtoullg
sta.q t_val
jsr make_tok
jsr set_cmdbuf
rts
ptok_alph:
ldb
jsr init_lex
ldb
lda
pha
tba
jsr delmcpy
pla
lda
sta regb
@isop:
ldb
stb.q idx1
stb.q idx2
jsr set_lexptr
@isop_loop:
ldb idx1
cpb
beq @end
lda.w
clc
adc.w idx2
pha.q
jsr strcaseg
pla.q
beq @found
inc idx1
@offset:
mov d, a
jsr strlen
inc
add.w idx2, a
bra @isop_loop
@found:
lda
sta lex_type
sta t_id
lda.q idx1
sta.q t_val
lda
sta t_type
inc regb
@end:
jsr make_tok
jsr set_cmdbuf
rts
ptok_othr:
inc.w idx0
rts
set_lexptr:
lda.d
jsr set_ptr
and
tab
sta.q idx1
sta.q idx2
rts
set_cmdbuf:
and
tab
lda.q cmd_buf
jsr set_ptr
and
tab
rts
init_lex:
cpb
beq @init
@inc_str:
inc.w idx0
@init:
ldb
jsr set_lexptr
phy.w
tay
@loop:
lda (ptr3), y
beq @end
lda
sta (ptr3), y
iny
bra @loop
@end:
ply.w
rts
delmcpy:
pha
phb
and
pha
@loop:
ldy.w idx0
lda (ptr), y
pha
lda sp+4
pla
bne @isdelm2
jsr isdelm
@delmchk:
and sp+2
beq @copy
@isesc:
lda sp+1
beq @end
bra @copy
@isdelm2:
jsr isdelm2
bra @delmchk
@copy:
lda sp+12
bne @do_isesc
@copy1:
lda (ptr), y
ldy.w idx1
sta (ptr3), y
inc.w idx0
inc.w idx1
bra @loop
@do_isesc:
jsr isesc
sta sp+1
bra @copy1
@end:
pla.w
pla
and
ldy.w idx1
sta (ptr3), y
ldy.w idx0
rts
get_rs:
phb
ldb
plb
jsr tolower
cmp
beq @r1
cmp
beq @r2
cmp
beq @r3
@r0:
lda
rts
@r1:
lda
rts
@r2:
lda
rts
@r3:
lda
rts
make_tok:
nop
@end:
rts