Converging lambdas and match

This commit is contained in:
Devine Lu Linvega 2024-04-10 12:25:31 -07:00
parent 3c5e3de38f
commit 19b3c03a8a
1 changed files with 6 additions and 13 deletions

View File

@ -146,7 +146,7 @@ parse_frag(char *s)
static int
rewrite(void)
{
char c, last = 0, *p = direction ? bank_b : bank_a;
char c, last = 0, *p = direction ? bank_b : bank_a, *res;
while((c = *p) && c <= ' ') p++;
while((c = *p)) {
if(spacer(last)) {
@ -154,21 +154,15 @@ rewrite(void)
if(p[0] == '<' && p[1] == '>') {
r = rules_++;
r->id = rules_ - rules - 1;
p += 2;
r->a = dict_, p = parse_frag(p);
r->b = dict_, p = parse_frag(p);
p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p);
return commit_rule(r, p, 1);
}
if(p[0] == '?' && p[1] == '(') {
char *res;
p += 2;
lambda.a = dict_, p = parse_frag(p);
lambda.b = dict_, p = parse_frag(p);
r = &lambda;
p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p);
p++;
while((c = *p) && c <= ' ') p++;
r = &lambda;
res = match_rule(p, r);
if(res != NULL) {
if((res = match_rule(p, r)) != NULL) {
char cc, *b = r->b;
printf("LAMBDA [%s][%s] > %s\n", r->a, r->b, p);
if(!*b && last == ' ') outp_--;
@ -182,8 +176,7 @@ rewrite(void)
}
}
for(r = rules; r < rules_; r++) {
char *res = match_rule(p, r);
if(res != NULL) {
if((res = match_rule(p, r)) != NULL) {
char cc, *b = r->b;
if(!*b && last == ' ') outp_--;
while((cc = *b++)) {