Completed split from match and apply

This commit is contained in:
Devine Lu Linvega 2024-04-25 10:32:39 -07:00
parent 6d10bb3b66
commit 8cb22a9966
1 changed files with 8 additions and 8 deletions

View File

@ -6,7 +6,7 @@ typedef struct {
} Rule;
static int flip, quiet, cycles = 0x10000;
static Rule rules[0x1000], *rules_ = rules, lambda;
static Rule rules[0x1000], *rules_ = rules;
static char dict[0x8000], *dict_ = dict, empty;
static char bank_a[0x4000], *src_ = bank_a;
static char bank_b[0x4000], *dst_ = bank_b;
@ -136,7 +136,6 @@ apply_rule(Rule *r, char **regs, char *s)
{
unsigned int id;
char c, *b = r->b, *origin = dst_, *reg;
if((s = match_rule(r, regs, s)) == NULL) return 0;
/* phase: write rule */
while((c = *b++)) {
if(c == '?') {
@ -204,7 +203,7 @@ compile_rule(Rule *r, int id, char *src)
static int
rewrite(void)
{
char c, last = 0, *cap, *s = src_, *regs[0x08];
char c, last = 0, *cap, *s = src_, *regs[0x08], *res;
while(*s == ' ') s++;
while((c = *s)) {
if(spacer(last)) {
@ -218,15 +217,16 @@ rewrite(void)
}
/* phase: lambda */
if(c == '?' && s[1] == '(') {
cap = walk(s + 1);
compile_rule(&lambda, -1, s + 2);
s = cap;
Rule lambda;
cap = walk(s + 1), compile_rule(&lambda, -1, s + 2), s = cap;
while(*s == ' ') s++;
return apply_rule(&lambda, regs, s);
if((res = match_rule(&lambda, regs, s)) != NULL)
return apply_rule(&lambda, regs, res);
}
/* phase: match */
for(r = rules; r < rules_; r++)
if(apply_rule(r, regs, s)) return 1;
if((res = match_rule(r, regs, s)) != NULL)
return apply_rule(r, regs, res);
}
*dst_++ = last = c;
s++;