2025-02-02 17:58:16 -05:00
|
|
|
%sp { #2018 DEO }
|
|
|
|
%nl { #0a18 DEO }
|
2022-01-30 19:13:39 -05:00
|
|
|
|
|
|
|
|0100
|
2025-02-02 17:58:16 -05:00
|
|
|
;expr1 compile #010e DEO nl
|
|
|
|
emit-stack nl
|
|
|
|
emit-arena nl
|
|
|
|
|
|
|
|
LIT "= emit sp
|
|
|
|
#01 emit-bool sp
|
|
|
|
#01 emit-bool sp
|
|
|
|
#00 emit-bool sp
|
|
|
|
#01 emit-bool sp
|
|
|
|
#01 emit-bool sp
|
|
|
|
#00 emit-bool sp
|
|
|
|
#00 emit-bool sp
|
|
|
|
#00 emit-bool nl
|
|
|
|
|
|
|
|
LIT "A emit sp
|
|
|
|
;test1 OVR2k rx-match emit-bool sp
|
|
|
|
;test2 OVR2k rx-match emit-bool sp
|
|
|
|
;test3 OVR2k rx-match emit-bool sp
|
|
|
|
;test4 OVR2k rx-match emit-bool sp
|
|
|
|
;test5 OVR2k rx-match emit-bool sp
|
|
|
|
;test6 OVR2k rx-match emit-bool sp
|
|
|
|
;test7 OVR2k rx-match emit-bool sp
|
|
|
|
;test8 OVR2k rx-match emit-bool nl
|
|
|
|
|
|
|
|
LIT "B emit sp
|
|
|
|
;test1 ;graph1 rx-match emit-bool sp
|
|
|
|
;test2 ;graph1 rx-match emit-bool sp
|
|
|
|
;test3 ;graph1 rx-match emit-bool sp
|
|
|
|
;test4 ;graph1 rx-match emit-bool sp
|
|
|
|
;test5 ;graph1 rx-match emit-bool sp
|
|
|
|
;test6 ;graph1 rx-match emit-bool sp
|
|
|
|
;test7 ;graph1 rx-match emit-bool sp
|
|
|
|
;test8 ;graph1 rx-match emit-bool nl
|
|
|
|
|
|
|
|
reset-arena
|
|
|
|
#010f DEO BRK
|
2022-01-30 19:13:39 -05:00
|
|
|
|
|
|
|
( corresponds to regex: a(b|c)d* )
|
|
|
|
@expr1 "a(b|c)d* 00
|
|
|
|
|
|
|
|
( corresponds to regex: a(b|c)d* )
|
|
|
|
( accepts "ab" or "ac" followd by any number of d's )
|
|
|
|
@graph1
|
2025-02-02 17:58:16 -05:00
|
|
|
03 "a =x1
|
|
|
|
@x1 04 =x2 =x3
|
|
|
|
@x2 03 "b =x4
|
|
|
|
@x3 03 "c =x4
|
|
|
|
@x4 05 =x5 0000
|
|
|
|
@x5 03 "d =x4
|
2022-01-30 19:13:39 -05:00
|
|
|
|
|
|
|
( test case strings to try matching )
|
|
|
|
@test1 "ab 00 ( yes )
|
|
|
|
@test2 "acdd 00 ( yes )
|
|
|
|
@test3 "add 00 ( no )
|
|
|
|
@test4 "abd 00 ( yes )
|
|
|
|
@test5 "acddddddddddd 00 ( yes )
|
|
|
|
@test6 "bd 00 ( no )
|
|
|
|
@test7 "z 00 ( no )
|
|
|
|
@test8 00 ( no )
|
|
|
|
|
|
|
|
~regex.tal
|
|
|
|
|
2022-02-20 15:06:57 -05:00
|
|
|
@emit ( c^ -- )
|
2025-02-02 17:58:16 -05:00
|
|
|
#18 DEO JMP2r
|
2022-02-20 15:06:57 -05:00
|
|
|
|
2022-01-30 19:23:44 -05:00
|
|
|
@emit-short ( short* -- )
|
2025-02-02 17:58:16 -05:00
|
|
|
SWP emit-byte emit-byte JMP2r
|
2022-01-30 19:23:44 -05:00
|
|
|
|
|
|
|
@emit-byte ( byte^ -- )
|
2025-02-02 23:46:58 -05:00
|
|
|
DUP #04 SFT ,&hex JSR #0f AND !&hex
|
2022-01-30 19:23:44 -05:00
|
|
|
&hex #30 ADD DUP #39 GTH #27 MUL ADD emit
|
|
|
|
JMP2r
|
|
|
|
|
2022-02-20 15:06:57 -05:00
|
|
|
@emit-bool ( byte^ -- )
|
2025-02-02 17:58:16 -05:00
|
|
|
LIT "0 ADD emit JMP2r
|
2022-02-20 15:06:57 -05:00
|
|
|
|
2022-01-30 19:23:44 -05:00
|
|
|
( print stack size, followed by contents )
|
|
|
|
@emit-stack ( -> )
|
2025-02-02 17:58:16 -05:00
|
|
|
sp LIT "n emit LIT "= emit ;stack-pos LDA2 ;stack-bot SUB2 #0004 DIV2 emit-short LIT ": emit
|
2022-01-30 19:23:44 -05:00
|
|
|
;stack-bot
|
|
|
|
&loop
|
2025-02-02 23:46:58 -05:00
|
|
|
DUP2 ;stack-pos LDA2 LTH2 ?&ok
|
2025-02-02 17:58:16 -05:00
|
|
|
POP2 nl JMP2r
|
2022-01-30 19:23:44 -05:00
|
|
|
&ok
|
2025-02-02 17:58:16 -05:00
|
|
|
sp LDA2k emit-short
|
2025-02-02 23:46:58 -05:00
|
|
|
#0002 ADD2 !&loop
|
2022-01-30 19:23:44 -05:00
|
|
|
|
|
|
|
( emit n bytes from the given address )
|
|
|
|
@emit-n ( addr* count^ -> addr2* )
|
2025-02-02 23:46:58 -05:00
|
|
|
DUP #00 GTH ( addr count count>0? ) ?&ok ( addr count ) POP nl JMP2r
|
2022-01-30 19:23:44 -05:00
|
|
|
&ok
|
2025-02-02 17:58:16 -05:00
|
|
|
STH ( addr [count] ) sp LDAk emit-byte INC2 ( addr+1 [count] )
|
2022-01-30 19:23:44 -05:00
|
|
|
STHr #01 SUB ( addr+1 count-1 )
|
2025-02-02 23:46:58 -05:00
|
|
|
!emit-n
|
2022-01-30 19:23:44 -05:00
|
|
|
|
|
|
|
( emit the arena, with one line per node )
|
|
|
|
( parses node type, since node size is dynamic (3-5). )
|
|
|
|
@emit-arena ( -> )
|
|
|
|
;arena-bot
|
|
|
|
&loop
|
2025-02-02 23:46:58 -05:00
|
|
|
DUP2 ;arena-pos LDA2 LTH2 ?&ok POP2 JMP2r
|
2022-01-30 19:23:44 -05:00
|
|
|
&ok
|
2025-02-02 17:58:16 -05:00
|
|
|
DUP2 emit-short
|
|
|
|
LIT ": emit sp
|
2025-02-02 23:46:58 -05:00
|
|
|
LDAk #01 NEQ ?&c1 #03 emit-n !&loop
|
|
|
|
&c1 LDAk #02 NEQ ?&c2 #03 emit-n !&loop
|
|
|
|
&c2 LDAk #03 NEQ ?&c3 #04 emit-n !&loop
|
|
|
|
&c3 LDAk #04 NEQ ?&c4 #05 emit-n !&loop
|
|
|
|
&c4 LDAk #05 NEQ ?&c5 #05 emit-n !&loop
|
|
|
|
&c5 ;unknown-node-type errorm
|