From f65e5634ff904ddb1135c2edb629bc0d323a1e54 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 10:30:31 -0700 Subject: [PATCH] Basic match --- src/modal.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/modal.c b/src/modal.c index 6e3541a..2b6ab6e 100644 --- a/src/modal.c +++ b/src/modal.c @@ -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 *