Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-04-23 20:20:31 -07:00
parent 8bb661ced0
commit c73b9f0ad7
1 changed files with 6 additions and 8 deletions

View File

@ -14,7 +14,7 @@ static char bank_b[0x4000], *dst_ = bank_b;
/* clang-format off */
#define spacer(c) (c <= ' ' || c == '(' || c == ')')
#define get_reg(x) { regid = x; for(i = 0; i < regs_ptr; i++) if(regs_key[i] == regid) { reg = regs_val[i]; break; } }
#define get_reg(x) { regid = x; for(i = 0; i < rptr; i++) if(rkey[i] == regid) { reg = rval[i]; break; } }
/* clang-format on */
@ -76,10 +76,9 @@ write_reg(char r, char *reg)
*dst_++ = ' ';
*dst_++ = '(', reg++, depth++;
}
} else { /* token */
} else /* token */
while((c = *reg++) && !spacer(c))
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
}
for(i = 0; i < depth; i++) *dst_++ = ')';
return 1;
}
@ -111,8 +110,8 @@ write_rule(Rule *r, char *s, int create)
static int
apply_rule(Rule *r, char *s)
{
int i, regid, regs_ptr = 0;
char c, *a = r->a, regs_key[0x10], *regs_val[0x10];
int i, regid, rptr = 0;
char c, *a = r->a, rkey[0x10], *rval[0x10];
while((c = *a)) { /* phase: match rule */
if(c == '?') {
char *pcap = walk(s), *reg = NULL;
@ -122,7 +121,7 @@ apply_rule(Rule *r, char *s)
while(reg < rcap || pp < pcap)
if(*reg++ != *pp++) return 0;
} else /* reg set */
regs_key[regs_ptr] = regid, regs_val[regs_ptr++] = s;
rkey[rptr] = regid, rval[rptr++] = s;
a++, s = pcap;
if(!spacer(*a))
while((c = *a) && !spacer(c)) a++;
@ -187,8 +186,7 @@ rewrite(void)
return write_rule(r, s, 1);
}
if(c == '?' && s[1] == '(') { /* lambda */
cap = walk(s + 1);
lambda.id = -1;
cap = walk(s + 1), lambda.id = -1;
lambda.a = dict_, s = parse_frag(s + 2);
lambda.b = dict_, parse_frag(s), s = cap;
while(*s == ' ') s++;