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)
(swap (123) (456))
<> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
foo ((A B swap) dup)

View File

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