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