Basic match

This commit is contained in:
Devine Lu Linvega 2024-04-04 10:30:31 -07:00
parent 22229bdbb9
commit f65e5634ff
1 changed files with 23 additions and 2 deletions

View File

@ -7,11 +7,32 @@ typedef struct {
static int rules_len;
static Rule rules[0x100];
static char dict[0x8000], *next = dict;
static char program[0x1000], *prog_ = program;
static char prog[0x1000], *prog_ = prog;
static int
match(char *p, Rule *r)
{
char c, *a = r->a, *b = p;
while((c = *a)) {
if(c != *b) return 0;
a++, b++;
}
printf("> found: %s = %s, rule: %s\n", p, r->a, r->b);
return 1;
}
static int
reduce(void)
{
char c, *p = prog;
while((c = *p)) {
int i;
for(i = 0; i < rules_len; i++) {
Rule *r = &rules[i];
match(p, r);
}
p++;
}
return 1;
}
@ -23,7 +44,7 @@ display(void)
Rule *r = &rules[i];
printf("Rule #%d: %s -> %s\n", i, r->a, r->b);
}
printf("Program: %s\n", program);
printf("Program: %s\n", prog);
}
static char *