%sp { #2018 DEO } %nl { #0a18 DEO } |0100 ;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 ( 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 03 "a =x1 @x1 04 =x2 =x3 @x2 03 "b =x4 @x3 03 "c =x4 @x4 05 =x5 0000 @x5 03 "d =x4 ( 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 @emit ( c^ -- ) #18 DEO JMP2r @emit-short ( short* -- ) SWP emit-byte emit-byte JMP2r @emit-byte ( byte^ -- ) DUP #04 SFT ,&hex JSR #0f AND !&hex &hex #30 ADD DUP #39 GTH #27 MUL ADD emit JMP2r @emit-bool ( byte^ -- ) LIT "0 ADD emit JMP2r ( print stack size, followed by contents ) @emit-stack ( -> ) sp LIT "n emit LIT "= emit ;stack-pos LDA2 ;stack-bot SUB2 #0004 DIV2 emit-short LIT ": emit ;stack-bot &loop DUP2 ;stack-pos LDA2 LTH2 ?&ok POP2 nl JMP2r &ok sp LDA2k emit-short #0002 ADD2 !&loop ( emit n bytes from the given address ) @emit-n ( addr* count^ -> addr2* ) DUP #00 GTH ( addr count count>0? ) ?&ok ( addr count ) POP nl JMP2r &ok STH ( addr [count] ) sp LDAk emit-byte INC2 ( addr+1 [count] ) STHr #01 SUB ( addr+1 count-1 ) !emit-n ( emit the arena, with one line per node ) ( parses node type, since node size is dynamic (3-5). ) @emit-arena ( -> ) ;arena-bot &loop DUP2 ;arena-pos LDA2 LTH2 ?&ok POP2 JMP2r &ok DUP2 emit-short LIT ": emit sp 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