Only try-match during spacers

This commit is contained in:
Devine Lu Linvega 2024-04-06 09:10:19 -07:00
parent cced3c8d26
commit bb72d27e2d
3 changed files with 32 additions and 31 deletions

View File

@ -3,20 +3,20 @@
<> (add (0) (s ?y)) (s ?y) <> (add (0) (s ?y)) (s ?y)
<> (add (0) (0)) (0) <> (add (0) (0)) (0)
<> (subtract (s ?x) (s ?y)) (subtract ?x ?y) <> (sub (s ?x) (s ?y)) (sub ?x ?y)
<> (subtract (s ?x) (0)) (s ?x) <> (sub (s ?x) (0)) (s ?x)
<> (subtract (0) (s ?y)) (s ?y) <> (sub (0) (s ?y)) (s ?y)
<> (subtract (0) (0)) (0) <> (sub (0) (0)) (0)
<> (multiply (s ?x) (s ?y)) (add (s ?x) (multiply (s ?x) (subtract (s ?y) (s (0))))) <> (mul (s ?x) (s ?y)) (add (s ?x) (mul (s ?x) (sub (s ?y) (s (0)))))
<> (multiply (s ?x) (s (0)) (s ?x) <> (mul (s ?x) (s (0)) (s ?x)
<> (multiply (s (0)) (s ?y) (s ?y) <> (mul (s (0)) (s ?y) (s ?y)
<> (multiply (s ?x) (0)) (0) <> (mul (s ?x) (0)) (0)
<> (multiply (0) (s ?x)) (0) <> (mul (0) (s ?x)) (0)
<> (?x + ?y) (add ?x ?y) <> (?x + ?y) (add ?x ?y)
<> (?x - ?y) (subtract ?x ?y) <> (?x - ?y) (sub ?x ?y)
<> (?x * ?y) (multiply ?x ?y) <> (?x * ?y) (mul ?x ?y)
<> (factorial (s (0))) ((s (0))) <> (factorial (s (0))) ((s (0)))
<> (factorial (s ?x)) (((s ?x) * factorial ((s ?x) - (s (0))))) <> (factorial (s ?x)) (((s ?x) * factorial ((s ?x) - (s (0)))))

View File

@ -1,5 +1,4 @@
<> (?x dup) (?x ?x) <> ([b]) ()
<> (?x ?y swap) (?y ?x) <> (b) ([b])
<> ( ?x pop) ()
(1 2 3) (4 5 6) swap pop dup (abc)

View File

@ -59,7 +59,7 @@ match(char *p, Rule *r)
regs[id] = b; regs[id] = b;
a++, b = walk(b), c = *b; a++, b = walk(b), c = *b;
} }
if(!a[0]) return b; if(!a[0] && spacer(*(b + 1))) return b;
if(c != *b) return NULL; if(c != *b) return NULL;
a++, b++; a++, b++;
} }
@ -143,22 +143,24 @@ rewrite(void)
int i; int i;
if(p[0] == '<' && p[1] == '>') if(p[0] == '<' && p[1] == '>')
p = addrule(p) + 1, c = *p; p = addrule(p) + 1, c = *p;
for(i = 0; i < rules_len; i++) { if(p == bank_a || p == bank_b || spacer(*(p - 1))) {
Rule *r = &rules[i]; for(i = 0; i < rules_len; i++) {
char *res = match(p, r); Rule *r = &rules[i];
if(res != NULL) { char *res = match(p, r);
char cc, *b = r->b; if(res != NULL) {
while((cc = *b++)) { char cc, *b = r->b;
if(cc == '?') while((cc = *b++)) {
bind(*b++); if(cc == '?')
else bind(*b++);
*outp_++ = cc; else
*outp_++ = cc;
}
while((*outp_++ = *res++))
;
*outp_++ = 0;
save(i);
return 1;
} }
while((*outp_++ = *res++))
;
*outp_++ = 0;
save(i);
return 1;
} }
} }
*outp_++ = c; *outp_++ = c;