Fixed issue with empty r->b rules

This commit is contained in:
Devine Lu Linvega 2024-04-07 19:03:04 -07:00
parent 93d7d791f3
commit 7ea50f18b7
3 changed files with 8 additions and 2 deletions

View File

@ -9,5 +9,8 @@
<> (explode ?*) (str (?*)) <> (explode ?*) (str (?*))
<> (eq ?x ?x) (#t) <> (eq ?x ?x) (#t)
<> (eq ?x ?y) (#f) <> (eq ?x ?y) (#f)
<> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
<> (?x pop) ()
(implode reverse (explode hello)) (read) (explode hello) empty-register (eq abc abc) (eq abc def) (implode reverse (explode hello)) (read) (explode hello) empty-register (eq abc abc) (eq abc def) (1 2 3) (4 5 6) swap pop dup

View File

@ -105,6 +105,8 @@ commit(char r)
{ {
int depth = 0; int depth = 0;
char c, *s = regs[(int)r]; char c, *s = regs[(int)r];
printf(">[%s]\n", s);
if(r == '*') if(r == '*')
s = plode(s); s = plode(s);
else if(s[0] == '(') { else if(s[0] == '(') {
@ -182,6 +184,7 @@ rewrite(void)
char *res = match(p, r); char *res = match(p, r);
if(res != NULL) { if(res != NULL) {
char cc, *b = r->b; char cc, *b = r->b;
if(!*b) outp_--;
while((cc = *b++)) { while((cc = *b++)) {
if(cc == '?' && regs[(int)b[0]]) if(cc == '?' && regs[(int)b[0]])
commit(*b++); commit(*b++);