Fixed issue in write reg

This commit is contained in:
Devine Lu Linvega 2024-04-04 19:48:10 -07:00
parent 70a158d3da
commit 920be34b20
2 changed files with 14 additions and 16 deletions

View File

@ -1,4 +1,4 @@
<> (swap ?x ?y) (?y ?x) <> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
(swap (123) (456))
foo ((A B swap) dup)

View File

@ -35,31 +35,29 @@ match(char *p, Rule *r)
{ {
char c, *a = r->a, *b = p; char c, *a = r->a, *b = p;
while((c = *a)) { while((c = *a)) {
if(c == '?') { if(c == '?') regs[(int)*(++a)] = b, a++, b = walk(b), c = *b;
regs[(int)*(++a)] = b, a++, b = walk(b), c = *b;
}
if(c != *b) return NULL; if(c != *b) return NULL;
a++, b++; a++, b++;
} }
return b; return b;
} }
static int static void
writereg(char r) writereg(char r)
{ {
int depth = 0; int depth = 0;
char c, *s = regs[(int)r]; char c, *s = regs[(int)r];
if(s[0] == '(') {
while((c = *s++)) { while((c = *s++)) {
if(c == '(') depth++; if(c == '(') depth++;
if(c == ')') {
--depth;
if(!depth) break;
}
if(depth < 0) break;
if(depth == 0 && c == ' ') break;
*outp_++ = c; *outp_++ = c;
if(c == ')') --depth;
if(!depth) return;
} }
return 1; }
while(!spacer(s[0]) && (*outp_++ = *s++))
;
return;
} }
static void static void